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中实现注册和登录功能。 (使用Unity 2020.3.20f1)
但是,除了 Debug.Log() 函数之外,当我统一执行它时,它不起作用。对于上面的代码,当我输入有效的电子邮件和密码时,Debug.Log() 正在工作,但 SceneManager.LoadScene() 不工作...
我尝试更改ContinueWith()中的值(如messageUI.text = ~~),但它也不起作用......
我真的需要你的帮助...
谢谢。
大多数Unity API只能在Unity主线程上使用。
ContinueWith https://learn.microsoft.com/dotnet/api/system.threading.tasks.task.continuewith is not保证在任务启动的同一线程上执行!
为此,Firebase 提供了任务扩展 https://firebase.google.com/docs/reference/unity/class/firebase/extensions/task-extension ConinueWithOnMainThread https://firebase.google.com/docs/reference/unity/class/firebase/extensions/task-extension#class_firebase_1_1_extensions_1_1_task_extension_1af1fc309e7e9b9e9a3655b8b47cb06014在后台使用类似的东西,例如Unity主线程调度程序 https://github.com/PimDeWitte/UnityMainThreadDispatcher用于通过内部线程保存将结果回调分派回 Unity 主线程ConcurrentQueue https://learn.microsoft.com/dotnet/api/system.collections.concurrent.concurrentqueue-1和一个专门的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");
}
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)