Beispiel #1
0
    void DoTbmpShowMatchData()
    {
        if (mMatch == null)
        {
            mStatus = "No match is active!";
            return;
        }

        mStatus = mMatch.ToString();
    }
Beispiel #2
0
        private static TurnBasedMatch GetMatchFromJsonString(string matchAsJson)
        {
            Dictionary <string, object> parsedMatch = Json.Deserialize(matchAsJson) as Dictionary <string, object>;

            // Let's create our participant list
            List <Participant> participantList = new List <Participant>();

            List <object> parsedParticipants = parsedMatch["participants"] as List <object>;

            foreach (Dictionary <string, object> nextParticipant in parsedParticipants)
            {
                Dictionary <string, object> playerRepresentation = nextParticipant["player"] as Dictionary <string, object>;
                Player participantAsPlayer = new Player((string)playerRepresentation["playerDisplayName"],
                                                        (string)playerRepresentation["playerId"]);
                Participant participant = new Participant((string)nextParticipant["displayName"],
                                                          (string)nextParticipant["participantId"],
                                                          convertIntFromiOSToParticipantStatus(Convert.ToInt32((System.Int64)nextParticipant["status"])),
                                                          participantAsPlayer,
                                                          (bool)nextParticipant["isConnectedToRoom"]);
                participantList.Add(participant);
                Debug.Log("Adding participant " + participant.ToString());
            }


            string matchData = (string)parsedMatch["matchData"];

            byte[] bytes;
            if (matchData == null)
            {
                Debug.Log("Got a null matchData.");
                bytes = null;
            }
            else
            {
                bytes = System.Convert.FromBase64String(matchData);
            }


            TurnBasedMatch matchCreated = new TurnBasedMatch((string)parsedMatch["matchId"],
                                                             bytes,
                                                             (bool)parsedMatch["canRematch"],
                                                             (string)parsedMatch["localParticipantId"],
                                                             participantList,
                                                             Convert.ToInt32((System.Int64)parsedMatch["availableAutomatchSlots"]),
                                                             (string)parsedMatch["pendingParticipantId"],
                                                             convertIntoFromiOSToMatchTurnStatus(Convert.ToInt32((System.Int64)parsedMatch["turnStatus"])),
                                                             convertIntoFromiOSToMatchStatus(Convert.ToInt32((System.Int64)parsedMatch["matchStatus"])),
                                                             Convert.ToInt32((System.Int64)parsedMatch["variant"]));

            Debug.Log("Final parsed match object is " + matchCreated.ToString());
            return(matchCreated);
        }
            public void onResult(AndroidJavaObject result)
            {
                Logger.d("ResultProxy got result for method: " + mMethod);
                int            statusCode = JavaUtil.GetStatusCode(result);
                bool           isSuccess  = mSuccessCodes.Contains(statusCode);
                TurnBasedMatch match      = null;

                if (isSuccess)
                {
                    Logger.d("SUCCESS result from method " + mMethod + ": " + statusCode);
                    if (mMatchCallback != null)
                    {
                        Logger.d("Attempting to get match from result of " + mMethod);
                        AndroidJavaObject matchObj = JavaUtil.CallNullSafeObjectMethod(result, "getMatch");
                        if (matchObj != null)
                        {
                            Logger.d("Successfully got match from result of " + mMethod);
                            match = JavaUtil.ConvertMatch(mOwner.mClient.PlayerId, matchObj);
                            matchObj.Dispose();
                        }
                        else
                        {
                            Logger.w("Got a NULL match from result of " + mMethod);
                        }
                    }
                }
                else
                {
                    Logger.w("ERROR result from " + mMethod + ": " + statusCode);
                }

                if (mSuccessCallback != null)
                {
                    Logger.d("Invoking success callback (success=" + isSuccess + ") for " +
                             "result of method " + mMethod);
                    PlayGamesHelperObject.RunOnGameThread(() => {
                        mSuccessCallback.Invoke(isSuccess);
                    });
                }
                if (mMatchCallback != null)
                {
                    Logger.d("Invoking match callback for result of method " + mMethod + ": " +
                             "(success=" + isSuccess + ", match=" +
                             (match == null ? "(null)" : match.ToString()));
                    PlayGamesHelperObject.RunOnGameThread(() => {
                        mMatchCallback.Invoke(isSuccess, match);
                    });
                }
            }
            public void onResult(AndroidJavaObject result)
            {
                Logger.d("ResultProxy got result for method: " + this.mMethod);
                int            statusCode = JavaUtil.GetStatusCode(result);
                bool           isSuccess  = this.mSuccessCodes.Contains(statusCode);
                TurnBasedMatch match      = null;

                if (isSuccess)
                {
                    Logger.d(string.Concat(new object[]
                    {
                        "SUCCESS result from method ",
                        this.mMethod,
                        ": ",
                        statusCode
                    }));
                    if (this.mMatchCallback != null)
                    {
                        Logger.d("Attempting to get match from result of " + this.mMethod);
                        AndroidJavaObject androidJavaObject = JavaUtil.CallNullSafeObjectMethod(result, "getMatch", new object[0]);
                        if (androidJavaObject != null)
                        {
                            Logger.d("Successfully got match from result of " + this.mMethod);
                            match = JavaUtil.ConvertMatch(this.mOwner.mClient.PlayerId, androidJavaObject);
                            androidJavaObject.Dispose();
                        }
                        else
                        {
                            Logger.w("Got a NULL match from result of " + this.mMethod);
                        }
                    }
                }
                else
                {
                    Logger.w(string.Concat(new object[]
                    {
                        "ERROR result from ",
                        this.mMethod,
                        ": ",
                        statusCode
                    }));
                }
                if (this.mSuccessCallback != null)
                {
                    Logger.d(string.Concat(new object[]
                    {
                        "Invoking success callback (success=",
                        isSuccess,
                        ") for result of method ",
                        this.mMethod
                    }));
                    PlayGamesHelperObject.RunOnGameThread(delegate
                    {
                        this.mSuccessCallback(isSuccess);
                    });
                }
                if (this.mMatchCallback != null)
                {
                    Logger.d(string.Concat(new object[]
                    {
                        "Invoking match callback for result of method ",
                        this.mMethod,
                        ": (success=",
                        isSuccess,
                        ", match=",
                        (match != null) ? match.ToString() : "(null)"
                    }));
                    PlayGamesHelperObject.RunOnGameThread(delegate
                    {
                        this.mMatchCallback(isSuccess, match);
                    });
                }
            }