我有最新的firebase unity SDK - 4.3.0
我的Unity版本是2017.2.0f3
在我的脚本中,如果我有两次调用GetValueAsync()。ContinueWith(),第一个正常执行,第二个暂停。如果我以某种方式将两个调用合并为一个,则程序在第一次调用时停止 我已经设置了数据库URL和引用。
IEnumerator fetchData()
{
int fetchGameDataStatus = 0;
int fetchPlayerDataStatus = 0;
try
{
reference.Child("PitJumping").GetValueAsync().ContinueWith(fetchTask =>
{
try
{
Debug.Log("Fetching data");
int i = 1;
if(fetchTask.IsCompleted)
{
foreach(var question in fetchTask.Result.Children)
{
int j = 1;
Dictionary<int,string> temp = new Dictionary<int, string>();
foreach(var option in question.Children)
{
temp.Add(j,option.Value.ToString());
j++;
}
gd.dict.Add(i, temp);
i++;
}
Debug.Log("End of task");
fetchGameDataStatus = 1;
}
else
{
Debug.Log(fetchTask.Exception.Message);
fetchGameDataStatus = 2;
}
}
catch(Exception e)
{
Debug.Log(e.Message);
Debug.Log("In fetch task catch!!!");
fetchGameDataStatus = 2;
}
Debug.Log("Reached");
});
}
catch(Exception e)
{
Debug.Log (e.Message);
fetchGameDataStatus = 2;
}
yield return new WaitUntil(()=> fetchGameDataStatus>0);
Debug.Log("fetchGameDataStatus = " + fetchGameDataStatus);
Debug.Log("Going to fetch PlayerData");
try
{
Debug.Log ("Reference set");
reference.Child("users").Child("sampleUserID").Child("PitJumping").GetValueAsync().ContinueWith(fetchTask =>
{
Debug.Log("Task for PlayerData started");
try
{
if (fetchTask.IsCompleted)
{
pd.questionsCompleted = int.Parse(fetchTask.Result.Value.ToString());
fetchPlayerDataStatus = 1;
}
else
{
fetchPlayerDataStatus = 2;
}
}
catch(Exception e)
{
Debug.Log(e.Message);
fetchPlayerDataStatus = 2;
}
});
}
catch(Exception e)
{
Debug.Log (e.Message);
fetchPlayerDataStatus = 2;
}
yield return new WaitUntil(() => (fetchGameDataStatus>0 && fetchPlayerDataStatus>0));
Debug.Log("fetched GD= " + fetchGameDataStatus);
Debug.Log("fetched PD= " + fetchPlayerDataStatus);
}
gd是GameData类的对象
pd是PlayerData类的对象
[Serializable]
class GameData
{
public Dictionary<int,Dictionary<int,string>> dict;
public GameData()
{
dict = new Dictionary<int, Dictionary<int, string>>();
}
}
[Serializable]
public class PlayerData
{
public int questionsCompleted;
public PlayerData(int x)
{
questionsCompleted = x;
}
public PlayerData()
{
Debug.Log("Empty constructor");
}
}
很抱歉没有正确关注MCVE,我无法准确找出错误原因 我意识到堆栈溢出已经有similar question,但答案并没有帮助我解决这个问题。