Local Player
Implemented in: EasyGameLobby
Wraps around Player instances, providing an interface for easy management and listening to player 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 player represented by the instance can send changes to the server using the UpdatePlayerData
method. Do not modify any data if the current player is not the player represented by the instance.
Any custom player 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(
(PlayerActionValue<int>)LobbyManager.Instance.CurrentPlayer["MyCustomPlayerValue"].Value
);
// Or
Debug.Log(
(PlayerActionValue<int>)LobbyManager.Instance.CurrentPlayer.CustomDataMap["MyCustomPlayerValue"].Value
);
Player Data
Id
- string Read-Only-
ClientId
- ulong Read-Only
Only visible to the host. -
IsHost
- LobbyActionValue<bool> -
IsConnected
- LobbyActionValue<bool>
True if the player is connected to the relay. Only visible to the host. -
Any Custom Player Value
- LobbyActionValue<T> CustomDataMap
- Dictionary<string, ILobbyValue>
Debug.Log(LobbyManager.Instance.CurrentPlayer.IsHost.Value);
Debug.Log(LobbyManager.Instance.CurrentPlayer.MyCustomPlayerValue.Value);
LobbyManager.Instance.CurrentPlayer.IsHost.OnValueChanged += (oldValue, newValue) =>
{
Debug.Log($"Is host changed from {oldValue} to {newValue}");
};
// Or
void OnIsHostChanged(bool oldValue, bool newValue)
{
Debug.Log($"Is host changed from {oldValue} to {newValue}");
}
LobbyManager.Instance.CurrentPlayer.IsHost.OnValueChanged += OnIsHostChanged;
Refer to Action Value for more information.
Methods
UpdatePlayerData
Declaration
Task UpdatePlayerData( )
Description
Updates the player data on the server. Only the player represented by the instance can send changes to the server.