Exemple #1
0
    private void SignInNoSilent()
    {
        AN_GoogleSignInOptions.Builder builder = new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
        builder.RequestId();
        builder.RequestEmail();
        builder.RequestProfile();

        AN_GoogleSignInOptions gso    = builder.Build();
        AN_GoogleSignInClient  client = AN_GoogleSignIn.GetClient(gso);

        AN_Logger.Log("SignInNoSilent Start ");

        client.SignIn((signInResult) => {
            AN_Logger.Log("Sign In StatusCode: " + signInResult.StatusCode);
            if (signInResult.IsSucceeded)
            {
                AN_Logger.Log("SignIn Succeeded");
                UpdateUIWithAccount(signInResult.Account);
            }
            else
            {
                AN_Logger.Log("SignIn filed: " + signInResult.Error.FullMessage);
            }
        });
    }
Exemple #2
0
    private void SignInFlow()
    {
        AN_Logger.Log("Play Services Sign In started....");
        AN_GoogleSignInOptions.Builder builder = new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);

        //Google play documentation syas that
        // you don't need to use this, however, we recommend you still
        // add those option to your Sing In builder. Some version of play service lib
        // may retirn a signed account with all fileds empty if you will not add this.
        // However according to the google documentation this step isn't required
        // So the decision is up to you.
        builder.RequestId();
        builder.RequestEmail();
        builder.RequestProfile();

        // Add the APPFOLDER scope for Snapshot support.
        builder.RequestScope(AN_Drive.SCOPE_APPFOLDER);

        AN_GoogleSignInOptions gso    = builder.Build();
        AN_GoogleSignInClient  client = AN_GoogleSignIn.GetClient(gso);

        AN_Logger.Log("Let's try Silent SignIn first");
        client.SilentSignIn((result) => {
            if (result.IsSucceeded)
            {
                AN_Logger.Log("SilentSignIn Succeeded");
                UpdateUIWithAccount(result.Account);
            }
            else
            {
                // Player will need to sign-in explicitly using via UI

                AN_Logger.Log("SilentSignIn Failed with code: " + result.Error.Code);
                AN_Logger.Log("Starting the default Sign in flow");

                //Starting the interactive sign-in
                client.SignIn((signInResult) => {
                    AN_Logger.Log("Sign In StatusCode: " + signInResult.StatusCode);
                    if (signInResult.IsSucceeded)
                    {
                        AN_Logger.Log("SignIn Succeeded");
                        UpdateUIWithAccount(signInResult.Account);
                    }
                    else
                    {
                        AN_Logger.Log("SignIn filed: " + signInResult.Error.FullMessage);
                    }
                });
            }
        });
    }
        public void SignInRequest(Action <bool, AN_CommonStatusCodes> resultCallback = null, bool ignorePrefs = false)
        {
            if (!IsGoogleApiAvailable)
            {
                return;
            }

            Debug.Log("Signing request...");

            if (IsSignedIn()) //if already signed in
            {
                resultCallback.SafeInvoke(true, AN_CommonStatusCodes.SUCCESS);
                GetSignedInPlayerData();
                ActivateGPlayPopup();

                _isSigninIgnored = false;
                PlayerPrefs.SetInt("IsSigninIgnored", 0);
                OnGPlayAuth.SafeInvoke(true);

                return;
            }

            if (!ignorePrefs)
            {
                if (_isSigninIgnored)
                {
                    resultCallback.SafeInvoke(false, AN_CommonStatusCodes.CANCELED);
                    Debug.Log("Signin Ignored!");
                    return;
                }
            }

            AN_GoogleSignInOptions.Builder builder =
                new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
            builder.RequestId();
            builder.RequestEmail();
            builder.RequestProfile();
            //builder.RequestScope(AN_Drive.SCOPE_APPFOLDER);

            var gso    = builder.Build();
            var client = AN_GoogleSignIn.GetClient(gso);

            var authStatus = AN_CommonStatusCodes.SIGN_IN_REQUIRED;

            //silent sign in
            client.SilentSignIn(signInResult =>
            {
                Debug.Log("Sign In StatusCode [silent]: " + signInResult.StatusCode);
                authStatus = signInResult.StatusCode;

                if (signInResult.IsSucceeded)
                {
                    Debug.Log("SignIn Succeeded [silent]");
                    GoogleSignedInAccount = signInResult.Account;
                    resultCallback.SafeInvoke(true, authStatus);
                    ActivateGPlayPopup();

                    //finally when signin is success, cache the player data for first time
                    if (authStatus == AN_CommonStatusCodes.SUCCESS)
                    {
                        GetSignedInPlayerData();

                        _isSigninIgnored = false;
                        PlayerPrefs.SetInt("IsSigninIgnored", 0);

                        OnGPlayAuth.SafeInvoke(true);
                    }
                }
                else
                {
                    GoogleSignedInAccount = null;
                    Debug.Log("Silent SignIn failed [silent] : " + signInResult.Error.FullMessage);

                    //interactive sign in
                    if (authStatus == AN_CommonStatusCodes.SIGN_IN_REQUIRED)
                    {
                        client.SignIn(interactiveSignInResult =>
                        {
                            authStatus = interactiveSignInResult.StatusCode;
                            Debug.Log("Sign In StatusCode [interactive]: " + interactiveSignInResult.StatusCode);

                            if (interactiveSignInResult.IsSucceeded)
                            {
                                Debug.Log("SignIn Succeeded [interactive]");
                                GoogleSignedInAccount = interactiveSignInResult.Account;
                                resultCallback.SafeInvoke(true, authStatus);
                                ActivateGPlayPopup();

                                //finally when signin is success, cache the player data for first time
                                if (authStatus == AN_CommonStatusCodes.SUCCESS)
                                {
                                    GetSignedInPlayerData();

                                    _isSigninIgnored = false;
                                    PlayerPrefs.SetInt("IsSigninIgnored", 0);

                                    OnGPlayAuth.SafeInvoke(true);
                                }
                            }
                            else
                            {
                                resultCallback.SafeInvoke(false, authStatus);
                                Debug.Log("SignIn failed [interactive]: " + interactiveSignInResult.Error.FullMessage);

                                if (authStatus == AN_CommonStatusCodes.CANCELED || authStatus == AN_CommonStatusCodes.ERROR)
                                {
                                    _isSigninIgnored = true;
                                    PlayerPrefs.SetInt("IsSigninIgnored", 1);
                                }
                            }
                        });
                    }
                }
            });

            //finally when signin is success, cache the player data for first time
            if (authStatus == AN_CommonStatusCodes.SUCCESS)
            {
                GetSignedInPlayerData();
                ActivateGPlayPopup();

                _isSigninIgnored = false;
                PlayerPrefs.SetInt("IsSigninIgnored", 0);

                OnGPlayAuth.SafeInvoke(true);
            }
        }