Completion of this issue will introduce the concept of rooms and levels to our game, allowing the player to transition across rooms within the same level. This will require creating a "Level Manager", capable of disabling inactive rooms, and handling & verifying Transition Endpoints.
Detail
Rooms (Component)
Rooms will need to exist as a MonoBehavior on a parent GameObject for each room in a level.
The room's ID will be used by the Level Manager to access specific rooms within the level. Each room in a level should have a level-unique ID.
The dictionary of Transition Endpoints (Keyed ID numbers and Valued at Transition Endpoint objects), allows the room's transition endpoints to be accessed easily by other scripts, and allows the level managers to make connections between two room's transitions.
Whenever the player is not in a room, the entire root GameObject for the room should become inactive (but not unloaded / destroyed). The Room Component should thusly have a public method for Loading and Unloading the room.
Transition Endpoint (Component)
A transition endpoint will serve as a point in which the player can enter the room the endpoint exists in. Each endpoint should have a room-unique ID.
When the player transitions to this endpoint, they will be placed at the endpoint's world position.
Collision Transition (Component)
This component will store a path to a transition endpoint (accessed via the Level Manager) and will send the player to that endpoint when the player collides with it's hitbox.
These should have a flag which allows their behavior to be temporarily disabled, and the transition should be validated to make sure the endpoint exists before attempting the load.
Further, since we may have different types of transition activators, it would be useful to create an ITransitionActivator interface for later serialization.
Level Manager (Component)
Each scene will contain a Level Manager singleton, which acts as a wrapper around all rooms in the level. It will handle loading the currently active level, as well as globally resolving room-ID/endpoint-ID paths to allow scripts to find rooms and endpoints easily.
Remarks
The "room" Component will very likely be expanded to hold significantly more data about the room and it's contents, such as what needs to be repaired, items collected, etc. Further, it is also worth noting that our game will eventually consist of multiple Level Managers to separate our game into different levels on different scenes.
One thing to avoid would be the temptation to use the inspector window to handle Transition Endpoint connections. We ideally want to minimize coupling between rooms and use a Manager object to handle these connections, and doing so will make validation significantly more robust.
In a further issue, we will look into adding a bunch of validation and autofilling to this framework via editor scripting to improve robustness. Things like transition paths should be automatically validated, and Level Managers should be able to automatically fill in all rooms in the level.
Tasks
Transition Endpoints
[x] Create a Transition Endpoint component
[x] Store room-unique ID.
[x] Create a prefab for these objects.
Room
[x] Create a Room component
[x] Store a level-unique room-ID.
[x] Store a dictionary of Transition Endpoints in the current room.
[x] Add public functions for loading and unloading the room.
Level Manager
[x] Create a Level Manager singleton component.
[x] Store a dictionary of all rooms, keyed by room ID and valued at room components.
[x] Create a "LoadRoom" method, which will load the given room and unload all other rooms.
[x] Allow a room to be specified as the "default" room, loaded on start up.
[x] Create a "GetEndPoint" method, which accesses a Transition Endpoint using a room-ID and transition-ID.
Collision Tranisition
[x] Create an OutgoingTransition base class, which encapsulates outgoing transitions.
[x] Store a room-ID and transition-ID to transition to.
[x] Create a MovePlayerToRoom method, loading the desired room and moving the player there using the Level Manager.
[x] Trigger this transition when the player enters the collision trigger.
Brief
Completion of this issue will introduce the concept of rooms and levels to our game, allowing the player to transition across rooms within the same level. This will require creating a "Level Manager", capable of disabling inactive rooms, and handling & verifying Transition Endpoints.
Detail
Rooms (Component)
Rooms will need to exist as a MonoBehavior on a parent GameObject for each room in a level.
The room's ID will be used by the Level Manager to access specific rooms within the level. Each room in a level should have a level-unique ID.
The dictionary of Transition Endpoints (Keyed ID numbers and Valued at Transition Endpoint objects), allows the room's transition endpoints to be accessed easily by other scripts, and allows the level managers to make connections between two room's transitions.
Whenever the player is not in a room, the entire root GameObject for the room should become inactive (but not unloaded / destroyed). The Room Component should thusly have a public method for Loading and Unloading the room.
Transition Endpoint (Component)
A transition endpoint will serve as a point in which the player can enter the room the endpoint exists in. Each endpoint should have a room-unique ID.
When the player transitions to this endpoint, they will be placed at the endpoint's world position.
Collision Transition (Component)
This component will store a path to a transition endpoint (accessed via the Level Manager) and will send the player to that endpoint when the player collides with it's hitbox.
These should have a flag which allows their behavior to be temporarily disabled, and the transition should be validated to make sure the endpoint exists before attempting the load.
Further, since we may have different types of transition activators, it would be useful to create an
ITransitionActivator
interface for later serialization.Level Manager (Component)
Each scene will contain a Level Manager singleton, which acts as a wrapper around all rooms in the level. It will handle loading the currently active level, as well as globally resolving room-ID/endpoint-ID paths to allow scripts to find rooms and endpoints easily.
Remarks
The "room" Component will very likely be expanded to hold significantly more data about the room and it's contents, such as what needs to be repaired, items collected, etc. Further, it is also worth noting that our game will eventually consist of multiple Level Managers to separate our game into different levels on different scenes.
One thing to avoid would be the temptation to use the inspector window to handle Transition Endpoint connections. We ideally want to minimize coupling between rooms and use a Manager object to handle these connections, and doing so will make validation significantly more robust.
In a further issue, we will look into adding a bunch of validation and autofilling to this framework via editor scripting to improve robustness. Things like transition paths should be automatically validated, and Level Managers should be able to automatically fill in all rooms in the level.
Tasks
Transition Endpoints
Room
Level Manager
Collision Tranisition
OutgoingTransition
base class, which encapsulates outgoing transitions.MovePlayerToRoom
method, loading the desired room and moving the player there using the Level Manager.