[출처]- Unity Documentation
1. Create a lobby / 로비 세팅
새로운 Lobby를 만들 때, 다음과 같은 프로퍼티를 세팅할 수 있다
- Lobby name (required)
- Lobby visibility (public or private)
- Lobby size (the maximum occupancy)
- This is referred to as Max Players in the code.
- Initial custom lobby data
- This can include any arbitrary data. For example, map IDs and game modes.
- Lobby data with string or numeric values can be indexed, allowing for filtering and ordering on those indexes in queries.
- Initial (host) player data
- For example, player display names, skills and characters.
Note: When a player creates a lobby, they automatically become the host.
쿼리란?
쿼리는 웹 서버에 특정한 정보를 보여달라는 웹 클라이언트 요청(주로 문자열을 기반으로 한 요청이다)에 의한 처리
#2. Create a public lobby / 실제로 로비를 만들어보자!
public 로비는 Lobby Code가 필요 없으며, 누구든 보여지는 Query 결과에 참여할 수 있다
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.IsPrivate = false;
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
3번째 인자로는 LobbyOption을 받는다!
#3. Create a private lobby
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.IsPrivate = true;
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
option.IsPrivate만 달라진다!
#4. Create a lobby with standard, non-indexed data
로비 데이터는 Create Request도 포함될 수 있을 뿐만 아니라 뒤 따라오는 Update Request도 포함될 수 있다!
The following code sample shows how to create a lobby with standard, non-indexed data:
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.Data = new Dictionary<string, DataObject>()
{
{
"ExamplePublicLobbyData", new DataObject(
visibility: DataObject.VisibilityOptions.Public, // Visible publicly.
value: "ExamplePublicLobbyData")
},
};
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
#5. Create a lobby with indexed string data
The following code sample shows how to create a lobby with indexed string data:
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.Data = new Dictionary<string, DataObject>()
{
{
"GameMode", new DataObject(
visibility: DataObject.VisibilityOptions.Public, // Visible publicly.
value: "Conquest",
index: DataObject.IndexOptions.S1)
},
};
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
index: DataObject.IndexOptions.S1
#6. Create a lobby with indexed numeric data
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
options.Data = new Dictionary<string, DataObject>()
{
{
"MinimumSkillLevel", new DataObject(
visibility: DataObject.VisibilityOptions.Public, // Visible publicly.
value: "25",
index: DataObject.IndexOptions.N1)
},
};
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
index: DataObject.IndexOptions.N1
#7. Create a lobby with player data for the host
로비 데이터와 마찬가지로, Host의 플레이어 데이터도 별도의 update request를 더하는거 대신에 Create Request 또한 포함될 수 있습니다
string lobbyName = "new lobby";
int maxPlayers = 4;
CreateLobbyOptions options = new CreateLobbyOptions();
// Ensure you sign-in before calling Authentication Instance.
// See IAuthenticationService interface.
options.Player = new Player(
id: AuthenticationService.Instance.PlayerId,
data: new Dictionary<string, PlayerDataObject>()
{
{
"ExampleMemberPlayerData", new PlayerDataObject(
visibility: PlayerDataObject.VisibilityOptions.Member, // Visible only to members of the lobby.
value: "ExampleMemberPlayerData")
}
});
Lobby lobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
#8. Active and inactive lobbies
마지막으로! 로비는 30초안에 HeartBeat Request를 보내거나 Update하지 않으면 Inactive상태가 되어버립니다!
InActive Public Lobby가 되어버리면 Query 결과를 보여줄 수 없으며 자동으로 방이 삭제됩니다!
Update 또는 HeartBeat Request를 보냄으로써 다시 ReActivated될 수 있습니다!