/// <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(); * param.minUserCount = matchmakingGame.matchmakingParams; * param.maxUserCount = matchmakingGame.maxUserCount; * param.query = matchmakingGame.query; */ socket.ReceivedMatchmakerMatched += OnMatchmakerMatched; // Join the matchmaker ticket = await MatchmakingManager.EnterQueueAsync(socket, matchmakingGame.matchmakingParams); if (ticket == null) { Debug.Log("Couldn't start matchmaker" + Environment.NewLine + "Try again later"); socket.ReceivedMatchmakerMatched -= OnMatchmakerMatched; return(false); } else { // Matchmaker queue joined return(true); } }
/// <summary> /// Leaves matchmaker queue. /// </summary> private async Task <bool> StopMatchmakerAsync(IMatchmakerTicket ticket) { if (ticket == null) { Debug.Log("Couldn't stop matchmaker; matchmaking hasn't been started yet"); return(false); } ISocket socket = NakamaSessionManager.Instance.Socket; bool good = await MatchmakingManager.LeaveQueueAsync(socket, ticket); this.ticket = null; socket.ReceivedMatchmakerMatched -= OnMatchmakerMatched; return(good); }