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