fix(firebase): initialization was not done on main thread

This commit is contained in:
Fangh 2024-01-28 21:28:48 +01:00
parent b0ae9e077a
commit 073e60757d
3 changed files with 9 additions and 9 deletions

View File

@ -3485,7 +3485,7 @@ MonoBehaviour:
m_PressedTrigger: Pressed m_PressedTrigger: Pressed
m_SelectedTrigger: Selected m_SelectedTrigger: Selected
m_DisabledTrigger: Disabled m_DisabledTrigger: Disabled
m_Interactable: 1 m_Interactable: 0
m_TargetGraphic: {fileID: 1158329300} m_TargetGraphic: {fileID: 1158329300}
m_OnClick: m_OnClick:
m_PersistentCalls: m_PersistentCalls:

View File

@ -1,5 +1,6 @@
using Firebase; using Firebase;
using Firebase.Auth; using Firebase.Auth;
using Firebase.Extensions;
using System; using System;
using UnityEngine; using UnityEngine;
using UnityEngine.Android; using UnityEngine.Android;
@ -19,7 +20,7 @@ void Start()
{ {
AskForCameraAuthorizationForAndroid(); AskForCameraAuthorizationForAndroid();
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{ {
var dependencyStatus = task.Result; var dependencyStatus = task.Result;
if (dependencyStatus == DependencyStatus.Available) if (dependencyStatus == DependencyStatus.Available)
@ -43,7 +44,7 @@ void Authenticate()
{ {
FirebaseAuth auth = FirebaseAuth.DefaultInstance; FirebaseAuth auth = FirebaseAuth.DefaultInstance;
auth.SignInAnonymouslyAsync().ContinueWith(task => auth.SignInAnonymouslyAsync().ContinueWithOnMainThread(task =>
{ {
if (task.IsCanceled) if (task.IsCanceled)
{ {

View File

@ -1,13 +1,13 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Firebase.Database; using Firebase.Database;
using Firebase.Extensions; using Firebase.Extensions;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TMPro; using TMPro;
using Unity.VisualScripting;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
/// <summary> /// <summary>
/// This is the game state manager on the phone side /// This is the game state manager on the phone side
@ -26,7 +26,7 @@ public class GameManager : MonoBehaviour
public TextMeshProUGUI roomError; public TextMeshProUGUI roomError;
public TMP_InputField playerNameField; public TMP_InputField playerNameField;
public TextMeshProUGUI nameError; public TextMeshProUGUI nameError;
public UnityEngine.UI.Button submitNewPlayer; public Button submitNewPlayer;
[Header("WaitingRoom Component")] [Header("WaitingRoom Component")]
public TextMeshProUGUI listPlayersUI; public TextMeshProUGUI listPlayersUI;
@ -54,6 +54,7 @@ public class GameManager : MonoBehaviour
private void Awake() private void Awake()
{ {
submitNewPlayer.interactable = false;
FirebaseInitializer.Instance.onFirebaseReady += Initialize; FirebaseInitializer.Instance.onFirebaseReady += Initialize;
} }
@ -71,7 +72,6 @@ private void Start()
if (PlayerPrefs.HasKey("lastplayername")) if (PlayerPrefs.HasKey("lastplayername"))
playerNameField.text = PlayerPrefs.GetString("lastplayername"); playerNameField.text = PlayerPrefs.GetString("lastplayername");
submitNewPlayer.interactable = false;
} }
private void OnApplicationQuit() private void OnApplicationQuit()
@ -135,9 +135,8 @@ private void Initialize()
{ {
FirebaseInitializer.Instance.onFirebaseReady -= Initialize; FirebaseInitializer.Instance.onFirebaseReady -= Initialize;
realtimeDB = FirebaseDatabase.DefaultInstance.RootReference; realtimeDB = FirebaseDatabase.DefaultInstance.RootReference;
Debug.Log("Realtime DB initialized");
submitNewPlayer.interactable = true; submitNewPlayer.interactable = true;
Debug.Log("Realtime DB initialized");
} }
/// <summary> /// <summary>