/// <summary> /// Spawns an individual room /// </summary> /// <param name="attachSide">The side that must be open to attach the room</param> /// <param name="location">Where on the map to spawn the room</param> private void SpawnRoom(EnumList.RoomDoors attachSide, Vector3 location) { // Stores the array to spawn rooms from GameObject[] toSpawnFrom; // Checks what side needs to be open switch (attachSide) { case EnumList.RoomDoors.DOOR_UP: toSpawnFrom = rooms.topRooms; break; case EnumList.RoomDoors.DOOR_DOWN: toSpawnFrom = rooms.bottomRooms; break; case EnumList.RoomDoors.DOOR_LEFT: toSpawnFrom = rooms.leftRooms; break; case EnumList.RoomDoors.DOOR_RIGHT: toSpawnFrom = rooms.rightRooms; break; case EnumList.RoomDoors.DOOR_WIN: toSpawnFrom = rooms.winRoom; break; default: toSpawnFrom = rooms.walls; break; } // Hold the values used in the below loop GameObject toSpawn; RoomBehaviour toSpawnRB; // Makes sure only rooms of the correct difficulty spawn do { // Gets a random room from the correct list int roomIndex = Random.Range(0, toSpawnFrom.Length); // Gets the component needed to check the difficulty toSpawnRB = toSpawnFrom[roomIndex].GetComponent <RoomBehaviour>(); } while ((toSpawnRB.difficulty | difficulty) != difficulty); toSpawn = toSpawnRB.gameObject; // Spawns the room at the position of the spawnpoint GameObject room = Instantiate(toSpawn, location, Quaternion.identity); spawnedRooms.Add(room); }
/// <summary> /// Spawns the walls around the outside of the map /// </summary> private IEnumerator SpawnWalls() { // Forces the function to be called after the triggers yield return(0); bool hasSpawnedWin = false; // Fills the extra spawnpoints in with solid walls so they are not leading to the void List <GameObject> roomSpawns = GetAllSpawnpoints(); // Keep track of how many walls are going to be spawned int wallsToSpawn = roomSpawns.Count; float winSpawnChance = wallsToSpawn / 2; foreach (var spawnpoint in roomSpawns) { Vector3 spawnLocation = spawnpoint.transform.position; EnumList.RoomDoors typeToSpawn = EnumList.RoomDoors.DOOR_NONE; // Make sure the win room will be connected by a room if (spawnpoint.CompareTag("RoomSpawnpoint") && !hasSpawnedWin && spawnpoint.GetComponent <RoomSpawnSettings>().doorAttachSide != EnumList.RoomDoors.DOOR_NONE) { // The longer it has gone without spawning the room, the higher the chance float spawnChance = Random.Range(winSpawnChance, wallsToSpawn); if (spawnChance >= wallsToSpawn - 1) { typeToSpawn = EnumList.RoomDoors.DOOR_WIN; hasSpawnedWin = true; } } // Increase the chance of spawning the win room next loop ++winSpawnChance; SpawnRoom(typeToSpawn, spawnLocation); } // If the win room did not spawn, force spawn it if (!hasSpawnedWin) { SpawnRoom(EnumList.RoomDoors.DOOR_WIN, roomSpawns[0].transform.position); } Debug.Log("Spawning Done!"); roomArrow.SetActive(false); loadingCanvas.SetActive(false); spawnDone = true; }
/// <summary> /// Checks what side needs to be open for the doors to line up /// </summary> /// <param name="settings">The settings of the room to be checked</param> /// <param name="toCheck">The side to check if it is valid</param> /// <returns></returns> private bool CheckDoorAttachSide(RoomSpawnSettings settings, EnumList.RoomDoors toCheck) { return((settings.doorAttachSide & toCheck) != 0); }