Version: Unity 6.0 (6000.0)
言語 : 日本語
カリンググループの作成
Troubleshooting occlusion culling

カリング結果の取得

onStateChanged コールバックで結果を得る方法

可視範囲や距離のステートが変化するスフィアに反応する最も効率的な方法は、onStateChanged コールバックフィールドを使用することです。CullingGroupEvent 構造体を引数とする関数に onStateChanged を設定すると、カリングが完了した後、ステートが変わった各スフィアに対して onStateChanged が呼び出されます。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 で見つけられる情報は、CullingGroup に使用されるカメラが、実際にカリングするときにだけ更新されるということに注意してください。

カリンググループの作成
Troubleshooting occlusion culling
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961