T[] GetCollisionObjectsFromAChild(Vector2 checkPoint, float checkRadius, QuadtreeWithEventDelegate <T> child) { if (child._field.PointToFieldDistance(checkPoint) <= _maxRadius + checkRadius) { return(child.CheckCollision(checkPoint, checkRadius)); } return(new T[0]); }
public QuadtreeWithEventDelegate(float top, float right, float bottom, float left, int maxLeafNumber, float minSideLength, QuadtreeWithEventDelegate <T> root = null, QuadtreeWithEventDelegate <T> parent = null) { _field = new QuadtreeWithEventDelegateField(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 QuadtreeWithEventDelegate <T>(_field.top, _field.right, yCenter, xCenter, _maxLeafsNumber, _minSideLength, _root, this); _lowerRightChild = new QuadtreeWithEventDelegate <T>(yCenter, _field.right, _field.bottom, xCenter, _maxLeafsNumber, _minSideLength, _root, this); _lowerLeftChild = new QuadtreeWithEventDelegate <T>(yCenter, xCenter, _field.bottom, _field.left, _maxLeafsNumber, _minSideLength, _root, this); _upperLeftChild = new QuadtreeWithEventDelegate <T>(_field.top, xCenter, yCenter, _field.left, _maxLeafsNumber, _minSideLength, _root, this); foreach (QuadtreeWithEventDelegateLeaf <T> leaf in _leafs) { SetLeafToChildren(leaf); } _leafs = null; }
private void Awake() { _quadtree = new QuadtreeWithEventDelegate <GameObject>(_top, _right, _bottom, _left, _maxLeafsNumber, _minSideLength); }