Как визуализировать сообщения об ошибках в firebase с unity3d - PullRequest
0 голосов
/ 06 ноября 2018

Мне нужно визуализировать панель с сообщениями об ошибках, чтобы информировать пользователя но я не знаю, как получить исключение из задачи. Это код, когда я запускаю игру получаю эту ошибку и панель пуста и не активна:

SetActive можно вызывать только из основного потока. Конструкторы и инициализаторы полей будут выполняться из потока загрузки при загрузке сцены. Не используйте эту функцию в конструкторе или инициализаторах поля, вместо этого переместите код инициализации в функцию «Пробуждение» или «Запуск».

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);
    });
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...