Example #1
0
 bool RemoveLeafInTotalTree(QuadtreeLeafAction <T> leaf)
 {
     if (DontHaveChildren())
     {
         return(DoRemoveLeafFromSelf(leaf));
     }
     else
     {
         return(RemoveLeafInTotalTreeFromChindren(leaf));
     }
 }
Example #2
0
 //移除
 public bool RemoveLeaf(QuadtreeLeafAction <T> leaf)
 {
     if (DontHaveChildren())
     {
         return(RemoveLeafFromSelf(leaf));
     }
     else
     {
         return(RemoveLeafFromChildren(leaf));
     }
 }
Example #3
0
        bool SetLeafToSelf(QuadtreeLeafAction <T> leaf)
        {
            if (this == _root && !_field.Contains(leaf.position))
            {
                Debug.LogError("存入叶子失败,叶子不在四叉树范围内");
                return(false);
            }

            _leafs.Add(leaf);
            UpdateMaxRadiusWhenSetLeaf(leaf);
            Debug.Log("<color=#0040A0>位置在" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "的树梢节点存入位置在" + leaf.position + "半径是" + leaf.radius + "的叶子,存入后的最大半径是" + _maxRadius + "</color>");
            CheckAndDoSplit();
            return(true);
        }
Example #4
0
 private bool RemoveLeafInTotalTreeFromChindren(QuadtreeLeafAction <T> leaf)
 {
     if (_upperRightChild.RemoveLeafInTotalTree(leaf))
     {
         return(true); //如果子节点移除成功了,那就说明不需要继续遍历剩下的节点了,直接返回 true
     }
     if (_lowerRightChild.RemoveLeafInTotalTree(leaf))
     {
         return(true);
     }
     if (_lowerLeftChild.RemoveLeafInTotalTree(leaf))
     {
         return(true);
     }
     if (_upperLeftChild.RemoveLeafInTotalTree(leaf))
     {
         return(true);
     }
     return(false);
 }
Example #5
0
 bool RemoveLeafFromChildren(QuadtreeLeafAction <T> leaf)
 {
     Debug.Log("<color=#802030>位置在" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "的树枝节点从子节点移除位置在" + leaf.position + "半径是" + leaf.radius + "的叶子</color>");
     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));
     }
     return(_root.RemoveLeafInTotalTree(leaf));
 }
Example #6
0
        bool SetLeafToChildren(QuadtreeLeafAction <T> leaf)
        {
            Debug.Log("<color=#0040A0>位置在" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "的树枝节点向子节点存入位置在" + leaf.position + "半径是" + leaf.radius + "的叶子</color>");
            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);
        }
Example #7
0
 void ResetLeaf(QuadtreeLeafAction <T> leaf)
 {
     Debug.Log("<color=#800080>位置在" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "的树梢节点移除位置在" + leaf.position + "半径是" + leaf.radius + "的叶子,重新存入树</color>");
     RemoveLeafFromSelf(leaf);
     _root.SetLeaf(leaf);
 }
 public static bool RemoveLeaf(QuadtreeLeafAction <GameObject> leaf)
 {
     return(_quadtree.RemoveLeaf(leaf));
 }
 public static GameObject[] CheckCollision(QuadtreeLeafAction <GameObject> leaf)
 {
     return(_quadtree.CheckCollision(leaf));
 }
 private void Awake()
 {
     _transform = transform;
     _leaf      = new QuadtreeLeafAction <GameObject>(gameObject, GetLeafPosition(), _radius);
 }