T[] GetCollisionObjectsFromAChild(Vector2 checkPoint, float checkRadius, QuadtreeNestedClass <T> child)
 {
     if (child._field.PointToFieldDistance(checkPoint) <= _maxRadius + checkRadius)      //这里不光要考虑到检测半径,还要考虑到节点最大半径
     {
         return(child.CheckCollision(checkPoint, checkRadius));
     }
     return(new T[0]);
 }
        public QuadtreeNestedClass(float top, float right, float bottom, float left, int maxLeafNumber, float minSideLength, QuadtreeNestedClass <T> root = null, QuadtreeNestedClass <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 QuadtreeNestedClass <T>(_field.top, _field.right, yCenter, xCenter, _maxLeafsNumber, _minSideLength, _root, this);
            _lowerRightChild = new QuadtreeNestedClass <T>(yCenter, _field.right, _field.bottom, xCenter, _maxLeafsNumber, _minSideLength, _root, this);
            _lowerLeftChild  = new QuadtreeNestedClass <T>(yCenter, xCenter, _field.bottom, _field.left, _maxLeafsNumber, _minSideLength, _root, this);
            _upperLeftChild  = new QuadtreeNestedClass <T>(_field.top, xCenter, yCenter, _field.left, _maxLeafsNumber, _minSideLength, _root, this);

            foreach (Leaf leaf in _leafs)
            {
                SetLeafToChildren(leaf);
            }
            _leafs = null;
        }
Ejemplo n.º 4
0
 public static bool RemoveLeaf(QuadtreeNestedClass <GameObject> .Leaf leaf)
 {
     return(_quadtree.RemoveLeaf(leaf));
 }
Ejemplo n.º 5
0
 public static GameObject[] CheckCollision(QuadtreeNestedClass <GameObject> .Leaf leaf)
 {
     return(_quadtree.CheckCollision(leaf));
 }
Ejemplo n.º 6
0
 private void Awake()
 {
     _quadtree = new QuadtreeNestedClass <GameObject>(_top, _right, _bottom, _left, _maxLeafsNumber, _minSideLength);
 }
        QuadtreeNestedClass <GameObject> .Leaf _leaf;     //因为叶子变成了四叉树的内部类,这里就需要通过 四叉树类.叶子类 来表示叶子类

        private void Awake()
        {
            _transform = transform;
            _leaf      = new QuadtreeNestedClass <GameObject> .Leaf(gameObject, GetLeafPosition(), _radius);
        }