| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  | namespace Guru | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     using UnityEngine; | 
					
						
							|  |  |  |     using System; | 
					
						
							| 
									
										
										
										
											2023-12-28 08:33:12 +00:00
										 |  |  |     using System.Collections; | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |     using System.Collections.Generic; | 
					
						
							|  |  |  |     using System.IO; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     public partial class GuruSDK: MonoBehaviour | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2024-01-29 08:27:01 +00:00
										 |  |  |         public const string Version = "1.0.6"; | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         public const string Tag = "[Guru]"; | 
					
						
							|  |  |  |         public const string ServicesConfigKey = "guru_services"; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |          | 
					
						
							|  |  |  |         private static GuruSDK _instance; | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 单利引用 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         public static GuruSDK Instance | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             get | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if(null == _instance) | 
					
						
							|  |  |  |                 { | 
					
						
							|  |  |  |                     _instance = CreateInstance(); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 return _instance; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private GuruSDKInitConfig _initConfig; | 
					
						
							|  |  |  |         private Action<bool> _onCompleteCallback; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private static GuruSDKModel _model; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         internal static GuruSDKInitConfig InitConfig => Instance._initConfig; | 
					
						
							|  |  |  |         internal static GuruSDKModel Model => GuruSDKModel.Instance; | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         private static GuruServicesConfig _appServicesConfig; | 
					
						
							| 
									
										
										
										
											2024-01-10 06:02:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-10 11:16:10 +00:00
										 |  |  |         private static GuruSettings _guruSettings; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private static GuruSettings GuruSettings | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             get | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 if (_guruSettings == null) _guruSettings = GuruSettings.Instance; | 
					
						
							|  |  |  |                 return _guruSettings; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-17 12:46:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private static bool _isDebugEnabled = false; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// Debug Mode | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         public static bool IsDebugMode | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             get | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  | #if UNITY_EDITOR || DEBUG | 
					
						
							|  |  |  |                 return true; | 
					
						
							|  |  |  | #endif | 
					
						
							| 
									
										
										
										
											2024-01-17 12:46:23 +00:00
										 |  |  |                 return _isDebugEnabled; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-07 14:59:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 初始化成功标志位 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         public static bool IsInitialSuccess { get; private set; } = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         #region 初始化 | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         private static GuruSDK CreateInstance() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             var go = new GameObject(nameof(GuruSDK)); | 
					
						
							|  |  |  |             DontDestroyOnLoad(go); | 
					
						
							|  |  |  |             _instance = go.AddComponent<GuruSDK>(); | 
					
						
							|  |  |  |             return _instance; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         public static GuruSDKInitConfig BuildConfig( | 
					
						
							|  |  |  |             bool useCustomConsent = false,  | 
					
						
							|  |  |  |             bool autoLoadAds = true,  | 
					
						
							|  |  |  |             bool iapEnabled = true,  | 
					
						
							|  |  |  |             bool autoRecordFinishedLevels = true,  | 
					
						
							| 
									
										
										
										
											2024-01-18 09:03:53 +00:00
										 |  |  |             bool debugMode = false, | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |             Dictionary<string, object> defaultRemoteData = null, | 
					
						
							|  |  |  |             byte[] googleKeys = null, | 
					
						
							|  |  |  |             byte[] appleRootCerts = null) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             var config = GuruSDKInitConfig.Build(useCustomConsent, autoLoadAds, iapEnabled,  | 
					
						
							| 
									
										
										
										
											2024-01-18 09:03:53 +00:00
										 |  |  |                 autoRecordFinishedLevels, debugMode, defaultRemoteData, googleKeys, appleRootCerts); | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |             return config; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         public static void Init(Action<bool> onComplete) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Init(GuruSDKInitConfig.Build(), onComplete); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         public static void Init(GuruSDKInitConfig config, Action<bool> onComplete) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2024-01-07 14:59:02 +00:00
										 |  |  |             LogI($"---- Guru SDK init ----\n{config.ToString()}"); | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |             Instance.StartWithConfig(config, onComplete); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 启动SDK | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="config"></param> | 
					
						
							|  |  |  |         /// <param name="onComplete"></param> | 
					
						
							|  |  |  |         private void StartWithConfig(GuruSDKInitConfig config, Action<bool> onComplete) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Model.PropBLevel.OnValueChanged += OnBLevelChanged; | 
					
						
							|  |  |  |             Model.PropBPlay.OnValueChanged += OnBPlayChanged; | 
					
						
							|  |  |  |              | 
					
						
							| 
									
										
										
										
											2024-01-17 12:46:23 +00:00
										 |  |  |             IsInitialSuccess = false; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |             _initConfig = config; | 
					
						
							|  |  |  |             _onCompleteCallback = onComplete; | 
					
						
							| 
									
										
										
										
											2024-01-17 12:46:23 +00:00
										 |  |  |             _isDebugEnabled = config.DebugMode; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-08 07:01:04 +00:00
										 |  |  |             //--- 之后的逻辑放在 Start 方法内 --- | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         void Start() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             //---- Init All tools ---- | 
					
						
							| 
									
										
										
										
											2024-01-10 06:02:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |             //---------- Start Firebase ------------ | 
					
						
							|  |  |  |             FirebaseUtil.InitFirebase(OnFirebaseReady); | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |             // FirebaseUtil.OnFetchRemoteSuccess+= OnFetchRemoteCallback; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |             //---------- Start Facebook ------------ | 
					
						
							|  |  |  |             FBService.Instance.StartService(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-08 07:01:04 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 开始各种组件初始化 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         private void OnFirebaseReady() | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2024-01-08 07:01:04 +00:00
										 |  |  |             IsInitialSuccess = true; | 
					
						
							| 
									
										
										
										
											2024-01-30 02:23:49 +00:00
										 |  |  |     | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |             if (!InitConfig.UseCustomConsent) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |                 // LogI($"--- #3 Start Consent Flow ---"); | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |                 StartConsentFlow(); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-12-28 08:33:12 +00:00
										 |  |  |              | 
					
						
							|  |  |  |             if(!string.IsNullOrEmpty(IPMConfig.IPM_UID)) SetUID(IPMConfig.IPM_UID); | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |             // 开始Remote Manager初始化  | 
					
						
							|  |  |  |             RemoteConfigManager.Init(BuildDefaultRemoteData(_initConfig.DefaultRemoteData)); | 
					
						
							|  |  |  |             RemoteConfigManager.OnFetchCompleted += OnFetchRemoteCallback; | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |              | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |             // 根据上次的云控配置来初始化参数 | 
					
						
							|  |  |  |             SetupServicesConfig(); | 
					
						
							| 
									
										
										
										
											2024-01-08 07:01:04 +00:00
										 |  |  |              | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |             _onCompleteCallback?.Invoke(true); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |          | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 注入云控参数基础数据 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="dict"></param> | 
					
						
							|  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |         private Dictionary<string, object> BuildDefaultRemoteData(Dictionary<string, object> dict) | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2024-01-07 14:59:02 +00:00
										 |  |  |             if (dict == null) dict = new Dictionary<string, object>(3); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |             // 注入默认的 Services 配置值 | 
					
						
							|  |  |  |             string json = Model.LoadDefaltServicesConfigJson();  | 
					
						
							|  |  |  |             if (!string.IsNullOrEmpty(json)) dict[ServicesConfigKey] = json; | 
					
						
							|  |  |  |         | 
					
						
							|  |  |  |             return dict; | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 拉取云控参数完成 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="success"></param> | 
					
						
							|  |  |  |         private void OnFetchRemoteCallback(bool success) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             LogI($"--- Remote fetch complete: {success} ---"); | 
					
						
							|  |  |  |             ABTestManager.Init(); // 启动AB测试解析器 | 
					
						
							|  |  |  |             Callbacks.Remote._onRemoteFetchComplete?.Invoke(success); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region App Remote Update | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void SetupServicesConfig() | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |             bool useKeywords = false; | 
					
						
							| 
									
										
										
										
											2023-12-28 08:33:12 +00:00
										 |  |  |             bool useIAP = true; | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |              | 
					
						
							|  |  |  |             var services = GetRemoteServicesConfig(); | 
					
						
							|  |  |  |             if (services != null) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 _appServicesConfig = services; | 
					
						
							| 
									
										
										
										
											2023-12-28 08:33:12 +00:00
										 |  |  |                 useKeywords = _appServicesConfig.IsKeywordsEnabled(); | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |                 useIAP = _appServicesConfig.IsIAPEnabled(); | 
					
						
							| 
									
										
										
										
											2023-12-28 08:33:12 +00:00
										 |  |  |                  | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |            | 
					
						
							|  |  |  |                 if (null != _appServicesConfig.adjust_settings && null != GuruSettings) | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |                     // 更新 Adjust Tokens | 
					
						
							| 
									
										
										
										
											2024-02-02 11:06:32 +00:00
										 |  |  |                     GuruSettings.UpdateAdjustTokens( | 
					
						
							|  |  |  |                         _appServicesConfig.adjust_settings.AndroidToken(), | 
					
						
							|  |  |  |                         _appServicesConfig.adjust_settings.iOSToken()); | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |                     // 更新 Adjust Events | 
					
						
							|  |  |  |                     GuruSettings.UpdateAdjustEvents(_appServicesConfig.adjust_settings.events); | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |                  | 
					
						
							|  |  |  |                 if (null != _appServicesConfig.app_settings) | 
					
						
							| 
									
										
										
										
											2024-01-08 10:45:22 +00:00
										 |  |  |                 { | 
					
						
							| 
									
										
										
										
											2024-02-02 11:06:32 +00:00
										 |  |  |                     if (_appServicesConfig.app_settings.tch_020 > 0) | 
					
						
							| 
									
										
										
										
											2024-01-10 06:02:53 +00:00
										 |  |  |                     { | 
					
						
							|  |  |  |                         Analytics.EnableTch02Event = true; | 
					
						
							| 
									
										
										
										
											2024-02-02 11:06:32 +00:00
										 |  |  |                         Analytics.SetTch02TargetValue(_appServicesConfig.app_settings.tch_020); | 
					
						
							| 
									
										
										
										
											2024-01-10 06:02:53 +00:00
										 |  |  |                     } | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |                       | 
					
						
							|  |  |  |                     // 设置获取设备 UUID 的方法 | 
					
						
							|  |  |  |                     if (_appServicesConfig.app_settings.using_uuid) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         IPMConfig.UsingUUID = true; // 开始使用 UUID 作为 DeviceID 标识 | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (null !=  GuruSettings) | 
					
						
							|  |  |  |                     { | 
					
						
							|  |  |  |                         // 更新和升级 GuruSettings 对应的值 | 
					
						
							|  |  |  |                         GuruSettings.UpdateAppSettings( | 
					
						
							|  |  |  |                             _appServicesConfig.app_settings.bundle_id, | 
					
						
							|  |  |  |                             _appServicesConfig.fb_settings?.fb_app_id ?? "", | 
					
						
							|  |  |  |                             _appServicesConfig.app_settings.support_email, | 
					
						
							|  |  |  |                             _appServicesConfig.app_settings.privacy_url, | 
					
						
							|  |  |  |                             _appServicesConfig.app_settings.terms_url, | 
					
						
							|  |  |  |                             _appServicesConfig.app_settings.android_store, | 
					
						
							|  |  |  |                             _appServicesConfig.app_settings.ios_store); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2024-01-08 10:45:22 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-01-08 02:22:56 +00:00
										 |  |  |              | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  |             if (useIAP) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-12-28 08:33:12 +00:00
										 |  |  |                 InitIAP(_initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-01-31 04:54:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |             if (useKeywords) | 
					
						
							|  |  |  |             { | 
					
						
							| 
									
										
										
										
											2023-12-28 08:33:12 +00:00
										 |  |  |                 KeywordsManager.Install(Model.IsIAPUser, Model.SuccessLevelCount); // 启动Keyword管理器 | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private GuruServicesConfig GetRemoteServicesConfig() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             var json = GetRemoteString(ServicesConfigKey); | 
					
						
							|  |  |  |             if (!string.IsNullOrEmpty(json)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 return JsonParser.ToObject<GuruServicesConfig>(json); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 数据 | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         private void OnBLevelChanged(int blevel) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             SetUserBLevel(blevel); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnBPlayChanged(int bplay) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             SetUserBPlay(bplay); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-07 14:59:02 +00:00
										 |  |  |         public static string UID => _model?.UserId ?? ""; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-10 11:16:10 +00:00
										 |  |  |         public static string SupportEmail => GuruSettings.SupportEmail ?? ""; | 
					
						
							| 
									
										
										
										
											2024-01-10 10:22:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         public static string StoreUrl | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             get | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 string url = ""; | 
					
						
							|  |  |  | #if UNITY_EDITOR | 
					
						
							| 
									
										
										
										
											2024-01-15 12:52:22 +00:00
										 |  |  |                 url = "https://test@com.guru.ai"; | 
					
						
							| 
									
										
										
										
											2024-01-10 10:22:02 +00:00
										 |  |  | #elif UNITY_ANDROID | 
					
						
							| 
									
										
										
										
											2024-01-10 11:16:10 +00:00
										 |  |  |                 url = GuruSettings?.AndroidStoreUrl ?? ""; | 
					
						
							| 
									
										
										
										
											2024-01-10 10:22:02 +00:00
										 |  |  | #elif UNITY_IOS | 
					
						
							| 
									
										
										
										
											2024-01-10 11:16:10 +00:00
										 |  |  |                 url = GuruSettings?.IOSStoreUrl ?? ""; | 
					
						
							| 
									
										
										
										
											2024-01-10 10:22:02 +00:00
										 |  |  | #endif | 
					
						
							|  |  |  |                 return url; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         #endregion | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         #region Misc | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 打开页面 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="url"></param> | 
					
						
							|  |  |  |         public static void OpenURL(string url) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             GuruWebview.OpenPage(url); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-10 10:22:02 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region Logging | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2024-01-08 03:31:58 +00:00
										 |  |  |         internal static void LogI(object message) | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             Debug.Log($"{Tag} {message}"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2024-01-08 03:31:58 +00:00
										 |  |  |         internal static void LogW(object message) | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             Debug.LogWarning($"{Tag} {message}"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2024-01-08 03:31:58 +00:00
										 |  |  |         internal static void LogE(object message) | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             Debug.LogError($"{Tag} {message}"); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2024-01-08 03:31:58 +00:00
										 |  |  |         internal static void LogException(string message) | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             LogException( new Exception($"{Tag} {message}")); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2024-01-08 03:31:58 +00:00
										 |  |  |         internal static void LogException(Exception e) | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |             Debug.LogException(e); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |         #endregion | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         #region 生命周期 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 暂停时处理 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="paused"></param> | 
					
						
							|  |  |  |         private void OnAppPauseHandler(bool paused) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if(paused) Model.Save(true); // 强制保存数据 | 
					
						
							|  |  |  |             Callbacks.App._onAppPaused?.Invoke(paused); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         private void OnApplicationPause(bool paused) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             OnAppPauseHandler(paused); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnApplicationFocus(bool hasFocus) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             OnAppPauseHandler(!hasFocus); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private void OnApplicationQuit() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             Model.Save(true); | 
					
						
							|  |  |  |             Callbacks.App._onAppQuit?.Invoke(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #endregion | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         #region 延迟处理 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 启动协程 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="enumerator"></param> | 
					
						
							|  |  |  |         /// <returns></returns> | 
					
						
							|  |  |  |         public static Coroutine DoCoroutine(IEnumerator enumerator) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return Instance != null ? Instance.StartCoroutine(enumerator) : null; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         public static void KillCoroutine(Coroutine coroutine) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if(coroutine != null) | 
					
						
							|  |  |  |                 Instance.StopCoroutine(coroutine); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-10 10:22:02 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         /// <summary> | 
					
						
							|  |  |  |         /// 延时执行 | 
					
						
							|  |  |  |         /// </summary> | 
					
						
							|  |  |  |         /// <param name="seconds"></param> | 
					
						
							|  |  |  |         /// <param name="callback"></param> | 
					
						
							|  |  |  |         public static void Delay(float seconds, Action callback) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             DoCoroutine(Instance.OnDelayCall(seconds, callback)); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         private IEnumerator OnDelayCall(float delay, Action callback) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (delay > 0) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 yield return new WaitForSeconds(delay); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 yield return null; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             callback?.Invoke(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-01-10 10:22:02 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-27 12:24:16 +00:00
										 |  |  |         #endregion | 
					
						
							| 
									
										
										
										
											2024-01-07 14:59:02 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2023-12-26 03:40:48 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } |