C# Firebase unity回调未调用GameObject.SetActive()

C# Firebase unity回调未调用GameObject.SetActive(),c#,unity3d,firebase-realtime-database,C#,Unity3d,Firebase Realtime Database,我使用Firebase实时数据库来存储某些游戏模式设置,并获取我使用的设置GetValueAsync().ContinueWith()当我使用Debug.Log()进行测试时,它工作正常,但当我需要通过激活消息对象来向玩家显示消息时,它工作不正常,此时,调试代码执行在到达GameObject.SetActive()之前停止。这就是我所描述的代码 private void GetValue(string path, Action<DataSnapshot> onValueGet) {

我使用Firebase实时数据库来存储某些游戏模式设置,并获取我使用的设置
GetValueAsync().ContinueWith()
当我使用
Debug.Log()
进行测试时,它工作正常,但当我需要通过激活消息对象来向玩家显示消息时,它工作不正常,此时,调试代码执行在到达
GameObject.SetActive()
之前停止。这就是我所描述的代码

private void GetValue(string path, Action<DataSnapshot> onValueGet)
{
    dbRef.Child(path).GetValueAsync().ContinueWith(task =>
    {
        if (task.IsFaulted)
        {
            Debug.LogError($"Failed getting Value Async. {task.Exception}");
        }

        if (task.IsCompleted)
        {
            onValueGet?.Invoke(task.Result);
        }
    });
}

internal void GetGamemode(string id, Action<Gamemode> onGamemodeGet)
{
    GetValue($"{id}/Settings/Gamemode", (snapshot) =>
    {
        if (int.TryParse(snapshot.ToString(), out int result))
        {
            onGamemodeGet?.Invoke((Gamemode)result);
        }
        else
        {
            onGamemodeGet?.Invoke(Gamemode.Default);
        }
    });
}

通过调试,我看到它调用了
ShowMessage()
,但在
ShowMessage()
方法中它什么也不做。

好的,我让它工作的方法是在一个协程中等待响应,并在得到响应后调用回调

private IEnumerator GetValue(string path, Action<DataSnapshot> onValueGet)
{
    bool responseGot = false;
    DataSnapshot responsePayload = null;
    dbRef.Child(path).GetValueAsync().ContinueWith(task =>
    {
        if (task.IsFaulted)
        {
            Debug.LogError($"Failed getting Value Async. {task.Exception}");
        }

        responseGot = true;
        responsePayload = task.Result;
    });

    yield return new WaitUntil(() => responseGot);
    onValueGet?.Invoke(responsePayload);
}
private IEnumerator GetValue(字符串路径,操作onValueGet)
{
bool responseGot=false;
DataSnapshot responsePayload=null;
dbRef.Child(路径).GetValueAsync().ContinueWith(任务=>
{
if(task.IsFaulted)
{
LogError($“获取值异步失败。{task.Exception}”);
}
responseGot=true;
responsePayload=task.Result;
});
返回新的等待时间(()=>responseGot);
onValueGet?调用(responsePayload);
}
这是用于获取值的修改方法,它可以正确地与
UnityEngine
对象交互

private IEnumerator GetValue(string path, Action<DataSnapshot> onValueGet)
{
    bool responseGot = false;
    DataSnapshot responsePayload = null;
    dbRef.Child(path).GetValueAsync().ContinueWith(task =>
    {
        if (task.IsFaulted)
        {
            Debug.LogError($"Failed getting Value Async. {task.Exception}");
        }

        responseGot = true;
        responsePayload = task.Result;
    });

    yield return new WaitUntil(() => responseGot);
    onValueGet?.Invoke(responsePayload);
}