/// <summary> /// Create and place and DungeonRooms and Corridors from the generated dungeons. /// </summary> /// <param name="dungeon">The dungeon that was just generated.</param> /// <param name="levelNumber">The number of the level.</param> /// <param name="timer">The current used DungeonTimer.</param> /// <returns></returns> public IEnumerator CreateRooms(Dungeon dungeon, int levelNumber, DungeonConfig config, DungeonTimer timer) { List <DungeonRoom> dungeonRooms = new List <DungeonRoom>(); DungeonDict.Instance.ResetRooms(dungeon.Rooms.Length + dungeon.Corridors.Length); GameObject prefabDoorLR = RegionDict.Instance.PrefabDoorLR; GameObject prefabDoorUD = RegionDict.Instance.PrefabDoorUD; // Create DungeonRooms for (int i = 0; i < dungeon.Rooms.Length; i++) { GameObject dungeonRoomObject = Instantiate(DungeonCreator.Instance.PrefabDungeonRoom); dungeonRoomObject.transform.parent = DungeonCreator.Instance.RoomsContainer; DungeonRoom dungeonRoom = SetRoomType(dungeon.Rooms[i], dungeonRoomObject, levelNumber, config); // set room id dungeonRoom.id = i; DungeonDict.Instance.Register(dungeonRoom); SetRoomBorder(dungeon, i, dungeonRoom); SetRoomObjects(dungeon.Rooms[i], dungeonRoomObject, dungeonRoom); SetDoors(dungeon, prefabDoorLR, prefabDoorUD, i, dungeonRoomObject, dungeonRoom); dungeonRooms.Add(dungeonRoom); dungeonRoom.OnFullyCreated(); if (timer.ShouldWait()) { yield return(timer.Wait(0.9f + ((i * 1.0f / dungeon.Rooms.Length) * 0.05f))); } } // Create corridors. for (int i = 0; i < dungeon.Corridors.Length; i++) { Corridor corridor = dungeon.Corridors[i]; GameObject corridorObject = new GameObject("Corridor_" + i); corridorObject.transform.parent = DungeonCreator.Instance.CorridorContainer; CorridorRoom corridorRoom = corridorObject.AddComponent <CorridorRoom>(); corridorRoom.id = dungeon.Rooms.Length + i; corridorRoom.walkableTiles = corridor.GetWalkableTiles(); corridorRoom.direction = corridor.Size.y == 3; SetCorridorBorder(corridor, corridorRoom); DungeonDict.Instance.Register(corridorRoom); } }
/// <summary> /// Destroys all dungeon gameobjects. /// </summary> /// <returns></returns> private IEnumerator DestroyPreviousGameObjects() { if (roomsContainer.childCount > 0) { for (int i = roomsContainer.childCount - 1; i >= 0; i--) { Destroy(roomsContainer.GetChild(i).gameObject); } } if (corridorContainer.childCount > 0) { for (int i = corridorContainer.childCount - 1; i >= 0; i--) { Destroy(corridorContainer.GetChild(i).gameObject); } } if (timer.ShouldWait()) { yield return(timer.Wait(0.01f)); } }