Sun Guangdong 2015.7.12
Multiplayer Lobby Multiplayer Hall
A lot of multiplayer games have a registers (staging area): The actual game waits for all players to join the place, in this region-often referred to as "lobby", the player may be able to select options that can set themselves to start after the game is ready.
Networklobbymanager is a dedicated NetworkManager network manager that can provide the Unity multiplayer Game Hall (Unity multiplayer lobby). It includes:
• Limit the number of players that can be added
• Each client supports multiple players, then limit the number of players per client
• Prevent players from joining when playing in-progress
• Each player is ready to play, so all players are ready to start the game
• Per player configuration data
• Rejoin the lobby when the game is over
• Virtual function, which allows custom logic to lobby events
Guilobbymanager is a UI for lobby special lobby management. It can be used as an asset pack (asset package) and can be imported into the Unity project to easily add a lobby to multiplayer games. Scripts and UI presets can be customized in packages to make the appearance and feel different.
There are two types of player objects-each prefabricated slot in the Networklobbymanager (prefab slot):
Lobbyplayer Objects
• Each player
• Create a client connection or be created when you add a player
• Persistent until client disconnects
• Ready for the player in the lobby flag
• Handling orders in the lobby
• Add user scripts to prefab to save game-specific player data
Gameplayer objects
• Each player
• Create when you start a game scene
• Be destroyed when entering the hall again
• Process commands in the game
The Networklobbyplayer component is used for Lobbyplayer objects. It provides a number of virtual function callbacks that can be used to customize the lobby behavior
public virtual void Oncliententerlobby ()
{
} public
virtual void Onclientexitlobby ()
{
}
public virtual void Onclientready (bool readyState)
{
}
Add Lobby to a Game:
The process of adding networklobby to multiplayer games (no multiplayer lobby asset packs):
• Create a new lobbyscene lobby scene
• Scene added to build settings, will be the first scene
• Create a new gameobject in the new scene and rename it to Lobbymanager
• Add the Networklobbymanager component to the Lobbymanager object
• Add the Networkmanagerhud component to the Lobbymanager object
• Open the Networklobbymanager component on the Inspector panel
• Set Lobbyscene to the current scene
• Set Playscene as the main game scene
• Create a new game object and rename it to Lobbyplayer
• Add the Networklobbyplayer component to the Lobbyplayer
• Create a preset for Lobbyplayer to remove this instance from the scene
• Set Lobbyplayerprefab slots as Lobbyplayer presets
• The player's Gameplayerprefab slot in main game is set to this prefab
• Save the scene.
• Run games
This version of Networklobbymanager uses the Ongui user interface, like Networkmanagerhud. For a better user interface please use the multiplayer game Lobby asset Pack (Multiplayer-lobby asset package.
)。
Networklobbymanager has a number of virtual function callbacks that can be used to customize lobby behavior. Most importantly, Onlobbyserversceneloadedforplayer is invoked by each player on the server as they transition from the lobby to main game. This is the ideal place for application settings, from the lobby to the player's game object.
For the users to apply settings from their lobby player object to their In-game player object public
override bool Onlo Bbyserversceneloadedforplayer (Gameobject lobbyplayer, Gameobject gameplayer)
{
var cc = Lobbyplayer.getcomponent<colorcontrol> ();
var player = gameplayer.getcomponent<player> ();
Player.mycolor = Cc.mycolor;
return true;
}