Unity的Firebase是否包含childByAutoId?
我是一名经验丰富的Firebase用户,最近正在与Unity 2019合作一个游戏项目。UnityFirebase框架是否包含与iOS/Web中可用的childByAutoId等效的Unity的Firebase是否包含childByAutoId?,firebase,unity3d,firebase-realtime-database,Firebase,Unity3d,Firebase Realtime Database,我是一名经验丰富的Firebase用户,最近正在与Unity 2019合作一个游戏项目。UnityFirebase框架是否包含与iOS/Web中可用的childByAutoId等效的 public void UploadHighScore(Highscore highscore) { string json = JsonUtility.ToJson(highscore); reference .Child("Highscores") .ChildByA
public void UploadHighScore(Highscore highscore) {
string json = JsonUtility.ToJson(highscore);
reference
.Child("Highscores")
.ChildByAutoID // does not exist
.SetRawJsonValueAsync(json);
}
在C#中是否有另一种获得唯一ID的最佳实践方法?在Unity上调用该方法
在Firebase支持的大多数平台上,它实际上被称为
push()
,而iOS将其称为childByAutoId()
,Frank正确回答了我的问题,并提供了文档参考。
下面是一个代码示例,以防其他人遇到此问题
public void UploadHighScore(Highscore highscore) {
DatabaseReference location = reference
.Child("Highscores")
.Push();
highscore.uuid = location.Key; // storing the uuid for later usage like deletion etc
string json = JsonUtility.ToJson(highscore);
location.SetRawJsonValueAsync(json);
Debug.Log($"auto generated ID: {location.Key}"); // new child uuid
}
谢谢你,弗兰克。总是一个完美而快速的答案。我感谢您提供的文档参考。