【发布时间】:2020-08-22 06:49:40
【问题描述】:
我无法访问/编辑 getvalueasync 任务中的列表变量,任何尝试修改或读取列表“ShopItems”的代码都不会返回任何内容并阻止任何进一步的代码在同一范围内运行,不会返回任何错误在控制台中。 “ItemsLoaded” int 变量没有问题。
public static void IsItemPurchased(string item)
{
Debug.Log(ShopManager.ShopItems[0]); // This works
FirebaseDatabase.DefaultInstance.GetReference("/Shop/" + item + "/").GetValueAsync().ContinueWith(task =>
{
if (task.IsFaulted || task.IsCanceled)
{
Debug.LogError("Database: Failed to check item status - " + task.Exception);
}
else if (task.IsCompleted)
{
bool isPurchased;
if (task.Result.Value == null)
isPurchased = false;
else
isPurchased = (bool)task.Result.Value;
Debug.Log(ShopManager.ShopItems[0]); // Does not work
Debug.Log(ShopManager.ItemsLoaded); // This works
ShopManager.ShopItems.Where(i => i.gameObject.name == item).FirstOrDefault().Purchased = isPurchased; // Variable does not update
ShopManager.ItemsLoaded++;
}
});
}
【问题讨论】: