///<summary></summary>
        /// <seealso cref="GooglePlayGames.BasicApi.IPlayGamesClient.LoadAchievements"/>
        public void LoadAchievements(Action <Achievement[]> callback)
        {
            callback = AsOnGameThreadCallback(callback);
            if (!IsAuthenticated())
            {
                callback(null);
                return;
            }
            mServices.AchievementManager().FetchAll(
                response => {
                if (response.Status() != Status.ResponseStatus.VALID &&
                    response.Status() != Status.ResponseStatus.VALID_BUT_STALE)
                {
                    GooglePlayGames.OurUtils.Logger.e("Error retrieving achievements - check the log for more information. ");
                    callback(null);
                    return;
                }

                Achievement[] data = new Achievement[(int)response.Length()];
                int i = 0;
                foreach (var achievement in response)
                {
                    using (achievement)
                    {
                        data[i++] = achievement.AsAchievement();
                    }
                }
                callback.Invoke(data);
            });
        }
예제 #2
0
        private void HandleAuthTransition(Types.AuthOperation operation, Status.AuthStatus status)
        {
            GooglePlayGames.OurUtils.Logger.d("Starting Auth Transition. Op: " + operation + " status: " + status);
            lock (AuthStateLock)
            {
                switch (operation)
                {
                case Types.AuthOperation.SIGN_IN:
                    if (status == Status.AuthStatus.VALID)
                    {
                        uint currentAuthGeneration = mAuthGeneration;
                        mServices.AchievementManager().FetchAll(
                            results => PopulateAchievements(currentAuthGeneration, results));
                        mServices.PlayerManager().FetchSelf(
                            results => PopulateUser(currentAuthGeneration, results));
                    }
                    else
                    {
                        // Auth failed
                        // The initial silent auth failed - take note of that and
                        // notify any pending silent-auth callbacks. If there are
                        // additional non-silent auth callbacks pending, attempt to auth
                        // by popping the Auth UI.
                        mAuthState = AuthState.Unauthenticated;
                        GooglePlayGames.OurUtils.Logger.d(
                            "AuthState == " + mAuthState +
                            " calling auth callbacks with failure");

                        // Noisy sign-in failed - report failure.
                        Action <bool, string> localCallbacks = mPendingAuthCallbacks;
                        mPendingAuthCallbacks = null;
                        InvokeCallbackOnGameThread(localCallbacks, false, "Authentication failed");
                    }
                    break;

                case Types.AuthOperation.SIGN_OUT:
                    ToUnauthenticated();
                    break;

                default:
                    GooglePlayGames.OurUtils.Logger.e("Unknown AuthOperation " + operation);
                    break;
                }
            }
        }
예제 #3
0
        private void HandleAuthTransition(Types.AuthOperation operation, Status.AuthStatus status)
        {
            Logger.d("Starting Auth Transition. Op: " + operation + " status: " + status);
            lock (AuthStateLock)
            {
                switch (operation)
                {
                case Types.AuthOperation.SIGN_IN:
                    if (status == Status.AuthStatus.VALID)
                    {
                        // If sign-in succeeded, treat any silent auth callbacks the same way
                        // we would treat loud ones.
                        if (mSilentAuthCallbacks != null)
                        {
                            mPendingAuthCallbacks += mSilentAuthCallbacks;
                            mSilentAuthCallbacks   = null;
                        }

                        uint currentAuthGeneration = mAuthGeneration;
                        mServices.AchievementManager().FetchAll(
                            results => PopulateAchievements(currentAuthGeneration, results));
                        mServices.PlayerManager().FetchSelf(
                            results => PopulateUser(currentAuthGeneration, results));
                    }
                    else
                    {
                        // Auth failed
                        if (mAuthState == AuthState.SilentPending)
                        {
                            // The initial silent auth failed - take note of that and
                            // notify any pending silent-auth callbacks. If there are
                            // additional non-silent auth callbacks pending, attempt to auth
                            // by popping the Auth UI.
                            mSilentAuthFailed = true;
                            mAuthState        = AuthState.Unauthenticated;
                            var silentCallbacks = mSilentAuthCallbacks;
                            mSilentAuthCallbacks = null;
                            Debug.Log("Invoking callbacks, AuthState changed from silentPending to Unauthenticated.");

                            InvokeCallbackOnGameThread(silentCallbacks, false);
                            if (mPendingAuthCallbacks != null)
                            {
                                Debug.Log("there are pending auth callbacks - starting AuthUI");
                                GameServices().StartAuthorizationUI();
                            }
                        }
                        else
                        {
                            Debug.Log("AuthState == " + mAuthState + " calling auth callbacks with failure");
                            // Noisy sign-in failed - report failure.
                            Action <bool> localCallbacks = mPendingAuthCallbacks;
                            mPendingAuthCallbacks = null;
                            InvokeCallbackOnGameThread(localCallbacks, false);
                        }
                    }
                    break;

                case Types.AuthOperation.SIGN_OUT:
                    ToUnauthenticated();
                    break;

                default:
                    Logger.e("Unknown AuthOperation " + operation);
                    break;
                }
            }
        }