Exemple #1
0
        IEnumerator CheckMatchMakingStatus()
        {
            GetMatchmakingTicketResult matchmakingResult = null;

            if (string.IsNullOrEmpty(_ticketID))
            {
                Debug.LogError("You are trying to get matchmaking status with no ticket ID");
                yield break;
            }

            while (matchmakingResult == null || matchmakingResult.Status != "Matched")
            {
                if (matchmakingResult != null && matchmakingResult.Status == "Canceled")
                {
                    yield break;
                }

                PlayFabMultiplayerAPI.GetMatchmakingTicket(
                    new GetMatchmakingTicketRequest
                {
                    QueueName = SelectedQueue,
                    TicketId  = _ticketID
                },
                    (result) => matchmakingResult = result,
                    (error) => print(error.GenerateErrorReport())
                    );

                yield return(new WaitForSecondsRealtime(_checkMatchingStatusInterval));

                Debug.Log(matchmakingResult.Status);
            }
        }
Exemple #2
0
        private static async Task <bool> WaitForTicket(Player player, string mmQueueName)
        {
            var getTicketRequest = new GetMatchmakingTicketRequest
            {
                TicketId  = player.mmTicketId,
                QueueName = mmQueueName // Why isn't this discoverable from the ticketId?
            };

            bool success = false;

            for (int i = 0; i < 10; i++)
            {
                PlayFabResult <GetMatchmakingTicketResult> ticketResult = await player.mpApi.GetMatchmakingTicketAsync(getTicketRequest);

                GetMatchmakingTicketResult ticket = VerifyPlayFabCall(ticketResult, "Matchmake ticket poll failed.");
                if (ticket.Status == "Matched")
                {
                    player.mmMatchId = ticket.MatchId;
                    player.ticket    = ticket;
                    success          = true;
                    break;
                }
                System.Threading.Thread.Sleep(6000);
                // "WaitingForMatch", "Matched"
            }
            VerifySuccess(success, $"Matchmake for {player.context.PlayFabId}");
            return(success);
        }
Exemple #3
0
    private void OnGetMatchmakingTicket(GetMatchmakingTicketResult getMatchmakingTicketResult)
    {
        // When PlayFab returns our matchmaking ticket
        string ticketResult = "";

        if (getMatchmakingTicketResult.Status == "Matched")
        {
            // If we found a match, we then need to access its server
            MatchFound(getMatchmakingTicketResult);
            ticketResult = getMatchmakingTicketResult.Status;
        }
        else if (getMatchmakingTicketResult.Status == "Canceled")
        {
            // If the matchmaking ticket was canceled we need to reset the input UI
            uiManager.SetInputInteractable(true);
            ticketResult = "Start Session";
        }
        else
        {
            // If we don't have a conclusive matchmaking status, we keep polling the ticket
            StartCoroutine(PollMatchmakingTicket(getMatchmakingTicketResult.TicketId));
            ticketResult = getMatchmakingTicketResult.Status;
        }

        // Display matchmaking status in the UI
        uiManager.DisplayNetworkMessage(ticketResult);
    }
Exemple #4
0
    private void MatchFound(GetMatchmakingTicketResult getMatchmakingTicketResult)
    {
        // When we find a match, we need to request the connection variables to join clients
        PlayFabMultiplayerAPI.GetMatch(
            new GetMatchRequest {
            MatchId   = getMatchmakingTicketResult.MatchId,
            QueueName = matchmakingQueue
        },

            this.OnGetMatch,
            this.OnPlayFabError
            );
    }
    private void OnGetMatchMakingTicket(GetMatchmakingTicketResult result)
    {
        queueStatusText.text = $"Status: {result.Status}";

        switch (result.Status)
        {
        case "Matched":
            StopCoroutine(pollTicketCoroutine);
            StartMatch(result.MatchId);
            break;

        case "Canceled":
            StopCoroutine(pollTicketCoroutine);
            randomMatchMakingPanel.SetActive(false);
            mainPanel.SetActive(true);
            break;
        }
    }
    private void OnTicketGet(GetMatchmakingTicketResult res)
    {
        PlayfabUtils.OnSuccess(feedbackText, $"Matchmaking Status: {res.Status}");

        switch (res.Status)
        {
        case "Matched":
            StopCoroutine(pollTicketCoroutine);
            leaveBtn.SetActive(false);
            PrepareMatch(res.MatchId);
            break;

        case "Canceled":
            PlayfabUtils.OnError(feedbackText, "Matchmaking timeout! Please try again...");
            StopCoroutine(pollTicketCoroutine);
            leaveBtn.SetActive(false);
            backBtn.GetComponent <Button>().interactable = true;
            break;
        }
    }