Example #1
0
    void PlaceEventRoom(EventRoom currentEventRoom)
    {
        // Create doorway lists to loop over
        List <Doorway> currentAvailableDoorways = new List <Doorway>(allAvailableDoorways);
        Doorway        doorwayEntrance          = currentEventRoom.doorways[0];
        Doorway        doorwayExit = currentEventRoom.doorways[1];

        bool roomPlaced = false;

        // Try all available doorways
        foreach (Doorway availableDoorway in currentAvailableDoorways)
        {
            Room room = (Room)currentEventRoom;
            PositionRoomAtDoorway(ref room, doorwayEntrance, availableDoorway);

            //  Check room overlaps
            if (CheckRoomOverlap(currentEventRoom))
            {
                // If overlap detected - skip to next iteration of the loop
                continue;
            }

            // No overlap, set this to true and...
            roomPlaced = true;

            placedEventRooms.Add(currentEventRoom);

            // Remove occupied doorways
            doorwayEntrance.gameObject.SetActive(false);
            allAvailableDoorways.Remove(doorwayEntrance);

            availableDoorway.gameObject.SetActive(false);
            allAvailableDoorways.Remove(availableDoorway);

            currentEventRoom.LoadPrefabEvent();
            currentEventRoom.onRoomCompleteDelegate += ContinueLevelGeneration;

            // Exit loop if room has been placed.
            if (roomPlaced)
            {
                break;
            }
        }

        // Room couldn't be placed. Restart.
        if (!roomPlaced)
        {
            ResetLevelGenerator();
        }
        // WAIT UNTIL PLAYER HAS COMPLETED THE EVENT ROOM TO CONTINUE GENERATING LEVEL?
    }