Get Rooms

Overview

Gets the public rooms of your game in the Lobby server.

Methods

GetRooms(int, int, Action<bool, SWGetRoomReply, SWLobbyError>)

Called by players to begin an asynchronous operation to get rooms in the Lobby server using the specified pageIndex and pageRowCount.

Class

SWGetRoomReply

The response object when the operation finished successfully.

SWLobbyError

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

// Serializable classes for room custom data
[Serializable]
public class RoomCustomData {
public string name;
public TeamCustomData team1;
public TeamCustomData team2;
}
[Serializable]
public class TeamCustomData {
public List < string > players = new List < string > ();
}
// Create a new RoomCustomData object;
RoomCustomData roomData = new RoomCustomData();
// Set its name to "New Room"
roomData.name = "New Room";
// Create two TeamCustomData objects
// Assign them to team1 and team2 of the RoomCustomData object
roomData.team1 = new TeamCustomData();
roomData.team2 = new TeamCustomData();
// Assign local player to team1 by
// adding local player's PlayerId to the players list of team1
roomData.team1.players.Add(NetworkClient.Lobby.PlayerId);
// create a new room with the RoomCustomData serializable object
NetworkClient.Lobby.CreateRoom(roomData, true, 4, (successful, roomId, error) =>{
if (successful) {
Debug.Log("Room created " + roomId);
}
else {
Debug.Log("Failed to create room " + error);
}
});
// Get rooms in the first page
// Page row count is 5
NetworkClient.Lobby.GetRooms(0, 5, (successful, reply, error) =>{
if (successful) {
// loop through the rooms of the page
foreach(SWRoom room in reply.rooms) {
// Deserialize room custom data
RoomCustomData roomData = room.GetCustomData < RoomCustomData > ();
}
}
else {
Debug.Log("Failed to get rooms " + error);
}
});