Exemplo n.º 1
0
 T[] GetCollisionObjectsFromAChild(Vector2 checkPoint, float checkRadius, QuadtreeWithAction <T> child)
 {
     if (child._field.PointToFieldDistance(checkPoint) <= _maxRadius + checkRadius)
     {
         return(child.CheckCollision(checkPoint, checkRadius));
     }
     return(new T[0]);
 }
Exemplo n.º 2
0
    public QuadtreeWithAction(float top, float right, float bottom, float left, int maxLeafNumber, float minSideLength, QuadtreeWithAction <T> root = null, QuadtreeWithAction <T> parent = null)
    {
        _field = new QuadtreeWithActionField(top, right, bottom, left);

        _maxLeafsNumber = maxLeafNumber;
        _minSideLength  = minSideLength;

        _root = root != null ? root : this;

        _parent = parent;
    }
Exemplo n.º 3
0
    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 QuadtreeWithAction <T>(_field.top, _field.right, yCenter, xCenter, _maxLeafsNumber, _minSideLength, _root, this);
        _lowerRightChild = new QuadtreeWithAction <T>(yCenter, _field.right, _field.bottom, xCenter, _maxLeafsNumber, _minSideLength, _root, this);
        _lowerLeftChild  = new QuadtreeWithAction <T>(yCenter, xCenter, _field.bottom, _field.left, _maxLeafsNumber, _minSideLength, _root, this);
        _upperLeftChild  = new QuadtreeWithAction <T>(_field.top, xCenter, yCenter, _field.left, _maxLeafsNumber, _minSideLength, _root, this);

        foreach (QuadtreeWithActionLeaf <T> leaf in _leafs)
        {
            SetLeafToChildren(leaf);
        }
        _leafs = null;
    }
Exemplo n.º 4
0
 private void Awake()
 {
     _quadtree = new QuadtreeWithAction <GameObject>(_top, _right, _bottom, _left, _maxLeafsNumber, _minSideLength);
 }