2019-07-20 00:05:55 +00:00
# NetworkLobbyManager
2019-02-20 15:58:50 +00:00
2019-06-25 17:38:10 +00:00
\*\*Please see the Lobby example in the Examples folder in your Mirror folder
2019-02-20 15:58:50 +00:00
2019-08-24 15:20:33 +00:00
The Network Lobby Manager is a specialized type of [Network Manager ](NetworkManager.md ) that provides a multiplayer lobby 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
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- Automatic start when all players are ready
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- Option to prevent players from joining a game in progress
2019-06-25 17:38:10 +00:00
- Customizable ways for players to choose options while in lobby
There are two types of player objects with the Network Lobby Manager:
2019-02-20 15:58:50 +00:00
**Lobby Player Prefab**
- One for each player
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- Created when client connects, or player is added
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- Persists until client disconnects
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- Holds ready flag and configuration data
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- Handles commands in the lobby
2019-06-25 17:38:10 +00:00
2019-08-24 15:20:33 +00:00
- Must use the [Network Lobby Player ](NetworkLobbyPlayer.md ) component
2019-02-20 15:58:50 +00:00
**Player Prefab**
- One for each player
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- Created when game scene is started
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- 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
![Network Lobby Manager ](NetworkLobbyManager.PNG )
## Properties
- **Show Lobby GUI**
Show the default OnGUI controls for the lobby.
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- **Min Players**
Minimum number of players needed to start a game.
2019-06-25 17:38:10 +00:00
2019-02-20 15:58:50 +00:00
- **Lobby Player Prefab**
2019-06-25 17:38:10 +00:00
The prefab to create for players when they enter the lobby (requires Network Lobby Player component).
2019-02-20 15:58:50 +00:00
- **Lobby Scene**
The scene to use for the lobby.
2019-06-25 17:38:10 +00:00
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.
- **lobbySlots**
List\<NetworkLobbyPlayer\> that manages the slots for connected clients in the lobby.
- **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-07-06 17:16:05 +00:00
public virtual void OnLobbyStartHost() {}
public virtual void OnLobbyStopHost() {}
public virtual void OnLobbyStartServer() {}
public virtual void OnLobbyServerConnect(NetworkConnection conn) {}
public virtual void OnLobbyServerDisconnect(NetworkConnection conn) {}
public virtual void OnLobbyServerSceneChanged(string sceneName) {}
public virtual GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn)
{
return null;
}
public virtual GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn)
{
return null;
}
public virtual bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
{
return true;
}
public virtual void OnLobbyServerPlayersReady()
{
ServerChangeScene(GameplayScene);
}
```
### Client Virtual Methods
2019-07-07 06:05:45 +00:00
```cs
2019-07-06 17:16:05 +00:00
public virtual void OnLobbyClientEnter() {}
public virtual void OnLobbyClientExit() {}
public virtual void OnLobbyClientConnect(NetworkConnection conn) {}
public virtual void OnLobbyClientDisconnect(NetworkConnection conn) {}
public virtual void OnLobbyStartClient() {}
public virtual void OnLobbyStopClient() {}
public virtual void OnLobbyClientSceneChanged(NetworkConnection conn) {}
public virtual void OnLobbyClientAddPlayerFailed() {}
```