示例#1
0
        bool RemoveLeafFromSelf(QuadtreeLeafRadius <T> leaf)
        {
            bool removeLeafBool = _leafs.Remove(leaf);

            UpdateMaxRadiusWhenRemoveLeaf();
            Debug.Log("位置在(" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + ")的树梢节点移除位置在" + leaf.position + "半径是" + leaf.radius + "的叶子,移除后的最大半径是" + _maxRadius);
            return(removeLeafBool);
        }
示例#2
0
 bool SetLeafToSelf(QuadtreeLeafRadius <T> leaf)
 {
     _leafs.Add(leaf);
     UpdateMaxRadiusWhenSetLeaf(leaf);
     Debug.Log("位置在(" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + ")的树梢节点存入位置在" + leaf.position + "半径是" + leaf.radius + "的叶子,存入后的最大半径是" + _maxRadius);
     CheckAndDoSplit();
     return(true);
 }
示例#3
0
        void UpdateMaxRadiusWhenSetLeaf(QuadtreeLeafRadius <T> leaf)
        {
            if (leaf.radius > _maxRadius)       //只有存入的叶子的半径超过了现在节点的最大半径才需要更新最大半径,存入更小的叶子并不会影响到检测。
            {
                _maxRadius = leaf.radius;

                CallParentUpdateMaxRadius();
            }
        }
示例#4
0
 /*
  *  移除叶子,比第零步多了更新最大半径的步骤和移除是否成功的返回
  */
 public bool RemoveLeaf(QuadtreeLeafRadius <T> leaf)
 {
     if (DontHaveChildren())
     {
         return(RemoveLeafFromSelf(leaf));
     }
     else
     {
         return(RemoveLeafFromChildren(leaf));
     }
 }
示例#5
0
 /*
  *  存入叶子
  *  在第零步的基础上增加了更新半径功能和返回存入是否成功功能
  */
 public bool SetLeaf(QuadtreeLeafRadius <T> leaf)
 {
     if (DontHaveChildren())
     {
         return(SetLeafToSelf(leaf));
     }
     else
     {
         return(SetLeafToChildren(leaf));
     }
 }
示例#6
0
        bool RemoveLeafFromChildren(QuadtreeLeafRadius <T> leaf)
        {
            Debug.Log("位置在((" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "))的树枝节点从子节点移除位置在" + leaf.position + "半径是" + leaf.radius + "的叶子");

            if (_upperRightChild._field.Contains(leaf.position))
            {
                return(_upperRightChild.RemoveLeaf(leaf));
            }
            if (_lowerRightChild._field.Contains(leaf.position))
            {
                return(_lowerRightChild.RemoveLeaf(leaf));
            }
            if (_lowerLeftChild._field.Contains(leaf.position))
            {
                return(_lowerLeftChild.RemoveLeaf(leaf));
            }
            if (_upperLeftChild._field.Contains(leaf.position))
            {
                return(_upperLeftChild.RemoveLeaf(leaf));
            }

            Debug.LogError("位置在(" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + ")的节点,移除叶子失败,叶子不在任何一个子节点的区域里");
            return(false);
        }
示例#7
0
        bool SetLeafToChildren(QuadtreeLeafRadius <T> leaf)
        {
            Debug.Log("位置在(" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + ")的树枝节点向子节点存入位置在" + leaf.position + "半径是" + leaf.radius + "的叶子");

            if (_upperRightChild._field.Contains(leaf.position))
            {
                return(_upperRightChild.SetLeaf(leaf));
            }
            if (_lowerRightChild._field.Contains(leaf.position))
            {
                return(_lowerRightChild.SetLeaf(leaf));
            }
            if (_lowerLeftChild._field.Contains(leaf.position))
            {
                return(_lowerLeftChild.SetLeaf(leaf));
            }
            if (_upperLeftChild._field.Contains(leaf.position))
            {
                return(_upperLeftChild.SetLeaf(leaf));
            }

            Debug.LogError("向位置在(" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + ")的节点存入叶子时发生错误:叶子不在所有子节点的范围里。");   //Debug.LogError:在Console面板输出Error,就是红色那种消息
            return(false);
        }
 public static void RemoveLeaf(QuadtreeLeafRadius <GameObject> leaf)
 {
     _quadtree.RemoveLeaf(leaf);
 }
 public static void SetLeaf(QuadtreeLeafRadius <GameObject> leaf)
 {
     _quadtree.SetLeaf(leaf);
 }
示例#10
0
 private void Awake()
 {
     _transform = transform;
     _leaf      = new QuadtreeLeafRadius <GameObject>(gameObject, GetLeafPosition(), _radius);
 }