コード例 #1
0
    //检测
    public T[] CheckCollision(QuadtreeWithActionLeaf <T> leaf)
    {
        List <T> objs = new List <T>(CheckCollision(leaf.position, leaf.radius));

        objs.Remove(leaf.obj);
        return(objs.ToArray());
    }
コード例 #2
0
 bool RemoveLeafFromSelf(QuadtreeWithActionLeaf <T> leaf)
 {
     if (DoRemoveLeafFromSelf(leaf))
     {
         return(true);
     }
     return(_root.RemoveLeafInTotalTree(leaf));
 }
コード例 #3
0
    void UpdateMaxRadiusWhenSetLeaf(QuadtreeWithActionLeaf <T> leaf)
    {
        if (leaf.radius > _maxRadius)       //只有存入的叶子的半径超过了现在节点的最大半径才需要更新最大半径,存入更小的叶子并不会影响到检测。
        {
            _maxRadius = leaf.radius;

            CallParentUpdateMaxRadius();
        }
    }
コード例 #4
0
 bool DoRemoveLeafFromSelf(QuadtreeWithActionLeaf <T> leaf)
 {
     if (_leafs.Remove(leaf))
     {
         UpdateMaxRadiusWhenRemoveLeaf();
         Debug.Log("<color=#802030>位置在" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "的树梢节点移除位置在" + leaf.position + "半径是" + leaf.radius + "的叶子,移除后的最大半径是" + _maxRadius + "</color>");
         return(true);
     }
     return(false);
 }
コード例 #5
0
 //存入
 public bool SetLeaf(QuadtreeWithActionLeaf <T> leaf)
 {
     if (DontHaveChildren())
     {
         return(SetLeafToSelf(leaf));
     }
     else
     {
         return(SetLeafToChildren(leaf));
     }
 }
コード例 #6
0
 bool RemoveLeafInTotalTree(QuadtreeWithActionLeaf <T> leaf)
 {
     if (DontHaveChildren())
     {
         return(DoRemoveLeafFromSelf(leaf));
     }
     else
     {
         return(RemoveLeafInTotalTreeFromChindren(leaf));
     }
 }
コード例 #7
0
 //移除
 public bool RemoveLeaf(QuadtreeWithActionLeaf <T> leaf)
 {
     if (DontHaveChildren())
     {
         return(RemoveLeafFromSelf(leaf));
     }
     else
     {
         return(RemoveLeafFromChildren(leaf));
     }
 }
コード例 #8
0
    bool SetLeafToSelf(QuadtreeWithActionLeaf <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);
    }
コード例 #9
0
 private bool RemoveLeafInTotalTreeFromChindren(QuadtreeWithActionLeaf <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);
 }
コード例 #10
0
 bool RemoveLeafFromChildren(QuadtreeWithActionLeaf <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));
 }
コード例 #11
0
    bool SetLeafToChildren(QuadtreeWithActionLeaf <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);
    }
 private void Awake()
 {
     _transform = transform;
     _leaf      = new QuadtreeWithActionLeaf <GameObject>(gameObject, GetLeafPosition(), _radius);
 }
コード例 #13
0
 public static bool RemoveLeaf(QuadtreeWithActionLeaf <GameObject> leaf)
 {
     return(_quadtree.RemoveLeaf(leaf));
 }
コード例 #14
0
 public static GameObject[] CheckCollision(QuadtreeWithActionLeaf <GameObject> leaf)
 {
     return(_quadtree.CheckCollision(leaf));
 }
コード例 #15
0
 void ResetLeaf(QuadtreeWithActionLeaf <T> leaf)
 {
     Debug.Log("<color=#800080>位置在" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "的树梢节点移除位置在" + leaf.position + "半径是" + leaf.radius + "的叶子,重新存入树</color>");
     RemoveLeafFromSelf(leaf);
     _root.SetLeaf(leaf);
 }