我正在使用Unity 2018.2.15f1,Firebase和Android / iOS。我有一些工作正常,直到没有。这是我在Firebase中设置的。
比赛 -Global1v1 -一个 --有效 ---MatchIDArray
我在Unity中所做的是:
public void CheckForAvailable1v1Match() {
reference.Child("Matches/OneVOne/Active/").GetValueAsync().ContinueWith(task => {
if (task.IsFaulted)
{
Debug.Log("Fault");
}
else if (task.IsCanceled) {
Debug.Log("Canceled");
}
else if (task.IsCompleted)
{
DataSnapshot snapshot = task.Result;
var closedCount = 1;
//ALL OF THESE BELOW WORK IN PLAYER BUT NOT ON DEVICE
//if (snapshot.ChildrenCount < 1)
//if (!snapshot.HasChildren)
//if (snapshot.ChildrenCount == 0)
//if (snapshot.Value == null)
//if (snapshot == null)
if(!snapshot.Exists)
{
Debug.Log("Does not exist here");
gameMNG.CreateOneOnX();
return;
}
if (snapshot.ChildrenCount > 0)
{
foreach (var c in snapshot.Children)
....
以上内容在播放器中效果很好,但只是挂在设备上。 Android和iOS。
根据我的阅读,如果您使用URL或查询查询firebase,快照将永远不会为null,因此它不会在快照== null上失败,因此您应该使用.Exists。
为了解决这个问题,我要做的只是在数组中添加一个我从未使用过的项,然后终结点将始终存在。当该桌子以某种方式被破坏,然后该桌子为空并且整个游戏失败时,问题就来了。
有什么想法吗?
更新 我重新组织了数据库,并将匹配对象分解为两个单独的位置。我现在有:
OneVOne /待处理和 Global1V1 / Active
然后我像以前一样使用快照== null,由于某种原因,它现在可以正常使用了……我很困惑,但是可以使用。