/// <summary> /// 填加一个裁剪请求 /// </summary> /// <param name="_cullingObject"></param> public void AddRequest(IViewCullingObject _cullingObject) { //检查当前的数量是否已经达到了最大值 //如果达到了,那么就不允许继续添加 if (currentRequestingCount >= maxSize) { this.Expand(Mathf.Max(1, maxSize / 2)); this.AddRequest(_cullingObject); Debug.LogWarning($"{System.DateTime.Now.ToShortTimeString()} : Culling系统超出了范围,已增加大小至{Mathf.Max(1, maxSize)}。"); } else { //currentRequestingCount其实就是最后一个可用的Index //把Object添加到追踪队列里面 //并且赋值Index以供记录 viewCullingObjects[currentRequestingCount] = _cullingObject; _cullingObject.index = currentRequestingCount; //将BoundingSpheres这边的数据与之同步 boundingSpheres[currentRequestingCount].position = _cullingObject.position; boundingSpheres[currentRequestingCount].radius = _cullingObject.radium; //增加数量,并且同步设置CullingGroup的数量 ++currentRequestingCount; cullingGroup.SetBoundingSphereCount(currentRequestingCount); } }
/// <summary> /// 更新裁剪数据 /// </summary> /// <param name="_cullingObject"></param> public void UpdateRequest(IViewCullingObject _cullingObject) { var index = _cullingObject.index; //如果index为-1,说明不在队列内 if (index != -1) { //更新对应的BoundingSpheres的位置和半径 boundingSpheres[index].position = _cullingObject.position; boundingSpheres[index].radius = _cullingObject.radium; } }
/// <summary> /// 移除一个裁剪请求 /// </summary> /// <param name="_cullingObject"></param> public void RemoveRequest(IViewCullingObject _cullingObject) { var index = _cullingObject.index; //如果Index为-1,说明根本就不在队列中 if (index != -1) { //从CullingGroup中移除该元素 cullingGroup.EraseSwapBack(index); //减少数量,并且同步设置CullingGroup的数量 --currentRequestingCount; cullingGroup.SetBoundingSphereCount(currentRequestingCount); //CullingGroup中是将最后一个元素移动到当前元素进行替换的 //因此ViewCullingObjects这边也采取相同的措施 //并更新被替换的Object的Index viewCullingObjects[index] = viewCullingObjects[currentRequestingCount]; viewCullingObjects[index].index = index; //将申请者的Index设置为-1,表示其已经不属于列表内 _cullingObject.index = -1; } }