2020-02-18 04:10:47 +00:00
# Network Room Manager
2019-02-20 15:58:50 +00:00
2019-09-11 08:06:25 +00:00
\*\*Please see the Room example in the Examples folder in your Mirror folder
2019-02-20 15:58:50 +00:00
2019-09-11 08:06:25 +00:00
The Network Room Manager is a specialized type of [Network Manager ](NetworkManager.md ) that provides a multiplayer room before entering the main play scene of the game. It allows you to set up a network with:
2019-02-20 15:58:50 +00:00
- A maximum player limit
- Automatic start when all players are ready
- Option to prevent players from joining a game in progress
2019-09-11 08:06:25 +00:00
- Customizable ways for players to choose options while in room
2019-06-25 17:38:10 +00:00
2019-09-11 08:06:25 +00:00
There are two types of player objects with the Network Room Manager:
2019-02-20 15:58:50 +00:00
2019-09-11 08:06:25 +00:00
**Room Player Prefab**
2019-02-20 15:58:50 +00:00
- One for each player
- Created when client connects, or player is added
- Persists until client disconnects
- Holds ready flag and configuration data
2019-09-11 08:06:25 +00:00
- Handles commands in the room
- Must use the [Network Room Player ](NetworkRoomPlayer.md ) component
2019-02-20 15:58:50 +00:00
**Player Prefab**
- One for each player
- Created when game scene is started
- Destroyed when leaving game scene
2019-06-25 17:38:10 +00:00
- Handles commands in the game
2019-02-20 15:58:50 +00:00
2019-09-11 15:16:22 +00:00
![Network Room Manager ](NetworkRoomManager.png )
2019-02-20 15:58:50 +00:00
## Properties
2019-09-11 08:06:25 +00:00
- **Show Room GUI**
Show the default OnGUI controls for the room.
2019-02-20 15:58:50 +00:00
- **Min Players**
Minimum number of players needed to start a game.
2019-09-11 08:06:25 +00:00
- **Room Player Prefab**
The prefab to create for players when they enter the room (requires Network Room Player component).
- **Room Scene**
The scene to use for the room.
2019-02-20 15:58:50 +00:00
- **Gameplay Scene**
The scene to use for main game play.
2019-07-06 17:16:05 +00:00
- **pendingPlayers**
List\<PendingPlayer\> that holds players that are ready to start playing.
2019-09-11 08:06:25 +00:00
- **roomSlots**
List\<NetworkRoomPlayer\> that manages the slots for connected clients in the room.
2019-07-06 17:16:05 +00:00
- **allPlayersReady**
Bool indicating if all players are ready to start playing. This value changes as players invoke `CmdChangeReadyState` indicating true or false, and will be set false when a new client connects.
## Methods
### Server Virtual Methods
2019-07-07 06:05:45 +00:00
```cs
2019-09-11 08:06:25 +00:00
public virtual void OnRoomStartHost() {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomStopHost() {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomStartServer() {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomServerConnect(NetworkConnection conn) {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomServerDisconnect(NetworkConnection conn) {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomServerSceneChanged(string sceneName) {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual GameObject OnRoomServerCreateRoomPlayer(NetworkConnection conn)
2019-07-06 17:16:05 +00:00
{
return null;
}
2019-09-11 08:06:25 +00:00
public virtual GameObject OnRoomServerCreateGamePlayer(NetworkConnection conn)
2019-07-06 17:16:05 +00:00
{
return null;
}
2019-09-11 08:06:25 +00:00
public virtual bool OnRoomServerSceneLoadedForPlayer(GameObject roomPlayer, GameObject gamePlayer)
2019-07-06 17:16:05 +00:00
{
return true;
}
2019-09-11 08:06:25 +00:00
public virtual void OnRoomServerPlayersReady()
2019-07-06 17:16:05 +00:00
{
ServerChangeScene(GameplayScene);
}
```
### Client Virtual Methods
2019-07-07 06:05:45 +00:00
```cs
2019-09-11 08:06:25 +00:00
public virtual void OnRoomClientEnter() {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomClientExit() {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomClientConnect(NetworkConnection conn) {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomClientDisconnect(NetworkConnection conn) {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomStartClient() {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomStopClient() {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomClientSceneChanged(NetworkConnection conn) {}
2019-07-06 17:16:05 +00:00
2019-09-11 08:06:25 +00:00
public virtual void OnRoomClientAddPlayerFailed() {}
2019-07-06 17:16:05 +00:00
```