Version: 6000.3
语言: 中文
创建剔除组
遮挡剔除问题排查

获取剔除结果

通过 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 检索到的信息仅在相机在场景中创建特定视点图像的组件。输出要么绘制到屏幕上,要么作为纹理捕获。更多信息
请参阅术语表
CullingGroup 实际执行其剔除。

创建剔除组
遮挡剔除问题排查