public static GameObject[] CheckCollision(QuadtreeWithSingletonData <GameObject> .Leaf leaf)
 {
     if (_quadtreeObject != null)
     {
         return(quadtreeObject._quadtree.CheckCollision(leaf));
     }
     return(new GameObject[0]);
 }
 //移除
 public static bool RemoveLeaf(QuadtreeWithSingletonData <GameObject> .Leaf leaf)
 {
     if (_quadtreeObject != null)                        //移除也是先检测四叉树物体是否存在,不存在的话肯定移除不了,返回 false
     {
         return(_quadtreeObject._quadtree.RemoveLeaf(leaf));
     }
     return(false);
 }
 T[] GetCollisionObjectsFromAChild(Vector2 checkPoint, float checkRadius, QuadtreeWithSingletonData <T> child)
 {
     if (child._field.PointToFieldDistance(checkPoint) <= _maxRadius + checkRadius)      //这里不光要考虑到检测半径,还要考虑到节点最大半径
     {
         return(child.CheckCollision(checkPoint, checkRadius));
     }
     return(new T[] { });
 }
    public QuadtreeWithSingletonData(float top, float right, float bottom, float left, int maxLeafNumber, float minSideLength, QuadtreeWithSingletonData <T> root = null, QuadtreeWithSingletonData <T> parent = null)
    {
        _field = new Field(top, right, bottom, left);

        _maxLeafsNumber = maxLeafNumber;
        _minSideLength  = minSideLength;

        _root = root != null ? root : this;

        _parent = parent;
    }
    void Split()
    {
        Debug.Log("<color=#808000>位置在" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + "的树梢节点达到分割条件,进行分割</color>");

        Update();

        float xCenter = (_field.left + _field.right) / 2;
        float yCenter = (_field.bottom + _field.top) / 2;

        _upperRightChild = new QuadtreeWithSingletonData <T>(_field.top, _field.right, yCenter, xCenter, _maxLeafsNumber, _minSideLength, _root, this);
        _lowerRightChild = new QuadtreeWithSingletonData <T>(yCenter, _field.right, _field.bottom, xCenter, _maxLeafsNumber, _minSideLength, _root, this);
        _lowerLeftChild  = new QuadtreeWithSingletonData <T>(yCenter, xCenter, _field.bottom, _field.left, _maxLeafsNumber, _minSideLength, _root, this);
        _upperLeftChild  = new QuadtreeWithSingletonData <T>(_field.top, xCenter, yCenter, _field.left, _maxLeafsNumber, _minSideLength, _root, this);

        foreach (Leaf leaf in _leafs)
        {
            SetLeafToChildren(leaf);
        }
        _leafs = null;
    }
 //存入
 public static bool SetLeaf(QuadtreeWithSingletonData <GameObject> .Leaf leaf)
 {
     return(quadtreeObject._quadtree.SetLeaf(leaf));      //存入时通过接口获取四叉树物体,这样能保证四叉树一直存在,不会发生存入空树
 }
Ejemplo n.º 7
0
 private void Awake()
 {
     _transform = transform;
     _leaf      = new QuadtreeWithSingletonData <GameObject> .Leaf(gameObject, GetLeafPosition(), _radius);
 }