void DrawConnections(VirtualCell input_cell, List <CellLocation> unvisited_locations, PhysicalMap physicalMap, VirtualMap virtualMap, int max_distance) { unvisited_locations.Remove(input_cell.location); Vector3 input_pos = physicalMap.GetRealWorldPosition(input_cell.location, virtualMap.storey_number); //Debug.Log("Has connected cells: " + start_cell.connectedCells.Count); foreach (CellLocation connected_cell_location in input_cell.connectedCells) { //Debug.Log(connected_cell_location); Vector3 end_pos = physicalMap.GetRealWorldPosition(connected_cell_location, virtualMap.storey_number); //Debug.Log(input_cell.distance_from_root * 1f / virtualMap.GetMaximumDistance()); Color col = Color.Lerp(Color.red, Color.green, input_cell.distance_from_root * 1f / max_distance); Handles.color = col; Handles.DrawLine(input_pos, end_pos); if (unvisited_locations.Contains(connected_cell_location)) { DrawConnections(virtualMap.GetCell(connected_cell_location), unvisited_locations, physicalMap, virtualMap, max_distance); } } }
void OnSceneGUI() { if (showDebugCoordinates || showDebugConnections) { PhysicalMap physicalMap = this.targetInstance.GetPhysicalMap(); VirtualMap[] virtualMaps = this.targetInstance.GetVirtualMaps(); if (this.targetInstance.HasGeneratedDungeon()) { if (physicalMap != null && virtualMaps.Length > 0) { GUIStyle guiStyle = new GUIStyle(); if (showDebugCoordinates) { for (int i = 0; i < virtualMaps.Length; i++) { foreach (VirtualCell c in virtualMaps[i].GetAllCells()) { Vector3 p = physicalMap.GetRealWorldPosition(c.location, i); if (c.location.x % 2 == 1 && c.location.y % 2 == 1) { guiStyle.normal.textColor = Color.yellow; int actual_x = (c.location.x - 1) / 2; int actual_y = (c.location.y - 1) / 2; Handles.Label(p, c.location.x + "," + c.location.y + "\n(" + actual_x + "," + actual_y + ")", guiStyle); } else { guiStyle.normal.textColor = Color.white; Handles.Label(p, c.location.x + "," + c.location.y, guiStyle); } } } } if (showDebugConnections) { for (int i = 0; i < virtualMaps.Length; i++) { VirtualMap virtualMap = virtualMaps[i]; List <CellLocation> unvisited_locations = new List <CellLocation>(virtualMap.WalkableLocations); //Debug.Log("Starting from " + start_location); int max_distance = virtualMap.GetMaximumDistance(); int stop_iter = 0; while (unvisited_locations.Count > 0) { CellLocation start_location = unvisited_locations[0]; // We start from a walkable cell (doesn't matter which one) VirtualCell start_cell = virtualMap.GetCell(start_location); DrawConnections(start_cell, unvisited_locations, physicalMap, virtualMap, max_distance); stop_iter++; if (stop_iter == 100) { DaedalusDebugUtils.Assert(false, "Looping in show debug connectsion!"); break; // ERROR HERE! } } } } // TEST path check //VirtualMap test_virtualMap = virtualMaps[0]; //List<CellLocation> test_unvisited_locations = new List<CellLocation>(test_virtualMap.WalkableLocations); //test_virtualMap.ExistsPathBetweenLocations(test_unvisited_locations[0], test_unvisited_locations[test_unvisited_locations.Count - 1]); } } } }