private void CacheNeighbors() { _neighbors = new List <Region>(); foreach (int connection in _connections) { foreach (Region region in RegionConnectionManager.GetRegions(connection)) { if (region != this && !_neighbors.Contains(region)) { _neighbors.Add(region); } } } }
public static void Draw() { if (DebugData.RegionsDrawAllBounds) { foreach (Region region in _regions) { EG_Debug.DrawRect(region.Bounds, Color.white); } } if (DebugData.RegionsDrawSelected) { Vector2 mousePosInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Contains(mousePosInWorld)) { Region region = GetRegion(mousePosInWorld); EG_Debug.DrawText("----------SELECTED REGION----------\n" + region); foreach (int connection in region.Connections) { EG_Debug.DrawText(connection + ": " + RegionConnectionManager.GetRegions(connection).Count()); } foreach (Vector2 pos in region.OwnedPositions) { EG_Debug.DrawSquare(new Rect(pos, Vector2.one), DEBUG_SELECTED_REGION_COLOR); } if (DebugData.RegionsDrawEntities) { foreach (Entity entity in region.Entities) { EG_Debug.DrawRect(entity.Rect, DEBUG_REGION_ENTITY_COLOR); } } if (DebugData.RegionsDrawNeighbors) { foreach (Region neighbor in region.Neighbors) { foreach (Vector2 pos in neighbor.OwnedPositions) { EG_Debug.DrawSquare(new Rect(pos, Vector2.one), DEBUG_NEIGHBOR_REGION_COLOR); } } } if (DebugData.RegionsDrawEdges) { foreach (Region.Connection connection in region.Connections) { Vector2 pos = connection.Position; Vector2 size = new Vector2((connection.Normal.x == 0) ? 1 : connection.Normal.x * connection.Length, (connection.Normal.y == 0) ? 1 : connection.Normal.y * connection.Length); Rect rect = new Rect(pos, size); EG_Debug.DrawSquare(rect, DEBUG_REGION_EDGE_COLOR); EG_Debug.DrawRect(rect, Color.black); } } } } }