| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Threading.Tasks; | 
					
						
							| 
									
										
										
										
											2025-08-31 08:42:48 +00:00
										 |  |  |  | using AdjustSdk; | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  | using Firebase; | 
					
						
							| 
									
										
										
										
											2025-08-31 08:42:48 +00:00
										 |  |  |  | using Firebase.Extensions; | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  | using Firebase.RemoteConfig; | 
					
						
							| 
									
										
										
										
											2025-08-31 03:55:05 +00:00
										 |  |  |  | using SDK.Utils; | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-31 03:55:05 +00:00
										 |  |  |  | public class FireBaseRemoteConfigManager : NormalSingleton<FireBaseRemoteConfigManager> | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-08-31 08:42:48 +00:00
										 |  |  |  |     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归因                    | 
					
						
							|  |  |  |  |                     }); | 
					
						
							|  |  |  |  |                 }); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |      | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 获取int参数 | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="key"></param> | 
					
						
							|  |  |  |  |     /// <param name="defaultValue"></param> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							| 
									
										
										
										
											2025-08-31 03:55:05 +00:00
										 |  |  |  |     public async Task<int> GetRemoteConfigInt(string key,  int defaultValue = 0) | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         try | 
					
						
							|  |  |  |  |         { | 
					
						
							| 
									
										
										
										
											2025-08-31 08:42:48 +00:00
										 |  |  |  |             // await FirebaseRemoteConfig.DefaultInstance.FetchAsync(TimeSpan.Zero); | 
					
						
							|  |  |  |  |             // await FirebaseRemoteConfig.DefaultInstance.ActivateAsync(); | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  |          | 
					
						
							|  |  |  |  |             // 获取值 | 
					
						
							|  |  |  |  |             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> | 
					
						
							| 
									
										
										
										
											2025-08-31 08:42:48 +00:00
										 |  |  |  |     public string GetRemoteConfigString(string key,  string defaultValue = "") | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         try | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             // 获取值 | 
					
						
							|  |  |  |  |             var configValue = FirebaseRemoteConfig.DefaultInstance.GetValue(key); | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |              | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  |             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> | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |     public bool GetRemoteConfigBool(string key,  bool defaultValue = false) | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         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> | 
					
						
							| 
									
										
										
										
											2025-08-31 09:26:39 +00:00
										 |  |  |  |     public float GetRemoteConfigBool(string key,  float defaultValue = 0) | 
					
						
							| 
									
										
										
										
											2025-08-30 08:47:09 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         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; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |