C# 无法从unity3d中的firebase实时数据库检索数据
我是unity firebase开发者的新手。基本上,我制作了一个函数C# 无法从unity3d中的firebase实时数据库检索数据,c#,firebase,unity3d,firebase-realtime-database,C#,Firebase,Unity3d,Firebase Realtime Database,我是unity firebase开发者的新手。基本上,我制作了一个函数GetPlayerPrize,从firebase获取特定的(登录用户)奖品详细信息。但在从firebase实时数据库检索数据时,我无法得到任何响应 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Firebase; using Firebase.Auth; usi
GetPlayerPrize
,从firebase获取特定的(登录用户)奖品详细信息。但在从firebase实时数据库检索数据时,我无法得到任何响应
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Firebase;
using Firebase.Auth;
using Firebase.Database;
using Firebase.Unity.Editor;
public class prizeCanvasScript : MonoBehaviour
{
public Text silver;
public Text gold;
public Button silverButton;
public Button GoldButton;
public Firebase.Auth.FirebaseAuth auth;
public Firebase.Auth.FirebaseUser user;
public void Start() {
InitializeFirebase();
}
public void InitializeFirebase()
{
FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://robberbird.firebaseio.com/");
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
user = auth.CurrentUser;
GetPlayerPrize();
}
void GetPlayerPrize()
{
Debug.Log("Getting player data" + user.UserId);
FirebaseDatabase.DefaultInstance
.GetReference("users")
.Child(user.UserId)
.GetValueAsync()
.ContinueWith((task) =>{
if (task.IsFaulted)
{
Debug.LogError("Error retriving user data: " + user.UserId);
// Handle the error...
}
else if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
Debug.Log("snapshot" );
Debug.Log(snapshot);
// silver.text = snapshot.silverChest.ToString();
// gold.text = snapshot.GoldChest.ToString();
}
});
}
}
是否使用任务引用默认实例
static Task DI = new System.Threading.Tasks.Task(LoginAnon);
public static void LoginAnon()
{
DI = FirebaseAuth.DefaultInstance.SignInAnonymouslyAsync().ContinueWith(result =>
{
FirebaseDatabase.DefaultInstance.GetReference("Lobbies/").ChildAdded += HandleLobbyAdded;
FirebaseDatabase.DefaultInstance.GetReference("Lobbies/").ChildRemoved += HandleLobbyRemoved;
});
}
你是说这两个都不是Debug.LogError(“错误检索用户数据:“+user.UserId”)代码>或
调试日志(“快照”)有人打过电话吗?有。LogError(“检索用户数据时出错:“+user.UserId”);也不是Debug.Log(“快照”);曾经打过电话。
public static void HandleLobbyRemoved(object sender, ChildChangedEventArgs e)
{
DataSnapshot snap = e.Snapshot;
if (e.DatabaseError != null)
{
Debug.LogError(e.DatabaseError.Message);
return;
}
//User who created the lobby
string uID = snap.Key.ToString();
}