如何使用unity3d可视化Firebase中的错误消息

时间:2018-11-06 20:59:08

标签: c# firebase unity3d firebase-authentication

我需要可视化带有错误消息的面板,以便通知用户 但我不知道如何从任务中获取异常。这是代码,当我开始游戏时收到此错误,并且面板为空且未启用:

  

SetActive只能从主线程调用。   加载场景时,将从加载线程执行构造函数和字段初始化程序。   不要在构造函数或字段初始化程序中使用此函数,而应将初始化代码移至Awake或Start函数。

public void firebaseRegistration(string email, string password){
     auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => {
        if (task.IsCanceled) {
            messagePanel.SetActive(true);
            Debug.LogError("Task canceled");
            message.GetComponent<Text>().text = "Task canceled";
            return;
        } else if (task.IsFaulted) {
            string error = task.Exception.GetBaseException().ToString();
            if (error.Contains("The email address is badly formatted")) {
                Debug.LogError("The email address is badly formatted");
                messagePanel.SetActive(true);
                message.GetComponent<Text>().text = "The email address is badly formatted";
                return;
            }
            if (error.Contains("The given password is invalid")) {
                Debug.LogError("The given password is invalid");
                messagePanel.SetActive(true);
                message.GetComponent<Text>().text ="The given password is invalid";
                return;
            }
            if (error.Contains("The email address is already in use by another account.")) {
                Debug.LogError("The email address is already in use by another account.");
                messagePanel.SetActive(true);
                message.GetComponent<Text>().text = "The email address is already in use by another account.";
                return;
            }
            Debug.LogError("Error during the creation of the user: " + task.Exception);
            Debug.Log("Error code: " + task.Exception.GetBaseException());
            return;
        }
        user = task.Result;
        Debug.LogFormat("User created: {0} ({1})", user.DisplayName, user.UserId);
    });
}

0 个答案:

没有答案