/// <summary> /// 初始化 /// </summary> /// <param name="data"></param> public void Init(SceneTreeData data) { // 重复初始化 if (_nodes.Count > 0) { Debug.LogError("SceneTree init repeat!"); Dispose(); } _data = data; if (_data.nodes.Length < 1) { return; } // 可见范围 _viewBounds = new Bounds(); _viewBounds.extents = new Vector3(_data.viewDistance, _data.viewDistance, _data.viewDistance); _nodes.Capacity = _data.nodes.Length; for (int i = 0; i < _data.nodes.Length; ++i) { var node = ObjectPool.New <SceneTreeNode>(); node.Init(this, _data.nodes[i]); _nodes.Add(node); } if (_data.nodes.Length > 0) { _root = _nodes[0]; } }
/// <summary> /// 销毁 /// </summary> public void Dispose() { for (int i = 0, ci = _nodes.Count; i < ci; ++i) { var node = _nodes[i]; ObjectPool.Release(ref node); } _nodes.Clear(); _data = null; _root = null; }