Exemplo n.º 1
0
        /// <summary>
        /// 检查视锥
        /// </summary>
        public void CheckFrustum(Frustum frustum)
        {
            /// 是否不是针对草节点加速一下,只有叶子节点才裁剪
            if (_resLoaded && _tree.data.Index == SceneTreeIndex.Grass)
            {
                if (_nodeObjects.Count > 0)
                {
                    if (_resLoaded && frustum.IsInFrustum(_data.bounds))
                    {
                        if (!_enable)
                        {
                            for (int i = 0, ci = _nodeObjects.Count; i < ci; ++i)
                            {
                                _nodeObjects[i]._data.go.layer = 0;
                                if (!_nodeObjects[i]._data.renderer.enabled)
                                {
                                    _nodeObjects[i]._data.renderer.enabled = true;
                                }
                                //_nodeObjects[i].CheckFrustum(frustum);
                            }
                        }
                        _enable = true;
                    }
                    else
                    {
                        Disable();
                    }
                }
                else
                {
                    for (int i = 0; i < _data.children.Length; ++i)
                    {
                        var child = _tree.GetNode(_data.children[i]);
                        child.CheckFrustum(frustum);
                    }
                }
                return;
            }

            if (_resLoaded && frustum.IsInFrustum(_data.bounds))
            {
                if (!_enable)
                {
                    int nLenght = _data.colliders.Length;
                    for (int i = 0; i < _data.colliders.Length; i++)
                    {
                        _data.colliders[i].gameObject.layer = 0;
                        _data.colliders[i].enabled          = true;
                    }
                }

                for (int i = 0, ci = _nodeObjects.Count; i < ci; ++i)
                {
                    _nodeObjects[i].CheckFrustum(frustum);
                }
                _enable = true;

                // 子节点
                for (int i = 0; i < _data.children.Length; ++i)
                {
                    var child = _tree.GetNode(_data.children[i]);
                    child.CheckFrustum(frustum);
                }
            }
            else
            {
                Disable();
            }
        }