Leaving and Deleting a room¶
When you have done with a room, e.g., when you have finished playing a single match, or when you change your mind to join a match, you leave the room. It may also delete the room.
Leaving a room¶
You can leave the room you are currently in by calling LeaveRoom
method on the StrixNetwork
singleton.
public void LeaveRoom(RoomLeaveEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
Note
Leaving a room doesn’t mean you are disconnecting from a room server. If you also want to disconnect from the room server, you should do so separately. However, such a disconnect operation is usually unneeded because an attempt to connect to a new room server automatically disconnects the existing one.
Deleting a room¶
A room is automatically deleted when it becomes unused. The exact condition of “unused” depends on the room owner migration server option:
If room owner migration is disabled, a room is considered unused and deleted when the room owner leaves the room (even if there is any other member in the room).
If room owner migration is enabled, a room is considered unused and deleted when the last member leaves the room.
You can also delete the room manually using the DeleteRoom method on the StrixNetwork
singleton.
void DeleteRoom(long roomId, RoomDeleteEventHandler handler, FailureEventHandler failureHandler, RequestConfig config = null)
In the current version of Strix Unity SDK, you cannot be joined to multiple rooms simultaneously. This means that the roomId argument must be the ID of the room you’re currently in. You can get this ID by calling:
StrixNetwork.instance.room.GetPrimaryKey();
Code Example¶
using SoftGear.Strix.Unity.Runtime;
using UnityEngine;
public class StrixDeleteRoomExample : MonoBehaviour
{
void Start()
{
var strixNetwork = StrixNetwork.instance;
// This is a placeholder value. Change this to your application ID
// It can be found on the Strix Cloud application information tab: https://www.strixcloud.net/app/applist
strixNetwork.applicationId = "00000000-0000-0000-0000-000000000000";
strixNetwork.ConnectMasterServer(
// This is a placeholder value. Change this to your master hostname
// It can be found on the Strix Cloud application information tab: https://www.strixcloud.net/app/applist
host: "000000000000000000000000.game.strixcloud.net",
connectEventHandler: _ => {
Debug.Log("Connection established.");
strixNetwork.CreateRoom(
new Dictionary<string, object> {
{ "name", "My Game Room" },
{ "capacity", 20 }
},
playerName: "My Player Name",
handler: createRoomResult => {
Debug.Log("Room created.");
strixNetwork.DeleteRoom(
roomId: strixNetwork.room.GetPrimaryKey(),
handler: deleteRoomResult => Debug.Log("Room deleted: " + (strixNetwork.room == null)),
failureHandler: deleteRoomError => Debug.LogError("Could not delete room. Reason: " + deleteRoomError.cause)
);
},
failureHandler: createRoomError => Debug.LogError("Could not create room. Reason: " + createRoomError.cause)
);
},
errorEventHandler: connectError => Debug.LogError("Connection failed. Reason: " + connectError.cause)
);
}
}
Note
Make sure to change the placeholder values of applicationId and host to the real ones that can be found on the Strix Cloud application information tab.