unity3d 如何获取统一的Firebase RemoteConfig参数

m0rkklqb  于 2022-11-25  发布在  其他
关注(0)|答案(1)|浏览(209)

我想得到这个参数的enter image description here。我尝试用这个代码FirebaseRemoteConfig.GetInstance(Firebase.FirebaseApp.DefaultInstance).GetValue(“VERSION”).ToString()来做这个,但是它什么都没有返回。我也试着用FirebaseRemoteConfig.DefaultInstance.GetValue来得到它,但是我得到了同样的结果。

using UnityEngine;
using UnityEngine.SceneManagement;
using Firebase.RemoteConfig;

public class GameOpening : MonoBehaviour
{
    Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
    // Use this for initialization
    void Start()
    {
        Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
            dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                
                Debug.Log(FirebaseRemoteConfig.DefaultInstance.GetValue("VERSION"));

            }
            else
            {
                Debug.LogError(
                    "Could not resolve all Firebase dependencies: " + dependencyStatus);
            }
        });
    }

    
}
kqlmhetl

kqlmhetl1#

在开始使用FirebaseRemoteConfig之前,你必须获取并激活它。你还应该决定你要使用的值的类型,例如Long。下一个例子应该可以工作:

using UnityEngine;
using UnityEngine.SceneManagement;
using Firebase.RemoteConfig;

public class GameOpening : MonoBehaviour
{
    Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
    // Use this for initialization
    async void Start()
    {
        await Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(async task => {
            var dependencyStatus = task.Result;
            if (dependencyStatus == Firebase.DependencyStatus.Available)
            {
                await FirebaseRemoteConfig.DefaultInstance.FetchAsync(TimeSpan.Zero);
                await FirebaseRemoteConfig.DefaultInstance.ActivateAsync();
                UnityEngine.Debug.Log(FirebaseRemoteConfig.DefaultInstance.GetValue("VERSION").LongValue);
            }
            else
            {
                UnityEngine.Debug.LogError(
                    "Could not resolve all Firebase dependencies: " + dependencyStatus);
            }
        });    
}

相关问题