示例#1
0
    public void signIn()
    {
        string email    = signIn_email.text;
        string password = signIn_password.text;

        if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password))
        {
            Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
            UserLogged.setFirebaseAuth(auth);
            auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    infoMessage.faceColor = new Color32(255, 0, 0, 255);
                    AggregateException ex = task.Exception as AggregateException;
                    if (ex != null)
                    {
                        Firebase.FirebaseException fbEx = null;
                        foreach (Exception e in ex.InnerExceptions)
                        {
                            fbEx = e as Firebase.FirebaseException;
                            if (fbEx != null)
                            {
                                break;
                            }
                        }

                        if (fbEx != null)
                        {
                            infoMessage.text = fbEx.Message;
                        }
                    }
                    return;
                }

                Firebase.Auth.FirebaseUser newUser = task.Result;
                infoMessage.faceColor    = new Color32(0, 255, 0, 255);
                infoMessage.text         = "Sign In successful!";
                FirebaseUser currentUser = auth.CurrentUser;
                if (currentUser != null)
                {
                    UserLogged.setLoggedUser(currentUser);
                    String nickname = currentUser.DisplayName;
                    if (string.IsNullOrEmpty(nickname))
                    {
                        DontDestroyOnLoad(this.user);
                        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 2);
                    }
                    else
                    {
                        DontDestroyOnLoad(this.user);
                        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 3);
                    }
                }
            });
        }
        else
        {
            infoMessage.faceColor = new Color32(255, 0, 0, 255);
            infoMessage.text      = "Email or Password cannot be empty!";
        }
    }