Get Rooms

Overview

Gets the public rooms of your game in the Lobby server.
Methods
Called by players to begin an asynchronous operation to get rooms in the Lobby server using the specified pageIndex and pageRowCount.
Class
The response object when the operation finished successfully.
The error that occurred when a lobby API operation failed.
SWRoom
Data model of a room.
Maximum page index is 255.
Maximum page row count is 15.

Example

1
// Serializable classes for room custom data
2
[Serializable]
3
public class RoomCustomData {
4
public string name;
5
public TeamCustomData team1;
6
public TeamCustomData team2;
7
}
8
9
[Serializable]
10
public class TeamCustomData {
11
public List < string > players = new List < string > ();
12
}
Copied!
1
// Create a new RoomCustomData object;
2
RoomCustomData roomData = new RoomCustomData();
3
4
// Set its name to "New Room"
5
roomData.name = "New Room";
6
7
// Create two TeamCustomData objects
8
// Assign them to team1 and team2 of the RoomCustomData object
9
roomData.team1 = new TeamCustomData();
10
roomData.team2 = new TeamCustomData();
11
12
// Assign local player to team1 by
13
// adding local player's PlayerId to the players list of team1
14
roomData.team1.players.Add(NetworkClient.Lobby.PlayerId);
15
16
// create a new room with the RoomCustomData serializable object
17
NetworkClient.Lobby.CreateRoom(roomData, true, 4, (successful, roomId, error) =>{
18
if (successful) {
19
Debug.Log("Room created " + roomId);
20
}
21
else {
22
Debug.Log("Failed to create room " + error);
23
}
24
});
Copied!
1
// Get rooms in the first page
2
// Page row count is 5
3
NetworkClient.Lobby.GetRooms(0, 5, (successful, reply, error) =>{
4
if (successful) {
5
// loop through the rooms of the page
6
foreach(SWRoom room in reply.rooms) {
7
// Deserialize room custom data
8
RoomCustomData roomData = room.GetCustomData < RoomCustomData > ();
9
}
10
}
11
else {
12
Debug.Log("Failed to get rooms " + error);
13
}
14
});
Copied!
Copy link