IEnumerator InstantiateRooms() { for (int i = 0; i < graph.Count; i++) { roomWorldPos.Set(graph[i].pos.x * gameData.roomBaseSize.x, graph[i].pos.y * gameData.roomBaseSize.y, 0); graph[i].roomInstance = Instantiate(graph[i].roomPrefab, roomWorldPos, Quaternion.identity, roomsParent[map[(int)graph[i].pos.x, (int)graph[i].pos.y].zoneType]) as Room; graph[i].roomInstance.gameObject.SetActive(showRoomsAtInstantiation); if (graph[i].pos.y == 0) { } for (int j = 0; j < graph[i].roomInstance.exits.Count; j++) { Exit exit = graph[i].roomPrefab.exits[j]; int x = (int)(graph[i].pos.x + exit.pos.x); int y = (int)(graph[i].pos.y + exit.pos.y); GraphRoom adjacentRoom = GetRoomFromMapIndex(x, y); if (adjacentRoom == null || !adjacentRoom.roomPrefab.exits.Exists(adjExit => Exit.AreExitsConnected(exit, adjExit, graph[i], adjacentRoom))) { float angle = exit.dir.x * 90 + (exit.dir.y == 1 ? 180 : 0); Vector3 pos = new Vector3(Mathf.Max(0, exit.pos.x) * gameData.roomBaseSize.x + 0.5f * gameData.roomBaseSize.x * Mathf.Abs(exit.dir.y), Mathf.Max(0, exit.pos.y) * gameData.roomBaseSize.y + 0.5f * gameData.roomBaseSize.y * Mathf.Abs(exit.dir.x), 0); GameObject exitObj = Instantiate(exitBlock, roomWorldPos + pos, Quaternion.Euler(0, 0, angle), graph[i].roomInstance.transform) as GameObject; exitObj.GetComponent <SpriteRenderer>().material = roomsMaterials[graph[i].roomPrefab.zoneIndex]; } } if (secondsBetweenInstanciation > 0) { yield return(new WaitForSecondsRealtime(secondsBetweenInstanciation)); } } yield return(null); // makes sure all the starts have been called; EventDispatcher.DispatchEvent(Events.GAME_LOADED, null); }
public void OnGraphCreated(object graphObject) { List <GraphRoom> graph = (List <GraphRoom>)graphObject; for (int i = 0; i < graph.Count; i++) { currentPos.Set(graph[i].pos.x * roomBaseSize.x, graph[i].pos.y * roomBaseSize.y, 0); currentSize.Set(roomBaseSize.x * graph[i].roomPrefab.size.x, roomBaseSize.y * graph[i].roomPrefab.size.y); currentRoom = Instantiate(roomPrefab, roomsParent) as RectTransform; if (graph[i].roomPrefab.type == RoomType.TREASURE) { Instantiate(treasureIconPrefab, currentRoom.transform, false); } else if (graph[i].roomPrefab.type == RoomType.BOSS) { Instantiate(bossIconPrefab, currentRoom.transform, false); } else if (graph[i].roomPrefab.type == RoomType.SPECIAL) { Instantiate(specialIconPrefab, currentRoom.transform, false); } currentRoom.localPosition = currentPos; currentRoom.sizeDelta = currentSize; rooms.Add(graph[i], currentRoom.gameObject); for (int j = 0; j < graph[i].roomPrefab.exits.Count; j++) { Exit exit = graph[i].roomPrefab.exits[j]; int x = (int)(graph[i].pos.x + exit.pos.x); int y = (int)(graph[i].pos.y + exit.pos.y); GraphRoom adjacentRoom = dungeon.GetRoomFromMapIndex(x, y); if (adjacentRoom != null && adjacentRoom.roomPrefab.exits.Exists(adjExit => Exit.AreExitsConnected(exit, adjExit, graph[i], adjacentRoom))) { currentExitPos.Set(Mathf.Max(0, exit.pos.x) * roomBaseSize.x + 0.5f * roomBaseSize.x * Mathf.Abs(exit.dir.y), Mathf.Max(0, exit.pos.y) * roomBaseSize.y + 0.5f * roomBaseSize.y * Mathf.Abs(exit.dir.x), 0); currentExitSize.Set(roomBaseSize.y * (0.10f + 0.38f * Mathf.Abs(exit.dir.y)), roomBaseSize.y * (0.10f + 0.38f * Mathf.Abs(exit.dir.x))); currentExit = Instantiate(exitPrefab, currentRoom.transform) as RectTransform; currentExit.localPosition = currentExitPos; currentExit.sizeDelta = currentExitSize; } } currentRoom.gameObject.SetActive(showAllRoomsAtStart); } }