public override ASceneElement Create() { Assert.IsFalse(IsNull()); SimpleElement element = SceneElementPool.New <SimpleElement>(); element.SetPrefab(prefab, poolName); return(element); }
/// <summary> /// 回收所有场景元素到对象池并清空集合。 /// </summary> public override void Clear() { for (int i = 0; i < elements.Count; i++) { SceneElementPool.Delete(elements[i]); } elements.Clear(); elementCoordinates.Clear(); }
protected override void UpdateCulling(ALayerCamera layerCamera) { if (elementCoordinates.Count == 0) { return; } // 获取可见的最近和最远场景元素的索引值 int nearElementIndex; int farElementIndex; GetVisibleElementsRange(layerCamera, out nearElementIndex, out farElementIndex); // 设置可视范围内的元素为可见 for (int i = nearElementIndex; i <= farElementIndex; i++) { if (!elements[i].IsVisible) { elements[i].OnBecameVisible(layerCamera); } } // 回收身后的场景元素 if (positiveDirection == RelativeDirection.Positive) { int index = 0; while (index < nearElementIndex) { SceneElementPool.Delete(elements[0]); elements.RemoveAt(0); elementCoordinates.RemoveAt(0); index += 1; } } else { int index = elements.Count - 1; while (index > farElementIndex) { SceneElementPool.Delete(elements[index]); elements.RemoveAt(index); elementCoordinates.RemoveAt(index); index -= 1; } } }