From 073e60757d77a20ac89bfe19bfe8b3366ac9ece9 Mon Sep 17 00:00:00 2001 From: Fangh Date: Sun, 28 Jan 2024 21:28:48 +0100 Subject: [PATCH] fix(firebase): initialization was not done on main thread --- Assets/Scenes/PhoneView.unity | 2 +- Assets/Scripts/FirebaseInitializer.cs | 5 +++-- Assets/Scripts/GameManager.cs | 11 +++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Assets/Scenes/PhoneView.unity b/Assets/Scenes/PhoneView.unity index 9921c7b..c3345ef 100644 --- a/Assets/Scenes/PhoneView.unity +++ b/Assets/Scenes/PhoneView.unity @@ -3485,7 +3485,7 @@ MonoBehaviour: m_PressedTrigger: Pressed m_SelectedTrigger: Selected m_DisabledTrigger: Disabled - m_Interactable: 1 + m_Interactable: 0 m_TargetGraphic: {fileID: 1158329300} m_OnClick: m_PersistentCalls: diff --git a/Assets/Scripts/FirebaseInitializer.cs b/Assets/Scripts/FirebaseInitializer.cs index 305554f..cb441a6 100644 --- a/Assets/Scripts/FirebaseInitializer.cs +++ b/Assets/Scripts/FirebaseInitializer.cs @@ -1,5 +1,6 @@ using Firebase; using Firebase.Auth; +using Firebase.Extensions; using System; using UnityEngine; using UnityEngine.Android; @@ -19,7 +20,7 @@ void Start() { AskForCameraAuthorizationForAndroid(); - FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => + FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => { var dependencyStatus = task.Result; if (dependencyStatus == DependencyStatus.Available) @@ -43,7 +44,7 @@ void Authenticate() { FirebaseAuth auth = FirebaseAuth.DefaultInstance; - auth.SignInAnonymouslyAsync().ContinueWith(task => + auth.SignInAnonymouslyAsync().ContinueWithOnMainThread(task => { if (task.IsCanceled) { diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 3571c2f..526362e 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -1,13 +1,13 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using Firebase.Database; using Firebase.Extensions; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; using TMPro; -using Unity.VisualScripting; using UnityEngine; +using UnityEngine.UI; /// /// This is the game state manager on the phone side @@ -26,7 +26,7 @@ public class GameManager : MonoBehaviour public TextMeshProUGUI roomError; public TMP_InputField playerNameField; public TextMeshProUGUI nameError; - public UnityEngine.UI.Button submitNewPlayer; + public Button submitNewPlayer; [Header("WaitingRoom Component")] public TextMeshProUGUI listPlayersUI; @@ -54,6 +54,7 @@ public class GameManager : MonoBehaviour private void Awake() { + submitNewPlayer.interactable = false; FirebaseInitializer.Instance.onFirebaseReady += Initialize; } @@ -71,7 +72,6 @@ private void Start() if (PlayerPrefs.HasKey("lastplayername")) playerNameField.text = PlayerPrefs.GetString("lastplayername"); - submitNewPlayer.interactable = false; } private void OnApplicationQuit() @@ -135,9 +135,8 @@ private void Initialize() { FirebaseInitializer.Instance.onFirebaseReady -= Initialize; realtimeDB = FirebaseDatabase.DefaultInstance.RootReference; - Debug.Log("Realtime DB initialized"); - submitNewPlayer.interactable = true; + Debug.Log("Realtime DB initialized"); } ///