Room CRUD
Creating Rooms
In this tutorial, we allow players to pick room names. The starter project already implemented the popup view to let players enter room names. You can use LobbyGUI's member method ShowNewGamePopup(Action<bool, string>) to display the popup view.
Open the LobbyDemo.cs script and add the following code to the CreateNewRoom() method.
If the player entered a name and clicked the OK button in the popup, the ok bool value will be true and gameName string value will be the value that the player entered.
Create a RoomCustomData object, initialize its team variables. Also, you can assign the local player to team1 by adding local player's PlayerId to team1's players' list.
You can use SWLobby's member method CreateRoom(object, bool, int, Action<bool, SWRegisterReply, SWLobbyError>) to create the new room.
Getting Rooms
You created a new room on the lobby server. You need to fetch the room from the lobby server.
Open the LobbyDemo.cs script and add the following code to the GetRooms() method.
You can use SWLobby's member method GetRooms(int, int, action<bool, SWGetRoomReply, SWLobbyError>) to fetch rooms from the lobby server.
The room custom data is a serializable object of type RoomCustomData, you can use SWRoom's member method GetCustomData<T>() to deserialize the room custom data.
Getting Players in a Room
You can use SWLobby's member method GetPlayersInRoom(Action<bool, SWGetPlayersReply, SWLobbyError>) to fetch the players in a room.
Add the GetPlayersInCurrentRoom() method.
Joining Rooms
You can use SWLobby's member method JoinRoom(string, Action<bool, SWJoinRoomReply, SWLobbyError>) to join a room on the lobby server.
Add the following code to the GetRooms() method.
Leaving Rooms
You can use SWLobby's member method LeaveRoom(Action<bool, SWLobbyError>) to leave a room on the lobby server.
Add the following code to the LeavingRoom() method.
Deleting Rooms
A room is automatically destroyed if there is no player in it. You don't need to manually delete rooms.
Last updated