Search Results for

    Show / Hide Table of Contents

    Class NetworkRoomManager

    This is a specialized NetworkManager that includes a networked room.

    Inheritance
    Object
    NetworkManager
    NetworkRoomManager
    NetworkLobbyManager
    Inherited Members
    NetworkManager.dontDestroyOnLoad
    NetworkManager.runInBackground
    NetworkManager.autoStartServerBuild
    NetworkManager.serverTickRate
    NetworkManager.offlineScene
    NetworkManager.onlineScene
    NetworkManager.transport
    NetworkManager.networkAddress
    NetworkManager.maxConnections
    NetworkManager.authenticator
    NetworkManager.playerPrefab
    NetworkManager.autoCreatePlayer
    NetworkManager.playerSpawnMethod
    NetworkManager.spawnPrefabs
    NetworkManager.startPositions
    NetworkManager.startPositionIndex
    NetworkManager.singleton
    NetworkManager.numPlayers
    NetworkManager.isNetworkActive
    NetworkManager.clientLoadedScene
    NetworkManager.mode
    NetworkManager.Reset()
    NetworkManager.Awake()
    NetworkManager.Start()
    NetworkManager.LateUpdate()
    NetworkManager.IsSceneActive(String)
    NetworkManager.StartServer()
    NetworkManager.StartClient()
    NetworkManager.StartClient(Uri)
    NetworkManager.StartHost()
    NetworkManager.StopHost()
    NetworkManager.StopServer()
    NetworkManager.StopClient()
    NetworkManager.OnApplicationQuit()
    NetworkManager.ConfigureHeadlessFrameRate()
    NetworkManager.ResetStatics()
    NetworkManager.OnDestroy()
    NetworkManager.networkSceneName
    NetworkManager.loadingSceneAsync
    NetworkManager.FinishLoadScene()
    NetworkManager.RegisterStartPosition(Transform)
    NetworkManager.UnRegisterStartPosition(Transform)
    NetworkManager.GetStartPosition()
    NetworkManager.OnServerError(NetworkConnectionToClient, Exception)
    NetworkManager.OnServerError(NetworkConnectionToClient, TransportError, String)
    NetworkManager.OnServerChangeScene(String)
    NetworkManager.OnClientError(Exception)
    NetworkManager.OnClientError(TransportError, String)
    NetworkManager.OnClientNotReady()
    NetworkManager.OnClientChangeScene(String, SceneOperation, Boolean)
    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 Source

    clientIndex

    Declaration
    public int clientIndex
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    minPlayers

    Declaration
    public int minPlayers
    Field Value
    Type Description
    Int32
    | Improve this Doc View Source

    pendingPlayers

    List of players that are in the Room

    Declaration
    public List<NetworkRoomManager.PendingPlayer> pendingPlayers
    Field Value
    Type Description
    List<NetworkRoomManager.PendingPlayer>
    | Improve this Doc View Source

    roomPlayerPrefab

    Declaration
    public NetworkRoomPlayer roomPlayerPrefab
    Field Value
    Type Description
    NetworkRoomPlayer
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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>
    | Improve this Doc View Source

    showRoomGUI

    Declaration
    public bool showRoomGUI
    Field Value
    Type Description
    Boolean

    Properties

    | Improve this Doc View Source

    allPlayersReady

    Declaration
    public bool allPlayersReady { get; set; }
    Property Value
    Type Description
    Boolean

    Methods

    | Improve this Doc View Source

    CheckReadyToBegin()

    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()
    | Improve this Doc View Source

    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
    NetworkManager.OnClientConnect()
    | Improve this Doc View Source

    OnClientDisconnect()

    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
    NetworkManager.OnClientDisconnect()
    | Improve this Doc View Source

    OnClientSceneChanged()

    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
    NetworkManager.OnClientSceneChanged()
    | Improve this Doc View Source

    OnGUI()

    virtual so inheriting classes can roll their own

    Declaration
    public virtual void OnGUI()
    | Improve this Doc View Source

    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()
    | Improve this Doc View Source

    OnRoomClientConnect()

    This is called on the client when it connects to server.

    Declaration
    public virtual void OnRoomClientConnect()
    | Improve this Doc View Source

    OnRoomClientDisconnect()

    This is called on the client when disconnected from a server.

    Declaration
    public virtual void OnRoomClientDisconnect()
    | Improve this Doc View Source

    OnRoomClientEnter()

    This is a hook to allow custom behaviour when the game client enters the room.

    Declaration
    public virtual void OnRoomClientEnter()
    | Improve this Doc View Source

    OnRoomClientExit()

    This is a hook to allow custom behaviour when the game client exits the room.

    Declaration
    public virtual void OnRoomClientExit()
    | Improve this Doc View Source

    OnRoomClientSceneChanged()

    This is called on the client when the client is finished loading a new networked scene.

    Declaration
    public virtual void OnRoomClientSceneChanged()
    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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()
    | Improve this Doc View Source

    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()
    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    OnRoomStartClient()

    This is called on the client when a client is started.

    Declaration
    public virtual void OnRoomStartClient()
    | Improve this Doc View Source

    OnRoomStartHost()

    This is called on the host when a host is started.

    Declaration
    public virtual void OnRoomStartHost()
    | Improve this Doc View Source

    OnRoomStartServer()

    This is called on the server when the server is started - including when a host is started.

    Declaration
    public virtual void OnRoomStartServer()
    | Improve this Doc View Source

    OnRoomStopClient()

    This is called on the client when the client stops.

    Declaration
    public virtual void OnRoomStopClient()
    | Improve this Doc View Source

    OnRoomStopHost()

    This is called on the host when the host is stopped.

    Declaration
    public virtual void OnRoomStopHost()
    | Improve this Doc View Source

    OnRoomStopServer()

    This is called on the server when the server is started - including when a host is stopped.

    Declaration
    public virtual void OnRoomStopServer()
    | Improve this Doc View Source

    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
    NetworkManager.OnServerAddPlayer(NetworkConnectionToClient)
    | Improve this Doc View Source

    OnServerConnect(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
    NetworkManager.OnServerConnect(NetworkConnectionToClient)
    | Improve this Doc View Source

    OnServerDisconnect(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
    NetworkManager.OnServerDisconnect(NetworkConnectionToClient)
    | Improve this Doc View Source

    OnServerReady(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
    NetworkManager.OnServerReady(NetworkConnectionToClient)
    | Improve this Doc View Source

    OnServerSceneChanged(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
    NetworkManager.OnServerSceneChanged(String)
    | Improve this Doc View Source

    OnStartClient()

    This is invoked when the client is started.

    Declaration
    public override void OnStartClient()
    Overrides
    NetworkManager.OnStartClient()
    | Improve this Doc View Source

    OnStartHost()

    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
    NetworkManager.OnStartHost()
    | Improve this Doc View Source

    OnStartServer()

    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
    NetworkManager.OnStartServer()
    | Improve this Doc View Source

    OnStopClient()

    This is called when a client is stopped.

    Declaration
    public override void OnStopClient()
    Overrides
    NetworkManager.OnStopClient()
    | Improve this Doc View Source

    OnStopHost()

    This is called when a host is stopped.

    Declaration
    public override void OnStopHost()
    Overrides
    NetworkManager.OnStopHost()
    | Improve this Doc View Source

    OnStopServer()

    This is called when a server is stopped - including when a host is stopped.

    Declaration
    public override void OnStopServer()
    Overrides
    NetworkManager.OnStopServer()
    | Improve this Doc View Source

    OnValidate()

    Declaration
    public override void OnValidate()
    Overrides
    NetworkManager.OnValidate()
    | Improve this Doc View Source

    ReadyStatusChanged()

    Declaration
    public void ReadyStatusChanged()
    | Improve this Doc View Source

    RecalculateRoomPlayerIndices()

    Declaration
    public void RecalculateRoomPlayerIndices()
    | Improve this Doc View Source

    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
    Overrides
    NetworkManager.ServerChangeScene(String)
    • Improve this Doc
    • View Source
    In This Article
    Back to top Generated by DocFX