Documentation
Ask or search…
K
Links

Create a Lobby

Overview

After supplying the parameters such as Name and maxPlayerInRoom, we will construct the lobby, start the server, and update the status once the lobby has been successfully created. To maintain lobby activity, perform a heartbeat ping in the Update method.
Update the PlayerDataObject and LobbyData in Tashi by executing Update OutgoingSessionDetails and Update IncomingSessionDetails.
Please note that this page will be updated with additional information about the Lobby. While the lobby is running, players can change their state or data via the PlayerDataObject within the Lobby.

Detail

  • Import the Unity package Lobby from the Unity Registry.
  • Create a UI for the Lobby, and ensure it is displayed after a user has signed in.
  • Create a function named CreateLobby in MenuSceneManager.cs:
public async void CreateLobby()
{
int maxPlayerInRoom = 8;
if (int.TryParse(_numberPlayerInRoomTextField.text, out int rs))
{
maxPlayerInRoom = rs;
}
else
{
maxPlayerInRoom = 8;
}
_numberPlayerInRoomTextField.text = maxPlayerInRoom.ToString();
// NetworkManager.Singleton.StartHost();
var lobbyOptions = new CreateLobbyOptions
{
IsPrivate = false,
};
string lobbyName = this.LobbyName();
LobbyManager.Instance.CurrentLobby =
await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayerInRoom, lobbyOptions);
LobbyManager.Instance.isLobbyHost = true;
_roomCodeLobbyTextField.text = LobbyManager.Instance.CurrentLobby.LobbyCode;
Debug.Log(
$"= Create Lobby name : {lobbyName} has max {maxPlayerInRoom} players. Lobby Code {LobbyManager.Instance.CurrentLobby.LobbyCode}");
UpdateStatusText();
LobbyManager.Instance.isSetInitPlayerDataObject = false;
}