【发布时间】:2017-07-02 19:35:07
【问题描述】:
我正在努力解决我的 Unity 2D 游戏的一个问题,我使用 Firebase 实时数据库来存储配置文件、命中、未命中、关卡进度等数据。
目前,我正在开发用户可以创建新个人资料/新角色的场景。我有以下代码工作:
var db = FirebaseDatabase.DefaultInstance.RootReference;
Profile profile = new Profile {
userId = GameManager.Instance.User.UserId,
name = "Bo Mortensen",
age = 34,
gender = "M"
};
string json = JsonUtility.ToJson (profile);
// The Push() is almost instant
var profileKey = db.Child ("profiles").Push ().Key;
// However, this takes around 3 seconds to return, even when specifying 1 as it's priority..
db.Child("profiles").Child(profileKey).SetRawJsonValueAsync (json, 1).ContinueWith (t => {
if(t.IsFaulted) {
Debug.Log("Faulted..");
}
if(t.IsCanceled) {
Debug.Log("Cancelled..");
}
if(t.IsCompleted) {
SceneManager.LoadScene ("Main game scene");
}
});
因此,为密钥创建实际的配置文件引用几乎是即时的,而 SetRawJsonValueAsync 真的很慢。在加载下一个场景之前进行了大约 5 秒的测试。
这对于 Firebase 是否正常?我有一种感觉,我不应该等待任务返回任何东西,然后在加载下一个场景时让它在后台工作。这将非常快,但是如果它被取消或出现故障怎么办?我无法控制。
应该说我在调试模式下运行我的 Unity 游戏,而 Firebase 目前是用于开发的免费层。不确定 Firebase 的付费层是否会提高性能。
非常感谢任何帮助/提示!
提前致谢。
【问题讨论】:
标签: c# firebase unity3d firebase-realtime-database