Exemplo n.º 1
0
        internal void HandleMatchEvent(Types.MultiplayerEvent eventType, string matchId,
                                       NativeTurnBasedMatch match)
        {
            // Capture the current value of the delegate to protect against racing updates.
            var currentDelegate = mMatchDelegate;

            if (currentDelegate == null)
            {
                return;
            }

            // Ignore REMOVED events - this plugin has no use for them.
            if (eventType == Types.MultiplayerEvent.REMOVED)
            {
                Logger.d("Ignoring REMOVE event for match " + matchId);
                return;
            }

            bool shouldAutolaunch = eventType == Types.MultiplayerEvent.UPDATED_FROM_APP_LAUNCH;

            match.ReferToMe();
            Callbacks.AsCoroutine(WaitForLogin(() =>
                                               { currentDelegate(match.AsTurnBasedMatch(mNativeClient.GetUserId()), shouldAutolaunch);
                                                 match.ForgetMe(); }));
        }
        internal void HandleMatchEvent(Types.MultiplayerEvent eventType, string matchId, NativeTurnBasedMatch match)
        {
            Action <GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch, bool> currentDelegate = mMatchDelegate;

            if (currentDelegate != null)
            {
                if (eventType == Types.MultiplayerEvent.REMOVED)
                {
                    Logger.d("Ignoring REMOVE event for match " + matchId);
                }
                else
                {
                    bool shouldAutolaunch = eventType == Types.MultiplayerEvent.UPDATED_FROM_APP_LAUNCH;
                    match.ReferToMe();
                    Callbacks.AsCoroutine(WaitForLogin(delegate
                    {
                        currentDelegate(match.AsTurnBasedMatch(mNativeClient.GetUserId()), shouldAutolaunch);
                        match.ForgetMe();
                    }));
                }
            }
        }
        private Action <TurnBasedManager.TurnBasedMatchResponse> BridgeMatchToUserCallback(Action <UIStatus, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> userCallback)
        {
            return(delegate(TurnBasedManager.TurnBasedMatchResponse callbackResult)
            {
                using (NativeTurnBasedMatch nativeTurnBasedMatch = callbackResult.Match())
                {
                    if (nativeTurnBasedMatch == null)
                    {
                        UIStatus arg = UIStatus.InternalError;
                        switch (callbackResult.ResponseStatus())
                        {
                        case CommonErrorStatus.MultiplayerStatus.VALID:
                            arg = UIStatus.Valid;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID_BUT_STALE:
                            arg = UIStatus.Valid;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_INTERNAL:
                            arg = UIStatus.InternalError;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_NOT_AUTHORIZED:
                            arg = UIStatus.NotAuthorized;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_VERSION_UPDATE_REQUIRED:
                            arg = UIStatus.VersionUpdateRequired;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.ERROR_TIMEOUT:
                            arg = UIStatus.Timeout;
                            break;
                        }
                        userCallback(arg, null);
                    }
                    else
                    {
                        GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch turnBasedMatch = nativeTurnBasedMatch.AsTurnBasedMatch(mNativeClient.GetUserId());
                        Logger.d("Passing converted match to user callback:" + turnBasedMatch);
                        userCallback(UIStatus.Valid, turnBasedMatch);
                    }
                }
            });
        }
 public void AcceptFromInbox(Action <bool, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> callback)
 {
     callback = Callbacks.AsOnGameThreadCallback(callback);
     mTurnBasedManager.ShowInboxUI(delegate(TurnBasedManager.MatchInboxUIResponse callbackResult)
     {
         using (NativeTurnBasedMatch nativeTurnBasedMatch = callbackResult.Match())
         {
             if (nativeTurnBasedMatch == null)
             {
                 callback(false, null);
             }
             else
             {
                 GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch turnBasedMatch = nativeTurnBasedMatch.AsTurnBasedMatch(mNativeClient.GetUserId());
                 Logger.d("Passing converted match to user callback:" + turnBasedMatch);
                 callback(true, turnBasedMatch);
             }
         }
     });
 }
        private Action <TurnBasedManager.TurnBasedMatchResponse> BridgeMatchToUserCallback(Action <GooglePlayGames.BasicApi.UIStatus, GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch> userCallback)
        {
            return((Action <TurnBasedManager.TurnBasedMatchResponse>)(callbackResult =>
            {
                using (NativeTurnBasedMatch nativeTurnBasedMatch = callbackResult.Match())
                {
                    if (nativeTurnBasedMatch == null)
                    {
                        GooglePlayGames.BasicApi.UIStatus uiStatus = GooglePlayGames.BasicApi.UIStatus.InternalError;
                        switch (callbackResult.ResponseStatus() + 5)
                        {
                        case ~(CommonErrorStatus.MultiplayerStatus.ERROR_INTERNAL | CommonErrorStatus.MultiplayerStatus.VALID):
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.Timeout;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.VersionUpdateRequired;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID_BUT_STALE:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.NotAuthorized;
                            break;

                        case CommonErrorStatus.MultiplayerStatus.VALID | CommonErrorStatus.MultiplayerStatus.VALID_BUT_STALE:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.InternalError;
                            break;

                        case ~CommonErrorStatus.MultiplayerStatus.ERROR_MATCH_ALREADY_REMATCHED:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.Valid;
                            break;

                        case ~CommonErrorStatus.MultiplayerStatus.ERROR_INACTIVE_MATCH:
                            uiStatus = GooglePlayGames.BasicApi.UIStatus.Valid;
                            break;
                        }
                        userCallback(uiStatus, (GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch)null);
                    }
                    else
                    {
                        GooglePlayGames.BasicApi.Multiplayer.TurnBasedMatch turnBasedMatch = nativeTurnBasedMatch.AsTurnBasedMatch(this.mNativeClient.GetUserId());
                        Logger.d("Passing converted match to user callback:" + (object)turnBasedMatch);
                        userCallback(GooglePlayGames.BasicApi.UIStatus.Valid, turnBasedMatch);
                    }
                }
            }));
        }