我有一个带有Firebase的Google身份验证Unity项目。我将用户信息存储在实时数据库中。它们存储为:
UnityProject
1->
Name: "Something"
Email: "Something"
2->
Name: "some other thing"
Email: "Something else"
现在,这些1,2由我提供(用作主键)。我首先给第一个用户ID 1和第二个使用的ID 2,依此类推。
但是我需要从Firebase取回存储的最后一个ID。例如,>
idToInsert = GetLastUsedID() + 1;
我已经使用了此代码,但是它不起作用。屏幕一直冻结,直到我强制关闭Unity。
public int GetLastUsedID() { int currentID = 1; bool continueSearch = true; while (continueSearch) { FirebaseREST.DatabaseReference reference = FirebaseREST.FirebaseDatabase.Instance.GetReference(""+currentID); string value = ""; currentID++; reference.GetValueAsync(10, (res) => { if (res.success) { value = res.data.GetRawJsonValue(); Debug.Log("Success fetched data : " + value); if(value == "") { continueSearch = false; Debug.Log(currentID); } } else { Debug.Log("Fetch data failed : " + res.message); continueSearch = false; } }); } return currentID; }
基本上,我只是尝试从1进行迭代,直到得到空字符串为止。空字符串表示该ID下不存在任何数据。
我有一个带有Firebase的Google身份验证Unity项目。我将用户信息存储在实时数据库中。它们存储为:UnityProject 1->名称:“ Something”电子邮件:...
我不熟悉FirebaseREST
(如果可以的话,我建议您使用official Firebase plugin,它不仅可以调用REST端点,还可以做很多事情,但是我认为我可以看到您的问题。