public static void OpenRegionSceneEditor(LevelRegion region = null) { previousScene = GUIAuxiliar.OpenNewScene("Region Editor", out var actualScene); RegionEditorWindow window = GUIAuxiliar.OpenEditorWindow <RegionEditorWindow>(Style.TITLE_REGION_EDITOR_WINDOW); if (String.IsNullOrEmpty(previousScene)) { return; } //RegionEditorWindow window = (RegionEditorWindow)EditorWindow.GetWindow(typeof(RegionEditorWindow)); if (!AssetDatabase.IsValidFolder(Paths.FOLDER_MAPS)) { AssetDatabase.CreateFolder(Paths.FOLDER_PREFABS, Paths.NAME_MAPS); } window.ReStart(); if (region != null) { Editlevel = region; window.LoadGrid(); } window.FindLevel(); Selection.activeObject = Editlevel.terrainGrid.gameObject; SceneView.lastActiveSceneView.FrameSelected(); window.Show(); //OpenWindow(); PrefabCollectionWindow.OpenWindow(); }
private void CreatePassage(Chunk chunk, LevelRegion regionA, LevelRegion regionB, Vector2I pointA, Vector2I pointB) { LevelRegion.ConnectRegions(regionA, regionB); var line = GetLine(pointA, pointB); foreach (var c in line) { DrawCircle(chunk, c, 1); } }
private void NewMap() { if (Editlevel != null && Editlevel.terrainGrid.gameObject) { DestroyImmediate(Editlevel.terrainGrid.gameObject); } Editlevel = (LevelRegion)CreateInstance(typeof(LevelRegion)); levelSerialized = new SerializedObject(Editlevel); Editlevel.regionName = "New Level"; Editlevel.mapSize = new Vector2Int(10, 10); Editlevel.xcellSize = 1; Editlevel.ycellSize = 1; Editlevel.varList = new List <IData>(); //CreateReorderableList(); CreateGrid(); }
private void OnPick() { if (isPicking) { LevelRegion pickedObject = (LevelRegion)EditorGUIUtility.GetObjectPickerObject(); if (pickedObject != null) { if (Editlevel.terrainGrid != null) { DestroyImmediate(Editlevel.terrainGrid.gameObject); } Editlevel = pickedObject; levelSerialized = new SerializedObject(Editlevel); LoadGrid(); //CreateReorderableList(); isPicking = false; Repaint(); } } }
private void FindLevel() { if (Editlevel == null) { var actualTerrain = FindObjectOfType <RegionTerrain>(); if (actualTerrain != null) { Editlevel = actualTerrain.owner; Editlevel.LoadGrid(); if (Editlevel.varList == null) { Editlevel.varList = new List <IData>(); } //CreateReorderableList(); } else { NewMap(); } } levelSerialized = new SerializedObject(Editlevel); }
private void ReStart() { Editlevel = null; levelSerialized = null; }
private void ConnectClosestRooms(IProgress <string> progress, List <LevelRegion> floorRegions, Chunk chunk, bool forceAccessibilityFromMainRegion = false) { progress.Report($"Connecting rooms (x{++_connectingRoomsCount})..."); var roomListA = new List <LevelRegion>(); // is not accessible from main region var roomListB = new List <LevelRegion>(); // is accessible from main region if (forceAccessibilityFromMainRegion) { foreach (var room in floorRegions) { if (room.IsAccessibleFromMainRegion) { roomListB.Add(room); } else { roomListA.Add(room); } } } else { roomListA = floorRegions; roomListB = floorRegions; } var bestDistance = 0; var bestTileA = new Vector2I(); var bestTileB = new Vector2I(); LevelRegion bestRegionA = null; LevelRegion bestRegionB = null; var possibleConnectionFound = false; foreach (var regionA in roomListA) { if (!forceAccessibilityFromMainRegion) { possibleConnectionFound = false; if (regionA.ConnectedRegions.Count > 0) { continue; } } foreach (var regionB in roomListB) { if ((regionA == regionB) || (regionA.IsConnected(regionB))) { continue; } // Find the closest points between the two rooms. for (var tileIndexA = 0; tileIndexA < regionA.EdgeTiles.Count; tileIndexA++) { for (var tileIndexB = 0; tileIndexB < regionB.EdgeTiles.Count; tileIndexB++) { var tileA = regionA.EdgeTiles[tileIndexA]; var tileB = regionB.EdgeTiles[tileIndexB]; var distanceBetweenRegions = (int)(Math.Pow(tileA.X - tileB.X, 2) + Math.Pow(tileA.Y - tileB.Y, 2)); if ((distanceBetweenRegions < bestDistance) || !possibleConnectionFound) { bestDistance = distanceBetweenRegions; possibleConnectionFound = true; bestTileA = tileA; bestTileB = tileB; bestRegionA = regionA; bestRegionB = regionB; } } } } if (possibleConnectionFound && !forceAccessibilityFromMainRegion) { progress.Report($"Creating a passage (x{++_passageCount})..."); CreatePassage(chunk, bestRegionA, bestRegionB, bestTileA, bestTileB); } } if (possibleConnectionFound && forceAccessibilityFromMainRegion) { CreatePassage(chunk, bestRegionA, bestRegionB, bestTileA, bestTileB); ConnectClosestRooms(progress, floorRegions, chunk, true); } if (!forceAccessibilityFromMainRegion) { ConnectClosestRooms(progress, floorRegions, chunk, true); } }