CreateLobby
Namespace: SynicSugar.MatchMake
Class: MatchMakeManager
Auto matchmaking
public async UniTask<Result> CreateLobby(Lobby lobbyCondition, CancellationTokenSource token = default(CancellationTokenSource))
Manual matchmaking
public async UniTask<Result> CreateLobby(Lobby lobbyCondition, uint minLobbyMember, List<AttributeData> userAttributes = null, CancellationTokenSource token = default(CancellationTokenSource))
Description
Create lobby as Host, wait for others until timeout. If the room is filled and can exchange the data for p2p, return true.
This CancellationTokenSource is used only to cancel matchmaking.
Usually we don't need pass tokensource. In this case, this function handles an exception internally and we can get just return bool result on CancelMatchMaking. If we pass it, we should TryCatch for CancelMatching.
When matchmaking fails, this always returns false, not an exception. To get result code, use LastResultCode.
The value is 0, less than LobbyMaxMembers or null, the matchmaking becomes Auto(Random) matchmaking.
Auto does not allow Host to kick Guests, and anyone who meets the lobbyCondition can join the lobby. When the lobby is full, closes the lobby not to join and start to prepare p2p automatically.
userAttributes is for matchmaking. The user attributes of names, job and so on that is needed before P2P.
These should be used just for matchmaking and the kick, the data for actual game should be exchanged via p2p for security and server bandwidth.
Recommend: SearchAndCreateLobby()
using UnityEngine;
// using System.Threading;
using Cysharp.Threading.Tasks;
using SynicSugar.MatchMake;
public class MatchMake : MonoBehaviour {
Lobby condition; //Create a Lobby as a condition before matchmake.
async UniTask StartMatching(){
Result result = await MatchMakeManager.Instance.CreateLobby(condition);
// //try catch
// Result result;
// try{
// CancellationTokenSource cts = new CancellationTokenSource();
// //Get Success or Failuer
// result = await MatchMakeManager.Instance.CreateLobby(condition, cts);
// }catch(OperationCanceledException){
// //Cancel matchmaking
// }
if(result != Result.Success){
//Failuer
return;
}
//Success
}
}