Version: Unity 6.0 (6000.0)
언어 : 한국어
컬링 그룹 만들기
Troubleshooting occlusion culling

컬링 결과 가져오기

onStateChanged 콜백을 통해 결과 받기

가시성 또는 거리 상태가 변경되는 구체에 대응하는 가장 효율적인 방법은 onStateChanged 콜백 필드를 사용하는 것입니다. CullingGroupEvent 구조를 인자로 사용하는 함수로 설정합니다. 이 함수는 컬링이 완료된 후 상태가 변경된 각 구체에 대해 호출됩니다. CullingGroupEvent 구조의 멤버는 구체의 이전 및 새 상태에 대해 알려 줍니다.

group.onStateChanged = StateChangedMethod;

private void StateChangedMethod(CullingGroupEvent evt)
{
    if(evt.hasBecomeVisible)
        Debug.LogFormat("Sphere {0} has become visible!", evt.index);
    if(evt.hasBecomeInvisible)
        Debug.LogFormat("Sphere {0} has become invisible!", evt.index);
}

CullingGroup 쿼리 API를 통한 결과 받기

onStateChanged 델리게이트 외에, CullingGroup은 바운딩 구체 배열에서구체의 최근 가시성 및 거리 결과를 검색해서 가져오는 데 사용되는 API도 제공합니다. 단일 구체의 상태를 확인하려면 IsVisible 및 GetDistance 메서드를 사용해야 합니다.

bool sphereIsVisible = group.IsVisible(0);
int sphereDistanceBand = group.GetDistance(0);

여러 구체의 상태를 확인하려면 QueryIndices 메서드를 사용하면 됩니다. 이 메서드는 지속적인 범위를 스캔하여 특정 가시성 또는 거리 상태와 일치하는 구체를 찾습니다.

// Allocate an array to hold the resulting sphere indices - the size of the array determines the maximum spheres checked per call
int[] resultIndices = new int[1000];
// Also set up an int for storing the actual number of results that have been placed into the array
int numResults = 0;

// Find all spheres that are visible
numResults = group.QueryIndices(true, resultIndices, 0);
// Find all spheres that are in distance band 1
numResults = group.QueryIndices(1, resultIndices, 0);
// Find all spheres that are hidden in distance band 2, skipping the first 100
numResults = group.QueryIndices(false, 2, resultIndices, 100);

쿼리 API를 통해 검색해서 가져온 정보는 컬링 그룹이 사용한 카메라가 실제로 컬링을 수행할 때만 업데이트됨을 기억해야 합니다.

컬링 그룹 만들기
Troubleshooting occlusion culling