Class NetworkRoomManager
This is a specialized NetworkManager that includes a networked room.
Inherited Members
Namespace: Mirror
Assembly: doc.dll
Syntax
public class NetworkRoomManager : NetworkManager
Remarks
The room has slots that track the joined players, and a maximum player count that is enforced. It requires that the NetworkRoomPlayer component be on the room player objects.
NetworkRoomManager is derived from NetworkManager, and so it implements many of the virtual functions provided by the NetworkManager class. To avoid accidentally replacing functionality of the NetworkRoomManager, there are new virtual functions on the NetworkRoomManager that begin with "OnRoom". These should be used on classes derived from NetworkRoomManager instead of the virtual functions on NetworkManager.
The OnRoom*() functions have empty implementations on the NetworkRoomManager base class, so the base class functions do not have to be called.
Fields
| Improve this Doc View SourceclientIndex
Declaration
public int clientIndex
Field Value
Type | Description |
---|---|
Int32 |
GameplayScene
The scene to use for the playing the game from the room. This is similar to the onlineScene of the NetworkManager.
Declaration
public string GameplayScene
Field Value
Type | Description |
---|---|
String |
minPlayers
Declaration
public int minPlayers
Field Value
Type | Description |
---|---|
Int32 |
pendingPlayers
List of players that are in the Room
Declaration
public List<NetworkRoomManager.PendingPlayer> pendingPlayers
Field Value
Type | Description |
---|---|
List<NetworkRoomManager.PendingPlayer> |
roomPlayerPrefab
Declaration
public NetworkRoomPlayer roomPlayerPrefab
Field Value
Type | Description |
---|---|
NetworkRoomPlayer |
RoomScene
The scene to use for the room. This is similar to the offlineScene of the NetworkManager.
Declaration
public string RoomScene
Field Value
Type | Description |
---|---|
String |
roomSlots
These slots track players that enter the room.
The slotId on players is global to the game - across all players.
Declaration
public List<NetworkRoomPlayer> roomSlots
Field Value
Type | Description |
---|---|
List<NetworkRoomPlayer> |
showRoomGUI
Declaration
public bool showRoomGUI
Field Value
Type | Description |
---|---|
Boolean |
Properties
| Improve this Doc View SourceallPlayersReady
Declaration
public bool allPlayersReady { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceCheckReadyToBegin()
CheckReadyToBegin checks all of the players in the room to see if their readyToBegin flag is set.
If all of the players are ready, then the server switches from the RoomScene to the PlayScene, essentially starting the game. This is called automatically in response to NetworkRoomPlayer.CmdChangeReadyState.
Declaration
public void CheckReadyToBegin()
OnClientConnect()
Called on the client when connected to a server.
The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.
Declaration
public override void OnClientConnect()
Overrides
| Improve this Doc View SourceOnClientDisconnect()
Called on clients when disconnected from a server.
This is called on the client when it disconnects from the server. Override this function to decide what happens when the client disconnects.
Declaration
public override void OnClientDisconnect()
Overrides
| Improve this Doc View SourceOnClientSceneChanged()
Called on clients when a scene has completed loaded, when the scene load was initiated by the server.
Scene changes can cause player objects to be destroyed. The default implementation of OnClientSceneChanged in the NetworkManager is to add a player object for the connection if no player object exists.
Declaration
public override void OnClientSceneChanged()
Overrides
| Improve this Doc View SourceOnGUI()
virtual so inheriting classes can roll their own
Declaration
public virtual void OnGUI()
OnRoomClientAddPlayerFailed()
Called on the client when adding a player to the room fails.
This could be because the room is full, or the connection is not allowed to have more players.
Declaration
public virtual void OnRoomClientAddPlayerFailed()
OnRoomClientConnect()
This is called on the client when it connects to server.
Declaration
public virtual void OnRoomClientConnect()
OnRoomClientDisconnect()
This is called on the client when disconnected from a server.
Declaration
public virtual void OnRoomClientDisconnect()
OnRoomClientEnter()
This is a hook to allow custom behaviour when the game client enters the room.
Declaration
public virtual void OnRoomClientEnter()
OnRoomClientExit()
This is a hook to allow custom behaviour when the game client exits the room.
Declaration
public virtual void OnRoomClientExit()
OnRoomClientSceneChanged()
This is called on the client when the client is finished loading a new networked scene.
Declaration
public virtual void OnRoomClientSceneChanged()
OnRoomServerAddPlayer(NetworkConnectionToClient)
This allows customization of the creation of the GamePlayer object on the server.
This is only called for subsequent GamePlay scenes after the first one.
See OnRoomServerCreateGamePlayer(NetworkConnection, GameObject) to customize the player object for the initial GamePlay scene.
Declaration
public virtual void OnRoomServerAddPlayer(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | The connection the player object is for. |
OnRoomServerConnect(NetworkConnectionToClient)
This is called on the server when a new client connects to the server.
Declaration
public virtual void OnRoomServerConnect(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | The new connection. |
OnRoomServerCreateGamePlayer(NetworkConnectionToClient, GameObject)
This allows customization of the creation of the GamePlayer object on the server.
By default the gamePlayerPrefab is used to create the game-player, but this function allows that behaviour to be customized. The object returned from the function will be used to replace the room-player on the connection.
Declaration
public virtual GameObject OnRoomServerCreateGamePlayer(NetworkConnectionToClient conn, GameObject roomPlayer)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | The connection the player object is for. |
GameObject | roomPlayer | The room player object for this connection. |
Returns
Type | Description |
---|---|
GameObject | A new GamePlayer object. |
OnRoomServerCreateRoomPlayer(NetworkConnectionToClient)
This allows customization of the creation of the room-player object on the server.
By default the roomPlayerPrefab is used to create the room-player, but this function allows that behaviour to be customized.
Declaration
public virtual GameObject OnRoomServerCreateRoomPlayer(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | The connection the player object is for. |
Returns
Type | Description |
---|---|
GameObject | The new room-player object. |
OnRoomServerDisconnect(NetworkConnectionToClient)
This is called on the server when a client disconnects.
Declaration
public virtual void OnRoomServerDisconnect(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | The connection that disconnected. |
OnRoomServerPlayersNotReady()
This is called on the server when CheckReadyToBegin finds that players are not ready
May be called multiple times while not ready players are joining
Declaration
public virtual void OnRoomServerPlayersNotReady()
OnRoomServerPlayersReady()
This is called on the server when all the players in the room are ready.
The default implementation of this function uses ServerChangeScene() to switch to the game player scene. By implementing this callback you can customize what happens when all the players in the room are ready, such as adding a countdown or a confirmation for a group leader.
Declaration
public virtual void OnRoomServerPlayersReady()
OnRoomServerSceneChanged(String)
This is called on the server when a networked scene finishes loading.
Declaration
public virtual void OnRoomServerSceneChanged(string sceneName)
Parameters
Type | Name | Description |
---|---|---|
String | sceneName | Name of the new scene. |
OnRoomServerSceneLoadedForPlayer(NetworkConnectionToClient, GameObject, GameObject)
This is called on the server when it is told that a client has finished switching from the room scene to a game player scene.
When switching from the room, the room-player is replaced with a game-player object. This callback function gives an opportunity to apply state from the room-player to the game-player object.
Declaration
public virtual bool OnRoomServerSceneLoadedForPlayer(NetworkConnectionToClient conn, GameObject roomPlayer, GameObject gamePlayer)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | The connection of the player |
GameObject | roomPlayer | The room player object. |
GameObject | gamePlayer | The game player object. |
Returns
Type | Description |
---|---|
Boolean | False to not allow this player to replace the room player. |
OnRoomStartClient()
This is called on the client when a client is started.
Declaration
public virtual void OnRoomStartClient()
OnRoomStartHost()
This is called on the host when a host is started.
Declaration
public virtual void OnRoomStartHost()
OnRoomStartServer()
This is called on the server when the server is started - including when a host is started.
Declaration
public virtual void OnRoomStartServer()
OnRoomStopClient()
This is called on the client when the client stops.
Declaration
public virtual void OnRoomStopClient()
OnRoomStopHost()
This is called on the host when the host is stopped.
Declaration
public virtual void OnRoomStopHost()
OnRoomStopServer()
This is called on the server when the server is started - including when a host is stopped.
Declaration
public virtual void OnRoomStopServer()
OnServerAddPlayer(NetworkConnectionToClient)
Called on the server when a client adds a new player with NetworkClient.AddPlayer.
The default implementation for this function creates a new player object from the playerPrefab.
Declaration
public override void OnServerAddPlayer(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | Connection from client. |
Overrides
| Improve this Doc View SourceOnServerConnect(NetworkConnectionToClient)
Called on the server when a new client connects.
Unity calls this on the Server when a Client connects to the Server. Use an override to tell the NetworkManager what to do when a client connects to the server.
Declaration
public override void OnServerConnect(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | Connection from client. |
Overrides
| Improve this Doc View SourceOnServerDisconnect(NetworkConnectionToClient)
Called on the server when a client disconnects.
This is called on the Server when a Client disconnects from the Server. Use an override to decide what should happen when a disconnection is detected.
Declaration
public override void OnServerDisconnect(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | Connection from client. |
Overrides
| Improve this Doc View SourceOnServerReady(NetworkConnectionToClient)
Called on the server when a client is ready.
The default implementation of this function calls NetworkServer.SetClientReady() to continue the network setup process.
Declaration
public override void OnServerReady(NetworkConnectionToClient conn)
Parameters
Type | Name | Description |
---|---|---|
NetworkConnectionToClient | conn | Connection from client. |
Overrides
| Improve this Doc View SourceOnServerSceneChanged(String)
Called on the server when a scene is completed loaded, when the scene load was initiated by the server with ServerChangeScene().
Declaration
public override void OnServerSceneChanged(string sceneName)
Parameters
Type | Name | Description |
---|---|---|
String | sceneName | The name of the new scene. |
Overrides
| Improve this Doc View SourceOnStartClient()
This is invoked when the client is started.
Declaration
public override void OnStartClient()
Overrides
| Improve this Doc View SourceOnStartHost()
This is invoked when a host is started.
StartHost has multiple signatures, but they all cause this hook to be called.
Declaration
public override void OnStartHost()
Overrides
| Improve this Doc View SourceOnStartServer()
This is invoked when a server is started - including when a host is started.
StartServer has multiple signatures, but they all cause this hook to be called.
Declaration
public override void OnStartServer()
Overrides
| Improve this Doc View SourceOnStopClient()
This is called when a client is stopped.
Declaration
public override void OnStopClient()
Overrides
| Improve this Doc View SourceOnStopHost()
This is called when a host is stopped.
Declaration
public override void OnStopHost()
Overrides
| Improve this Doc View SourceOnStopServer()
This is called when a server is stopped - including when a host is stopped.
Declaration
public override void OnStopServer()
Overrides
| Improve this Doc View SourceOnValidate()
Declaration
public override void OnValidate()
Overrides
| Improve this Doc View SourceReadyStatusChanged()
Declaration
public void ReadyStatusChanged()
RecalculateRoomPlayerIndices()
Declaration
public void RecalculateRoomPlayerIndices()
ServerChangeScene(String)
This causes the server to switch scenes and sets the networkSceneName.
Clients that connect to this server will automatically switch to this scene. This is called automatically if onlineScene or offlineScene are set, but it can be called from user code to switch scenes again while the game is in progress. This automatically sets clients to be not-ready. The clients must call NetworkClient.Ready() again to participate in the new scene.
Declaration
public override void ServerChangeScene(string newSceneName)
Parameters
Type | Name | Description |
---|---|---|
String | newSceneName |