SDK_UnityMoney/Assets/Script/SDKManager/FirebaseManager/FireBaseRemoteConfigManager.cs

160 lines
4.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Threading.Tasks;
using AdjustSdk;
using Firebase;
using Firebase.Extensions;
using Firebase.RemoteConfig;
using SDK.Utils;
using UnityEngine;
public class FireBaseRemoteConfigManager : NormalSingleton<FireBaseRemoteConfigManager>
{
public void FetchRemoteConfig()
{
Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task =>
{
if (task.Result == Firebase.DependencyStatus.Available)
{
Firebase.RemoteConfig.FirebaseRemoteConfig.DefaultInstance.FetchAsync(TimeSpan.Zero).ContinueWithOnMainThread(task =>
{
FirebaseRemoteConfig.DefaultInstance.ActivateAsync().ContinueWithOnMainThread(task =>
{
// adjust卸载监控
/* 执行到这时表示firebase接入正常能获取到远端在线参数 */
// 设置 firebase 初始化成功 flag
// 初始化广告
// 检查Adjust归因
});
});
}
});
}
/// <summary>
/// 获取int参数
/// </summary>
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public async Task<int> GetRemoteConfigInt(string key, int defaultValue = 0)
{
try
{
// await FirebaseRemoteConfig.DefaultInstance.FetchAsync(TimeSpan.Zero);
// await FirebaseRemoteConfig.DefaultInstance.ActivateAsync();
// 获取值
var configValue = FirebaseRemoteConfig.DefaultInstance.GetValue(key);
if (configValue.Source == ValueSource.RemoteValue)
{
return (int)configValue.LongValue;
}
else
{
return defaultValue;
}
}
catch (Exception e)
{
Debug.LogError($"Failed to get Remote Config value for key '{key}': {e.Message}");
return defaultValue;
}
}
/// <summary>
/// 获取string参数
/// </summary>
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public string GetRemoteConfigString(string key, string defaultValue = "")
{
try
{
// 获取值
var configValue = FirebaseRemoteConfig.DefaultInstance.GetValue(key);
if (configValue.Source == ValueSource.RemoteValue)
{
return configValue.StringValue;
}
else
{
return defaultValue;
}
}
catch (Exception e)
{
Debug.LogError($"Failed to get Remote Config value for key '{key}': {e.Message}");
return defaultValue;
}
}
/// <summary>
/// 获取bool参数
/// </summary>
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public bool GetRemoteConfigBool(string key, bool defaultValue = false)
{
try
{
// 获取值
var configValue = FirebaseRemoteConfig.DefaultInstance.GetValue(key);
if (configValue.Source == ValueSource.RemoteValue)
{
return configValue.BooleanValue;
}
else
{
return defaultValue;
}
}
catch (Exception e)
{
Debug.LogError($"Failed to get Remote Config value for key '{key}': {e.Message}");
return defaultValue;
}
}
/// <summary>
/// 获取float参数
/// </summary>
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
public float GetRemoteConfigBool(string key, float defaultValue = 0)
{
try
{
// 获取值
var configValue = FirebaseRemoteConfig.DefaultInstance.GetValue(key);
if (configValue.Source == ValueSource.RemoteValue)
{
return (float)configValue.DoubleValue;
}
else
{
return defaultValue;
}
}
catch (Exception e)
{
Debug.LogError($"Failed to get Remote Config value for key '{key}': {e.Message}");
return defaultValue;
}
}
}