/// <summary> /// Adds user to matchmaking queue with given params. /// Returns matchmaker ticket on succes or null on failure. /// </summary> public static async Task <IMatchmakerTicket> EnterQueueAsync(ISocket socket, MatchmakingParams matchmakingParams) { if (matchmakingParams == null) { Debug.LogError("Matchmaking params cannot be null"); return(null); } try { // Acquires matchmaking ticket used to join a match IMatchmakerTicket ticket = await socket.AddMatchmakerAsync( matchmakingParams.query, matchmakingParams.minUserCount, matchmakingParams.maxUserCount, matchmakingParams.stringProperties, matchmakingParams.numericProperties); return(ticket); } catch (Exception e) { Debug.LogWarning("An error has occured while joining the matchmaker: " + e); return(null); } }
/// <summary> /// Joins matchmaker queue. /// </summary> /// <remarks> /// Nakama allows for joining multiple matchmakers, however for the purposes of this demo, /// we will allow only for joining a single matchmaking queue. /// </remarks> private async Task <bool> StartMatchmakerAsync() { if (ticket != null) { Debug.Log("Matchmaker already started"); return(false); } ISocket socket = NakamaSessionManager.Instance.Socket; // Create params object with default values MatchmakingParams param = new MatchmakingParams(); socket.OnMatchmakerMatched += OnMatchmakerMatched; // Join the matchmaker ticket = await MatchmakingManager.EnterQueueAsync(socket, param); if (ticket == null) { Debug.Log("Couldn't start matchmaker" + Environment.NewLine + "Try again later"); socket.OnMatchmakerMatched -= OnMatchmakerMatched; return(false); } else { // Matchmaker queue joined return(true); } }