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.
아래는 서버에서 호출되는 NetworkLobbyManager 가상 함수입니다.
All of the above server functions have empty default implementations, except for OnLobbyServerPlayersReady, which calls ServerChangeScene with the PlayScene.
아래는 클라이언트에서 호출되는 NetworkLobbyManager 가상 함수입니다.
위 클라이언트 함수는 모두 빈 디폴트 구현 상태입니다.
There are two kinds of player objects - each which has a prefab slot in the NetworkLobbyManager. The slots can be seen in this screenshot:
LobbyPlayer는 플레이어가 로비에 참여할 때 LobbyPlayerPrefab에서 생성됩니다.
The “Minimum Players” field represents the minimum number of “Ready” players in the Lobby to start the Match with. If the number of connected clients is more than the “Minimum Players” value, then waiting for all connected clients to become “Ready” will start the Match.
아래는 “최소 플레이어” 수가 2인 경우입니다.
GamePlayer는 게임이 시작하는 시점에서 GamePlayerPrefab에서 생성됩니다.
NetworkLobbyPlayer 컴포넌트는 LobbyPlayer 오브젝트에서 사용합니다. 커스텀 로비 동작을 위해 사용될 수 있는 일부 가상 함수 콜백을 제공합니다.
public virtual void OnClientEnterLobby();
public virtual void OnClientExitLobby();
public virtual void OnClientReady(bool readyState);
The function OnClientEnterLobby is called on the client when the game enters the lobby. This happens when the lobby scene starts for the first time, and also when returning to the lobby from the game-play scene.
The function OnClientExitLobby is called on the client when the game exists the lobby. This happens when switching to the game-play scene.
OnClientReady 함수는 해당 플레이어의 준비 상태가 변경되는 경우 호출됩니다.
멀티플레이어 로비 에셋 패키지를 사용하지 않고 NetworkLobby를 멀티플레이어 게임에 추가하는 과정
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;
}
Unity 에셋 스토어에는 NetworkLobbyManager를 사용하고 로비 GUI를 제공하는 예제 프로젝트가 있습니다. 이 프로젝트를 시작점으로 활용하여 로비가 있는 멀티플레이어 게임을 만들 수 있습니다.