Offers a sample for a singleplayer lobby.
Allow the local player to manage adding/removing NPC factions, assigning their NPC types (difficulty), faction type and colors, pick a target map with a series of configurations such the defeat condition or game goal and the game’s speed modifier then the target map will be loaded alongside the specified factions in the lobby slots.
- RTS Engine 2022.0.0 or higher
Find it in the Core installation of the RTS Engine or get it from the Singleplayer Module and import it into your project.
The singleplayer module requires only one independent scene to run where all its components reside.
1. Singleplayer Lobby Menu Scene
Navigate to the Scenes folder in the module and open the SingleplayerLobbyMenu scene.
This scene comes with a menu that allows to add or remove (NPC) faction slots, pick a target map and more configurations to setup a singleplayer game.
The main object in this scene is the SinglePlayerLobby UI canvas. This game object holds all the UI elements necessary to construct the lobby menu as children objects as well as the components required to run the lobby and connect with the RTS Engine.
Select the SinglePlayerLobby game object and let's explore the components attached to it.
2. Singleplayer Lobby Components
We will now go through the components attached to the SinglePlayerLobby game object.
2.1 Local Lobby Manager
The Local Lobby Manager component is the main component responsible for the single player lobby.
Game Code: Enter the game's version in this field. It represents the version of your that the lobby is running.
Maps: This array field allows to input the available maps to play in a single player mode. For each map, add an element to this field and pick the following:
- Scene Name: The name of the target map scene. Make sure it is added in the build settings of your project.
- Name: Name to be displayed on UI elements in the lobby.
- Description: Short description of the map scene to display in the UI elements of the lobby.
- Factions Amount: Pick the minimum and the maximum amount of faction slots allowed to play in the map. Make sure that the amount of maximum faction slots matches the faction slots you defined in the Game Manager component in the map scene.
- Faction Types: Input the Faction Types that factions can use in the map.
- NPC Types: Input the NPC Types that NPC factions can use in the map.
Faction Color Selector: Pick a default color and a list of allowed faction colors that the local player can pick for their faction and the NPC factions.
Defeat Condition Selector: Define the conditions that marks a faction as defeated in the map and define a name that will be shown in the lobby UI menus that corresponds to each possible defeat condition.
Time Modifier Selector: Pick options for the speed that the game in the map can start with. The value of 1 represents a normal speed, while anything higher renders the game faster and anything lower renders it slower. This does not affect Unity's time scale but rather only RTS Engine related components.
Initial Resources Selector: Define options of resource types and corresponding amounts/capacities that the local player can pick from for factions to start the map with.
Prev Scene: The scene to load when leaving the lobby menu (when not starting a game).
Lobby Faction Prefab: A UI object prefab that includes the Local Lobby Faction Slot component. This component manages each individual lobby faction slot, whether it is the local player one or one that belongs to a NPC faction. The base prefab can be found in the following path: RTS Engine -> Modules -> Singleplayer -> Prefabs.
- Faction Color Image: A UI Button that is used to display the faction’s color. In the On Click event of the Button component, drag and drop the prefab object as the event source and set the event to LocalLobbyFactionSlot -> OnFactionColorUpdated.
- Faction Name Input: A UI Input field that is used to input and show the faction’s name. In the On End Edit event of the InputField component, drag and drop the prefab object as the event source and set the event to LocalLobbyFactionSlot -> OnFactionNameUpdated
- Faction Type Menu: A UI Dropdown which allows the player to pick a faction type for each faction slot. In the On Value Changed event of the Dropdown component, drag and drop the prefab object as the event source and set the event to LocalLobbyFactionSlot -> OnFactionTypeUpdated
- NPC Type Menu: A UI Dropdown which allows the player to pick a NPC Manager for each faction slot. In the On Value Changed event of the Dropdown component, drag and drop the prefab object as the event source and set the event to LocalLobbyFactionSlot -> OnFactionNPCManagerUpdated.
- Remove Button: A UI Button that the player can use to remove the faction slot associated with the instance of the lobby faction. In the On Click event of the Button component, drag and drop the prefab object as the event source and set the event to LocalLobbyFactionSlot -> Remove.
Start Delay Time: Delay time (in seconds) after the player starts the lobby game and before the target map scene is actually loaded.
Start Lobby Event: Unity event invoked when the lobby starts to load the target map.
Scene Loader: Defines properties regarding loading target map scenes. When the Load Async field is enabled, the target map scene would load asynchronously. The On Scene Load Start Unity event is called when the scene loading starts. For example, when the loading is done asynchronously, you can use the former event to show a loading screen while the target map scene is loading.
2.2 Local Lobby UI Manager
The Local Lobby UI Manager component is responsible for handling UI elements in a singleplayer lobby scene.
- Canvas: Main canvas that is the parent object of all lobby UI elements.
- Lobby Faction Slot Parent: Parent object of all the faction lobby slots objects. It must have a Grid Layout Group component attached to it.
- Map Dropdown Menu: UI Dropdown menu used to represent the maps that can be selected in the lobby. In the On Value Changed event of the Dropdown component, drag and drop the prefab object as the event source and set the event to LocalLobbyManagerUI -> OnLobbyGameDataUIUpdated
- Map Description Text: UI Text used to display the selected map's description.
- Map Faction Amount Text: UI Text used to display the selected map's min and max allowed faction amount.
- Add NPC Faction Button: UI Button used to add a NPC faction slot to the lobby.
- Start Game Button: UI Button used to start the game from the lobby. In the On Click event of the Button component, drag and drop the object that includes the prefab object the event source and set the event to LocalLobbyManagerUI -> StartLobby.
Additional UI elements include the following map menu UI dropdown elements that are assigned in the selector fields of the Local Lobby Manager component.
For all of the dropdowns, in the On Click event of the Button component, drag and drop the object that includes the Local Lobby UI Manager component as the event source and set the event to LocalLobbyUIManager -> OnLobbyGameDataUIUpdated.
2.3 Other Local Lobby Manager Components
- Lobby Logger: Required to print log statements in the lobby menu.
- Lobby Audio Manager: Handles playing audio clips and music in the lobby menu.
- Lobby Player Message UI Handler: Handles displaying messages to the player in the lobby menu.
Release Date: 07/30/2022
- RTS Engine 2022.2.3 or higher
- ADD the option in the lobby menu to pick a random faction type for a faction slot which allow the faction to have a random faction type of the ones specified in the currently selected map.