Lobby Manager
Implemented in: EasyGameLobby
The Lobby Manager is the main class that you will interact with when working with lobbies, it's a singleton and won't be destroyed on load. It is responsible for managing all lobby functionalities such as creating and keeping the lobby active sending Heartbeats
and everything you may need while working with lobbies.
The Lobby Manager also handles when the player is automatically disconnected from the lobby, see more about in the Settings page.
Unless you are creating your own lobby UI from scratch or modifying the existing one, you will not need to interact with the Lobby Manager directly. However, it is important to understand its properties and methods.
Properties
LobbyManager.Instance
Type: LobbyManager
The singleton instance of the Lobby Manager. You can access it from any script by calling LobbyManager.Instance
and access its properties and methods.
CurrentLobby
Type: LocalLobby
The current lobby the player is in. Instance of the LocalLobby
class, which contains all the information about the lobby. If the player is not in a lobby, it will be null
.
CurrentPlayer
Type: LocalPlayer
Instance of the LocalPlayer
class, which contains all the information about the player. Even if the player is not in a lobby, this property will always be available.
NetworkHelper
Type: NetworkHelper
Instance of the NetworkHelper
class, which contains all the methods for authenticating the player.
Methods
CreateLobby
Declaration
Task CreateLobby(bool isPrivate, string lobbyName, string password = null, int maxPlayers = DEFAULT_MAX_PLAYERS)
Task CreateLobby(LocalLobby newLobby, string lobbyName, int maxPlayers = DEFAULT_MAX_PLAYERS)
Parameters
Parameter | Type | Description |
---|---|---|
isPrivate* | bool | Determines if the lobby is private. |
lobbyName* | string | The name of the lobby. |
password | string | The password to join the lobby. |
maxPlayers | int | The maximum number of players allowed in the lobby. |
newLobby* | LocalLobby | New instance of the LocalLobby class with the lobby settings. |
* Required parameter.
Description
Creates a new lobby with the specified settings. If a LocalLobby instance is provided, it will use its settings instead of the parameters. The player will automatically join the lobby after creation and trigger the OnLobbyJoinedOrCreated
event.
JoinLobby
Declaration
Task JoinLobbyById(string id, string password = null)
Task JoinLobbyByCode(string code, string password = null)
Parameters
Parameter | Type | Description |
---|---|---|
id* | string | The ID of the lobby to join. |
code* | string | The code of the lobby to join. |
password | string | The password to join the lobby. |
* Required parameter.
Description
Joins a lobby by its ID or code. If the lobby is private, the password must be provided. The player will automatically join the lobby and trigger the OnLobbyJoinedOrCreated
event.
QuickJoinLobby
Declaration
Task QuickJoinLobby(QueryBuilder queryBuilder)
Parameters
Parameter | Type | Description |
---|---|---|
queryBuilder* | QueryBuilder | The query builder to filter the lobbies to join. |
* Required parameter.
Description
Joins a random lobby that matches the query builder filters. The player will automatically join the lobby and trigger the OnLobbyJoinedOrCreated
event.
GetLobbies
Declaration
Task<List<LocalLobby>> GetLobbiesAsLocal(QueryBuilder queryBuilder)
Task<List<Lobby>> GetLobbies(QueryBuilder queryBuilder)
Parameters
Parameter | Type | Description |
---|---|---|
queryBuilder* | QueryBuilder | The query builder to filter the lobbies to get. |
* Required parameter.
Description
Returns a list of lobbies that match the query builder filters. The lobbies can be returned as a list of Lobby
or LocalLobby
instances.
TryToReconnectLastJoinedLobby
Declaration
Task<bool> TryToReconnectLastJoinedLobby( )
Description
Tries to reconnect to the last lobby the player was in. Returns true
if the reconnection was successful, false
otherwise.
As Easy Game Lobby does not handle the game's networking or gameplay logic, be aware that even though the reconnection was successful, it's up to you to sync the current game state with the reconnected player.
LeaveLobby
Declaration
Task LeaveLobby(string reason = null)
Parameters
Parameter | Type | Description |
---|---|---|
reason | string | The reason for leaving the lobby. |
Description
Leaves the current lobby. If a reason is provided, an OnMsgPopup
event will be triggered with the reason with the type Info
.
RemovePlayer
Declaration
Task RemovePlayer(string playerId)
Parameters
Parameter | Type | Description |
---|---|---|
playerId* | string | The ID of the player to remove from the lobby. |
* Required parameter.
Description
Removes a player from the current lobby. Only the lobby owner can remove players from the lobby.
Events
OnLobbyJoinedOrCreated
Parameters
Parameter | Type | Description |
---|---|---|
joinedLobby | LocalLobby | The lobby that was joined or created. |
Description
Triggered when the player joins or creates a lobby, providing the LocalLobby instance of the lobby.
OnMsgPopup
Parameters
Parameter | Type | Description |
---|---|---|
text | string | The message to display. |
msgType | MessageType | The type of the message. |
Description
Triggered when a message popup is requested, providing the message text and type.
Message types enum:
Ignorable
Info
Warning
Error
Critical
OnLobbyLeft
Description
Triggered when the player leaves the lobby.
Request Cooldown
Every Lobby request has it's rate limits, RequestCooldown
is a class that helps managing the rate limit of the requests. All RequestCooldown are static readonly fields that can be accessed from the LobbyManager
class.
Available RequestCooldown:
QueryCooldown
CreateLobbyCooldown
JoinLobbyCooldown
QuickJoinCooldown
LeaveOrRemovePlayerCooldown
UpdatePlayerCooldown
UpdateLobbyCooldown
GetJoinedLobbiesCooldown
GetLobbyCooldown
ReconnectCooldown
HeartbeatCooldown
See more about the RequestCooldown class.