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

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


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