【发布时间】:2022-02-17 14:48:36
【问题描述】:
我想在“DAL”类中调用 Firebase 函数,因为我想创建一些抽象。我无法弄清楚如何从回调内部返回变量,或者如何传入回调以从我创建的控制器类中执行。我如何使 UserExistsInFirebase 异步并从控制器类中调用它,例如
public void GetUser() {
bool exists = await firebase.UserExistsInFirebase("User1");
}
public Task<bool> UserExistsInFirebase(string Username)
{
bool isExists = false;
reference.Child("Users").Child(Username).Child("Username").Child(Username).GetValueAsync().ContinueWithOnMainThread(task =>
{
if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
//checks to see if we found another user with the same username
if (snapshot.GetValue(true) != null)
{
isExists = true;
}
}
});
return isExists;
}
【问题讨论】:
标签: c# unity3d firebase-realtime-database