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
Assembly: com.unity.multiplayer-hlapi.Runtime.dll
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 |
---|---|
bool |
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 |
---|---|
bool |
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(bool)
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 |
---|---|---|
bool | readyState | Whether the player is ready or not. |
OnDeserialize(NetworkReader, bool)
Virtual function to override to receive custom serialization data. The corresponding function to send serialization data is OnSerialize().
Declaration
public override void OnDeserialize(NetworkReader reader, bool initialState)
Parameters
Type | Name | Description |
---|---|---|
NetworkReader | reader | Reader to read from the stream. |
bool | initialState | True if being sent initial state. |
Overrides
OnSerialize(NetworkWriter, bool)
Virtual function to override to send custom serialization data. The corresponding function to send serialization data is OnDeserialize().
The initialState flag is useful to differentiate between the first time an object is serialized and when incremental updates can be sent. The first time an object is sent to a client, it must include a full state snapshot, but subsequent updates can save on bandwidth by including only incremental changes. Note that SyncVar hook functions are not called when initialState is true, only for incremental updates.
If a class has SyncVars, then an implementation of this function and OnDeserialize() are added automatically to the class. So a class that has SyncVars cannot also have custom serialization functions.
The OnSerialize function should return true to indicate that an update should be sent. If it returns true, then the dirty bits for that script are set to zero, if it returns false then the dirty bits are not changed. This allows multiple changes to a script to be accumulated over time and sent when the system is ready, instead of every frame.
Declaration
public override bool OnSerialize(NetworkWriter writer, bool initialState)
Parameters
Type | Name | Description |
---|---|---|
NetworkWriter | writer | Writer to use to write to the stream. |
bool | initialState | If this is being called to send initial state. |
Returns
Type | Description |
---|---|
bool | True if data was written. |
Overrides
OnStartClient()
Called on every NetworkBehaviour when it is activated on a client.
Objects on the host have this function called, as there is a local client on the host. The values of SyncVars on object are guaranteed to be initialized correctly with the latest state from the server when this function is called on the client.
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()