Class NetworkLobbyPlayer
This component works in conjunction with the NetworkLobbyManager to make up the multiplayer lobby system.
The LobbyPrefab object of the NetworkLobbyManager must have this component on it. This component holds basic lobby player data required for the lobby to function. Game specific data for lobby players can be put in other components on the LobbyPrefab or in scripts derived from NetworkLobbyPlayer.
Inherited Members
Namespace: UnityEngine.Networking
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("Network/NetworkLobbyPlayer")]
[Obsolete("The high level API classes are deprecated and will be removed in the future.")]
public class NetworkLobbyPlayer : NetworkBehaviour
Fields
ShowLobbyGUI
This flag controls whether the default UI is shown for the lobby player.
As this UI is rendered using the old GUI system, it is only recommended for testing purposes.
Declaration
[Tooltip("Enable to show the default lobby GUI for this player.")]
[SerializeField]
public bool ShowLobbyGUI
Field Value
Type | Description |
---|---|
Boolean |
Properties
readyToBegin
This is a flag that control whether this player is ready for the game to begin.
When all players are ready to begin, the game will start. This should not be set directly, the SendReadyToBeginMessage function should be called on the client to set it on the server.
Declaration
public bool readyToBegin { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
slot
The slot within the lobby that this player inhabits.
Lobby slots are global for the game - each player has a unique slotId.
Declaration
public byte slot { get; set; }
Property Value
Type | Description |
---|---|
Byte |
Methods
OnClientEnterLobby()
This is a hook that is invoked on all player objects when entering the lobby.
Note: isLocalPlayer is not guaranteed to be set until OnStartLocalPlayer is called.
Declaration
public virtual void OnClientEnterLobby()
OnClientExitLobby()
This is a hook that is invoked on all player objects when exiting the lobby.
Declaration
public virtual void OnClientExitLobby()
OnClientReady(Boolean)
This is a hook that is invoked on clients when a LobbyPlayer switches between ready or not ready.
This function is called when the a client player calls SendReadyToBeginMessage() or SendNotReadyToBeginMessage().
Declaration
public virtual void OnClientReady(bool readyState)
Parameters
Type | Name | Description |
---|---|---|
Boolean | readyState | Whether the player is ready or not. |
OnDeserialize(NetworkReader, Boolean)
Declaration
public override void OnDeserialize(NetworkReader reader, bool initialState)
Parameters
Type | Name | Description |
---|---|---|
NetworkReader | reader | |
Boolean | initialState |
Overrides
OnSerialize(NetworkWriter, Boolean)
Declaration
public override bool OnSerialize(NetworkWriter writer, bool initialState)
Parameters
Type | Name | Description |
---|---|---|
NetworkWriter | writer | |
Boolean | initialState |
Returns
Type | Description |
---|---|
Boolean |
Overrides
OnStartClient()
Declaration
public override void OnStartClient()
Overrides
RemovePlayer()
This removes this player from the lobby.
This player object will be destroyed - on the server and on all clients.
Declaration
public void RemovePlayer()
SendNotReadyToBeginMessage()
This is used on clients to tell the server that this player is not ready for the game to begin.
Declaration
public void SendNotReadyToBeginMessage()
SendReadyToBeginMessage()
This is used on clients to tell the server that this player is ready for the game to begin.
Declaration
public void SendReadyToBeginMessage()
SendSceneLoadedMessage()
This is used on clients to tell the server that the client has switched from the lobby to the GameScene and is ready to play.
This message triggers the server to replace the lobby player with the game player.
Declaration
public void SendSceneLoadedMessage()