Room Spawn Generation
A quick writeup on how i imagine the basics of the room generation model will work, accessing a room information script assigned to each prefab of our rooms, and then storing them globally for easy accessLoasty
csharp
2 years ago
2.1 kB
10
Indexable
//Room Spawning Generation [SerializedField] List<GameObject> listOfTier1RoomPrefabs; [SerializedField] List<GameObject> listOfTier2RoomPrefabs; [SerializedField] List<GameObject> listOfTier3RoomPrefabs; const int ROOMS_PER_TIER = 2; const int NUM_OF_TIERS = 3; int MAX_GRID_FOR_ROOMS; RoomMap[,] spawnedRooms = new RoomInfo[] void start(){ MAX_GRID_FOR_ROOMS = ROOMS_PER_TIER * NUM_OF_TIERS; } //The player has triggered a collider to spawn a new room, pass in a room's information script to spawn a new one next to it void SelectNewRoom(RoomInformation curRoom){ List<GameObject> PossibleRooms = GetPossibleRooms(curRoom.tier); GameObject selectedRoom = null; if(!PossibleRooms.empty){ int roomNum = Random.Range(0, PossibleRooms.Count); selectedRoom = PossibleRooms[roomNum]; //Pass in the current room information to the new function, with the selected new room SpawnNewRoom(curRoom, selectedRoom) } else { debug.log("ERROR SPAWNING ROOM"); } } List<GameObject> GetPossibleRooms(int tier){ switch (tier) { case 0: //This should never happen, unless we treat the safe room as its own unique tier? return null; break; case 1: return listOfTier1RoomPrefabs; break; case 2: return listOfTier2RoomPrefabs; break; case 3: return listOfTier3RoomPrefabs; break; default: //If somehow we end up with a weird room tier value, return the lowest tier, just failsafe stuff return listOfTier1RoomPrefabs; break; } } void SpawnNewRoom(RoomInformation oldRoom, GameObject newRoom){ //In the room information, when a player triggers a room to spawn, store where it is located in the world Vector3 newRoomPos = oldRoom.GetTriggeredPosition(); GameObject spawnedRoom = newRoom.Instantiate() @ newRoomPos + /*whatever adjustments need to be made to fit it accordingly*/; //TODO: Store information in the map grid, and pass in any new information required to the new room }
Editor is loading...