【发布时间】:2019-03-20 04:43:59
【问题描述】:
我可以使用 Unity 将数据写入我的数据库。但是,我想更新现有数据,我该怎么做? (即读取每个现有的子数据并更新它,例如 score_new = score_old + X)我需要使用快照但我无法成功:/
我的数据写入代码:
public void WriteDatabase(int score, int level, int kill, int death, int xp, int live)
{
string uid;
if(usermanager!=null && usermanager.user != null)
{
uid = usermanager.user.UserId;
Debug.Log("DataManager: Set User ID from UserManager for User: " + uid);
}
else
{
Debug.LogError("DataManager: Set User not set.");
return;
}
LeaderBoardEntry entry = new LeaderBoardEntry(uid, score, level, kill, death, xp, live);
Dictionary<string, System.Object> entryValues = entry.ToDictionary();
Dictionary<string, System.Object> childUpdates = new Dictionary<string, System.Object>();
childUpdates["/Players/" + uid + "/"] = entryValues;
reference.UpdateChildrenAsync(childUpdates).ContinueWith(task =>
{
if (task.IsCanceled)
{
Debug.LogError("DataManager: UpdateChildrenAsync is Cancelled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("DataManager: UpdateChildrenAsync is Faulted.");
return;
}
Debug.Log("DataManager: UpdateChildrenAsync is Completed.");
});
}
提前致谢,
【问题讨论】:
标签: c# unity3d firebase-realtime-database