Local Lobby
Implemented in: EasyGameLobby
Local Lobby wraps around Lobby instances, providing an interface for easy management and listening to lobby values and events. Most data fields utilize either a LobbyActionValue
or an ActionValue
to facilitate value changes and event listening (Refer to their respective pages for more information). While any player can modify values locally, only the host can send changes to the server using the UpdateLobbyData
method. Do not modify any data if the current player is not the host.
All data of joined lobbies are automatically synchronized with the server, and the host is responsible for updating the lobby data.
Any custom lobby value can be easily accessed by its name, as shown in the example below:
Or accessed using a string:
// Casting is required to access the correct value type, otherwise it will always return the value as a string.
Debug.Log(
(LobbyActionValue<int>)LobbyManager.Instance.CurrentLobby["MyCustomValue"].Value
);
// Or
Debug.Log(
(LobbyActionValue<int>)LobbyManager.Instance.CurrentLobby.CustomDataMap["MyCustomValue"].Value
);
A new instance of a local lobby can be created and provided to the CreateLobby
method to create a lobby with updated values before creation.
// The relay code is always automatically generated, providing it will have no effect.
public LocalLobby(bool isPrivate, string password = null, string relayCode = null)
// Password is optional
LocalLobby newLobby = new LocalLobby(true, "password123");
newLobby.MyCustomValue.Value = 10;
await LobbyManager.Instance.CreateLobby(newLobby, "My Lobby", 4);
Lobby Data
Id
- string Read-OnlyCode
- string Read-OnlyName
- LobbyActionValue<string>MaxPlayers
- LobbyActionValue<int>IsPrivate
- LobbyActionValue<bool>IsLocked
- LobbyActionValue<bool>HostId
- LobbyActionValue<string>-
Password
- LobbyActionValue<string>
Only visible to the host. -
HasPassword
- ActionValue<bool> Players
- List<LocalPlayer>-
ClientIdToPlayer
- Dictionary<ulong, LocalPlayer>
Maps the Netcode client id to the LocalPlayer. Only visible to the host. -
RelayCode
- LobbyActionValue<string> Any Custom Lobby Value
- LobbyActionValue<T>CustomDataMap
- Dictionary<string, ILobbyValue>
Debug.Log(LobbyManager.Instance.CurrentLobby.Name.Value);
Debug.Log(LobbyManager.Instance.CurrentLobby.MyCustomValue.Value);
LobbyManager.Instance.CurrentLobby.Name.OnValueChanged += (oldValue, newValue) =>
{
Debug.Log($"Lobby name changed from {oldValue} to {newValue}");
};
// Or
void OnNameChanged(string oldValue, string newValue)
{
Debug.Log($"Lobby name changed from {oldValue} to {newValue}");
}
LobbyManager.Instance.CurrentLobby.Name.OnValueChanged += OnNameChanged;
Refer to Action Value for more information.
Methods
UpdateLobbyData
Declaration
Task UpdateLobbyData( )
Description
Sends all updated lobby values to the server. Only the host can send changes to the server.
Example:
LobbyManager.Instance.CurrentLobby.MyCustomValue.Value = 99;
LobbyManager.Instance.CurrentLobby.Name.Value = "New Lobby Name";
await LobbyManager.Instance.CurrentLobby.UpdateLobbyData();
Events
OnPlayerJoined
Parameters
LocalPlayer
- The player that joined the lobby.
Description
Event that is called when a player joins the lobby.
OnPlayerRemoved
Parameters
LocalPlayer
- The player that left the lobby.int
- The index of the player in the player list (Do not use this index to access the player in the player list as it will be unavailable).
Description
Event that is called when a player leaves the lobby.