Many multiplayer games have a staging area for players to join before playing the actual game. In this area - often called the “lobby”, players may be able to pick options and be able to set themselves as ready for the game to start.
The NetworkLobbyManager is a specialized NetworkManager that provides a lobby for Unity Multiplayer games. It includes:
The GuiLobbyManager is a special lobby manager that provides a user-interface for the lobby. It is available as an asset package and can be imported into Unity projects to easily add a lobby to multiplayer games. The scripts and UI prefabs in the package can be customized to make the look and feel of the lobby unique for any game.
There are two kinds of player objects - each which has a prefab slot in the NetworkLobbyManager:
LobbyPlayer Object
GamePlayer Object
The NetworkLobbyPlayer component is used for LobbyPlayer objects. It supplies some virtual function callbacks that can be used for custom lobby behaviour
public virtual void OnClientEnterLobby()
{
}
public virtual void OnClientExitLobby()
{
}
public virtual void OnClientReady(bool readyState)
{
}
Process for adding a NetworkLobby to a multiplayer game (without using the multiplayer-lobby asset package):
This version of the NetworkLobbyManager uses the OnGUI user interface like the NetworkManagerHUD. For a better user interface use the multiplayer-lobby asset package.
The NetworkLobbyManager has many virtual function callbacks that can be used for custom lobby behaviour. Most important is OnLobbyServerSceneLoadedForPlayer which is called on the server for each player as they transition from the lobby to the main game. This is the ideal place to apply settings from the lobby to the player’s game-play object.
// for users to apply settings from their lobby player object to their in-game player object
public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
{
var cc = lobbyPlayer.GetComponent<ColorControl>();
var player = gamePlayer.GetComponent<Player>();
player.myColor = cc.myColor;
return true;
}