我试图在我的应用中实施电子邮件/密码身份验证,但每当我运行我的应用程序时(在编辑器或手机上)都没有任何反应(Forebase控制台中没有任何东西,也没有什么是Unity控制台)。我确保这些值正确传递,并且我开始觉得我失败了一些非常基本的东西。
这是我的代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class RegisterOrSignInButtonClicked : MonoBehaviour {
public string buttonMode;
public Text Email;
public Text password;
public Text topText;
Firebase.Auth.FirebaseAuth auth;
Firebase.Auth.FirebaseUser user;
void Start () {
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
auth.StateChanged += Auth_StateChanged;
Auth_StateChanged (this, null);
}
void Auth_StateChanged (object sender, System.EventArgs e)
{
if (auth.CurrentUser != user) {
user = auth.CurrentUser;
}
if (user == null) {
return;
}
if (!user.IsEmailVerified ) {
user.SendEmailVerificationAsync ();
}
if (auth.CurrentUser != null) {
SceneManager.LoadScene ("ClickMenuScene");
}
}
public void buttonClicked(){
topText.text = Email.text.ToString();
if(buttonMode.Equals("Register")){
auth.CreateUserWithEmailAndPasswordAsync(Email.text.ToString(), password.text.ToString()).ContinueWith(task => {
if (task.IsCanceled) {
Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled.");
return;
}
if (task.IsFaulted) {
Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("Firebase user created successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
}
}
}