【问题标题】:How to change gameobjects in ContinueWith Firebase auth UNITY3D如何在 ContinueWith Firebase auth UNITY3D 中更改游戏对象
【发布时间】:2019-04-16 06:06:23
【问题描述】:

为什么我的代码不起作用?我想在 auth OK 或 auth Failed 后更改 UI 状态。

Services.Api.Auth.SignInWithEmailAndPasswordAsync(_emailField.text, _passwordField.text).ContinueWith(auth =>
    {
        if (auth.IsFaulted || auth.IsCanceled)
        {
            Services.Loading.Hide();
            Services.StateManager.ShowPopUp(Localisation.GetString("warningTitleText"), auth.Exception.Message.ToString());
            Debug.LogFormat("<color=red><b>[WEB]</b></color>" + " AUTHORIZATION FAULTED");
            return;
        }

        Services.Api.User = auth.Result;

        Services.Photon.Connect();
        Services.StateManager.Switch(nextState);

        Debug.LogFormat("<color=red><b>[WEB]</b></color>" + " AUTHORIZATION OK: {0}   ({1})",
            Services.Api.User.DisplayName, Services.Api.User.UserId);
    });

Debug.LogFormat 工作正常,但其他代码不工作:

            Services.Loading.Hide();
            Services.StateManager.ShowPopUp(Localisation.GetString("warningTitleText"), auth.Exception.Message.ToString());

        Services.Photon.Connect();
        Services.StateManager.Switch(nextState);

【问题讨论】:

  • 我必须将此异步添加到方法中,并且可以等待在主线程中继续: public async void LoginButton_Click(GameObject newState) { Services.Loading.Show();等待 Services.Api.Auth.SignInWithEmailAndPasswordAsync(_emailField.text, _passwordField.text).ContinueWith(task => { _taskStatus = task; }); ...

标签: c firebase unity3d firebase-authentication


【解决方案1】:

从您提供的小代码中,我最好的猜测是您正试图从“Services.Api.Auth.SignInWithEmailAndPasswordAsync”创建的某个随机线程中更改您的“UI 状态”。我对 Unity 中的多线程不太熟悉,但通常 UI 只能由拥有它的线程更改。

【讨论】:

  • 而在我的情况下,我可以根据授权是否成功来更改用户界面?
  • 我绝对肯定有一种方法可以完成你想要做的事情,但你必须在你的主线程上做......从你提供的小代码很难说发生了什么,您没有提供任何异常信息或类似信息...
猜你喜欢
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-27
  • 2014-11-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多