ContinueWith() 中的函数不起作用

The function inside ContinueWith() is not working

public void Login()
{
    string email = emailInputField.text;
    string password = passwordInputField.text;
    auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(
        task =>
        {
            if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
            {
                Debug.Log("[Login Success] ID: " + auth.CurrentUser.UserId);
                PlayerInformation.auth = auth;
                SceneManager.LoadScene("SongSelectScene");
            }
            else
            {
                messageUI.text = "[Login Failed] Please check your account";
                Debug.Log("[Login Failed] Please check your account");
            }
        });
}

我是一名正在学习 unity 的学生。我正在尝试通过 firebase 统一注册和登录功能。 (使用 unity 2020.3.20f1)

但是,除了Debug.Log()函数,我在unity中执行的时候没有用。对于上面的代码,当我输入有效的电子邮件和密码时 Debug.Log() 正在工作,但 SceneManager.LoadScene() 不工作...

我尝试更改 ContinueWith() 中的值(如 messageUI.text = ~~),但它也不起作用... 我真的需要你的帮助... 谢谢。

大部分UnityAPI只能在Unity主线程上使用

ContinueWith 保证在与任务启动相同的线程上执行!

特别是出于这个原因,Firebase 提供了 TaskExtensions ConinueWithOnMainThread which in the background uses something similar to e.g. UnityMainThreadDispatcher for dispatching the result callbacks back into the Unity main thread via an internal thread-save ConcurrentQueue 和一个专用的 Update 方法来处理它。

public void Login()
{
    string email = emailInputField.text;
    string password = passwordInputField.text;
    auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWithOnMainThread(
        task =>
        {
            if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
            {
                Debug.Log("[Login Success] ID: " + auth.CurrentUser.UserId);
                PlayerInformation.auth = auth;
                SceneManager.LoadScene("SongSelectScene");
            }
            else
            {
                messageUI.text = "[Login Failed] Please check your account";
                Debug.Log("[Login Failed] Please check your account");
            }
        });
}