public void Init(Rect b, NodeIndexQuadTree.VectorIndexPair[] objectsWithinNode, string _ObstructionLayer, int numObjectsPerNode) { NodeBounds = b; ObstructionLayer = _ObstructionLayer; ObjectsWithinNode = objectsWithinNode; if (ObjectsWithinNode.Length <= numObjectsPerNode) { ChildNodes = new NodeIndexQuadTreeNode[0]; return; } ChildNodes = new NodeIndexQuadTreeNode[4]; Rect[] childNodeRects = new Rect[4]; childNodeRects[0] = new Rect(b.xMin, b.yMin, b.width/2f, b.height/2); childNodeRects[1] = new Rect(b.xMin + b.width/2f, b.yMin, b.width/2f, b.height/2); childNodeRects[2] = new Rect(b.xMin, b.yMin + b.height/2, b.width/2f, b.height/2); childNodeRects[3] = new Rect(b.xMin + b.width/2f, b.yMin + b.height/2, b.width/2f, b.height/2); ChildNodes[0] = CreateInstance<NodeIndexQuadTreeNode>(); ChildNodes[0].Init(childNodeRects[0], objectsWithinNode.Where(a => childNodeRects[0].Contains(a.Position)).ToArray(), ObstructionLayer,numObjectsPerNode); ChildNodes[1] = CreateInstance<NodeIndexQuadTreeNode>(); ChildNodes[1].Init(childNodeRects[1], objectsWithinNode.Where(a => childNodeRects[1].Contains(a.Position)).ToArray(), ObstructionLayer, numObjectsPerNode); ChildNodes[2] = CreateInstance<NodeIndexQuadTreeNode>(); ChildNodes[2].Init(childNodeRects[2], objectsWithinNode.Where(a => childNodeRects[2].Contains(a.Position)).ToArray(), ObstructionLayer, numObjectsPerNode); ChildNodes[3] = CreateInstance<NodeIndexQuadTreeNode>(); ChildNodes[3].Init(childNodeRects[3], objectsWithinNode.Where(a => childNodeRects[3].Contains(a.Position)).ToArray(), ObstructionLayer, numObjectsPerNode); }