void BuildQuadtree() { Quadtree.Clear(); if (agents.Count > 0) { Rect bounds = Rect.MinMaxRect(agents[0].position.x, agents[0].position.y, agents[0].position.x, agents[0].position.y); for (int i = 1; i < agents.Count; i++) { Vector2 p = agents[i].position; bounds = Rect.MinMaxRect(Mathf.Min(bounds.xMin, p.x), Mathf.Min(bounds.yMin, p.y), Mathf.Max(bounds.xMax, p.x), Mathf.Max(bounds.yMax, p.y)); } Quadtree.SetBounds(bounds); for (int i = 0; i < agents.Count; i++) { Quadtree.Insert(agents[i]); } Quadtree.DebugDraw(); } Quadtree.CalculateSpeeds(); }