From 4f3ab222c312f49deda96a4b4c909b75e082d2f2 Mon Sep 17 00:00:00 2001 From: HuYufei Date: Wed, 27 Dec 2023 20:24:16 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=20=E6=9B=B4=E6=96=B0=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E9=85=8D=E7=BD=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GuruManager/Config/EditorGuruServiceIO.cs | 43 +++- Editor/GuruManager/Helper/GuruSDKBooster.cs | 30 +-- Editor/GuruManager/Manager/GuruSDKManager.cs | 163 +++++++------ .../GuruServicesConfig.cs} | 12 +- .../GuruServicesConfig.cs.meta} | 0 Runtime/Code/Core/GuruSDK.Callback.cs | 45 +++- Runtime/Code/Core/GuruSDK.Remote.cs | 57 +++++ Runtime/Code/Core/GuruSDK.Remote.cs.meta | 3 + Runtime/Code/Core/GuruSDK.cs | 217 ++++++++++++++++-- Runtime/Code/IAP/GuruIAP.cs | 2 + Runtime/Code/Model/GuruSDKModel.cs | 35 ++- Runtime/Prefab.meta | 3 - package.json | 1 - 13 files changed, 448 insertions(+), 163 deletions(-) rename Runtime/Code/{Core/GuruServiceConfig.cs => Config/GuruServicesConfig.cs} (90%) rename Runtime/Code/{Core/GuruServiceConfig.cs.meta => Config/GuruServicesConfig.cs.meta} (100%) create mode 100644 Runtime/Code/Core/GuruSDK.Remote.cs create mode 100644 Runtime/Code/Core/GuruSDK.Remote.cs.meta delete mode 100644 Runtime/Prefab.meta diff --git a/Editor/GuruManager/Config/EditorGuruServiceIO.cs b/Editor/GuruManager/Config/EditorGuruServiceIO.cs index c079790..bdfa485 100644 --- a/Editor/GuruManager/Config/EditorGuruServiceIO.cs +++ b/Editor/GuruManager/Config/EditorGuruServiceIO.cs @@ -15,13 +15,13 @@ namespace Guru.Editor private static string DefaultFilePath = Path.GetFullPath(Path.Combine(Application.dataPath, $"{DefaultFileName}.json")); - private static string _selectedFilePath = ""; + internal static string EmbededServiceFilePath = ""; /// /// 加载配置 /// /// - public static GuruServiceConfig LoadConfig() + public static GuruServicesConfig LoadConfig() { var a = AssetDatabase.FindAssets($"*{DefaultFileName}* t:TextAsset"); if (a == null || a.Length == 0) @@ -32,10 +32,10 @@ namespace Guru.Editor { var p = AssetDatabase.GUIDToAssetPath(a[0]); var fp = Path.GetFullPath(p); - if (File.Exists(fp)) _selectedFilePath = fp; + if (File.Exists(fp)) EmbededServiceFilePath = fp; var t = AssetDatabase.LoadAssetAtPath(p); // Debug.Log($"--- find services file:{p} \n{t.text}"); - return JsonMapper.ToObject(t.text); + return JsonMapper.ToObject(t.text); } return null; } @@ -44,11 +44,11 @@ namespace Guru.Editor /// 保存配置 /// /// - internal static void SaveConfig(GuruServiceConfig config = null) + internal static void SaveConfig(GuruServicesConfig config = null) { if (config == null) { - config = new GuruServiceConfig(); + config = new GuruServicesConfig(); } var jw = new JsonWriter() @@ -59,19 +59,19 @@ namespace Guru.Editor var json = jw.ToString(); - if (string.IsNullOrEmpty(_selectedFilePath)) _selectedFilePath = DefaultFilePath; - File.WriteAllText(_selectedFilePath, json); - Debug.Log($"Save config to {_selectedFilePath}"); + if (string.IsNullOrEmpty(EmbededServiceFilePath)) EmbededServiceFilePath = DefaultFilePath; + File.WriteAllText(EmbededServiceFilePath, json); + Debug.Log($"Save config to {EmbededServiceFilePath}"); } /// /// 创建空配置 /// /// - internal static GuruServiceConfig CreateEmpty() + internal static GuruServicesConfig CreateEmpty() { - var cfg = new GuruServiceConfig(); - cfg.version = GuruSDK.Version; + var cfg = new GuruServicesConfig(); + cfg.version = 0; cfg.app_settings = new GuruAppSettings(); cfg.ad_settings = new GuruAdSettings(); cfg.adjust_settings = new GuruAdjustSettings(); @@ -88,6 +88,25 @@ namespace Guru.Editor } + public static void DeployAppServiceFile() + { + var streamingPath = Application.streamingAssetsPath; + if(!Directory.Exists(streamingPath)) Directory.CreateDirectory(streamingPath); + var path = Path.Combine(streamingPath, $"{GuruSDK.ServicesConfigKey}.{GuruSDK.ServicesConfigExtension}"); + var config = LoadConfig(); + var from = EmbededServiceFilePath; + if (string.IsNullOrEmpty(from) || !File.Exists(from)) // 文件不存在 + { + return; + } + + if (null != config) + { + if (File.Exists(path)) File.Delete(path); + Debug.Log($" --- setup {GuruSDK.ServicesConfigKey} file on streamingPath"); + File.Copy(from, path); + } + } } } \ No newline at end of file diff --git a/Editor/GuruManager/Helper/GuruSDKBooster.cs b/Editor/GuruManager/Helper/GuruSDKBooster.cs index 1f8d63a..93e8669 100644 --- a/Editor/GuruManager/Helper/GuruSDKBooster.cs +++ b/Editor/GuruManager/Helper/GuruSDKBooster.cs @@ -32,38 +32,12 @@ namespace Guru.Editor } } - - - // [InitializeOnLoad] + [InitializeOnLoad] internal class BoostOnLoad { static BoostOnLoad() { - var config = EditorGuruServiceIO.LoadConfig(); - if (null != config) - { - Debug.Log("found guru-services file on disk"); - // TODO: - } - else - { - Debug.Log("Can't find guru-services.json on load..."); - // GuruSDKManager.Open(); - EditorGuruServiceIO.LoadConfig(); - } - + EditorGuruServiceIO.DeployAppServiceFile(); } - - - - } - - - - - - - - } \ No newline at end of file diff --git a/Editor/GuruManager/Manager/GuruSDKManager.cs b/Editor/GuruManager/Manager/GuruSDKManager.cs index 3b0dfe8..fce1a2c 100644 --- a/Editor/GuruManager/Manager/GuruSDKManager.cs +++ b/Editor/GuruManager/Manager/GuruSDKManager.cs @@ -1,18 +1,13 @@ - - -using System.Collections.Generic; -using System.IO; -using Facebook.Unity.Settings; -using UnityEditor.Compilation; - namespace Guru.Editor { using System; using UnityEditor; using UnityEngine; using Guru; - using AppLovinMax.Scripts.IntegrationManager.Editor; - + using System.Collections.Generic; + using System.IO; + using Facebook.Unity.Settings; + using UnityEditor.Compilation; public class GuruSDKManager: EditorWindow { @@ -35,7 +30,7 @@ namespace Guru.Editor } } - private GuruServiceConfig _serviceConfig; + private GuruServicesConfig _servicesConfig; private static GUIStyle _itemTitleStyle; private static GUIStyle StyleItemTitle { @@ -74,8 +69,8 @@ namespace Guru.Editor private void OnEnable() { titleContent = new GUIContent("Guru SDK Manager"); - _serviceConfig = EditorGuruServiceIO.LoadConfig(); - if (_serviceConfig != null) + _servicesConfig = EditorGuruServiceIO.LoadConfig(); + if (_servicesConfig != null) { Debug.Log($"[Guru] Load success."); CheckServicesCompletion(); @@ -108,7 +103,7 @@ namespace Guru.Editor string mk_no = " ( \u2718 ) "; string mk_star = " ( \u2605 ) "; string check_passed = $"{MARK_INDENT}{mk_yes} All items passed!"; - if (_serviceConfig == null) + if (_servicesConfig == null) { AddResultLine($"{mk_yes} guru-services is missing", false); AddResultLine($"Please contact Guru tech support to get help.", false); @@ -123,7 +118,7 @@ namespace Guru.Editor //-------- APP Settings -------- passed = true; AddResultLine($"[ App ]"); - if (_serviceConfig.app_settings == null) + if (_servicesConfig.app_settings == null) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} settings is missing!", false); @@ -131,25 +126,25 @@ namespace Guru.Editor } else { - if (_serviceConfig.app_settings.app_id.IsNullOrEmpty()) + if (_servicesConfig.app_settings.app_id.IsNullOrEmpty()) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} AppID is missing!", false); _serviceCriticalFail++; } - if (_serviceConfig.app_settings.bundle_id.IsNullOrEmpty()) + if (_servicesConfig.app_settings.bundle_id.IsNullOrEmpty()) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} BundleID is missing!", false); _serviceCriticalFail++; } - if (_serviceConfig.app_settings.product_name.IsNullOrEmpty()) + if (_servicesConfig.app_settings.product_name.IsNullOrEmpty()) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Product Name is missing!", false); _serviceCriticalFail++; } - if (_serviceConfig.app_settings.support_email.IsNullOrEmpty()) + if (_servicesConfig.app_settings.support_email.IsNullOrEmpty()) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Support Email is missing!", false); @@ -162,7 +157,7 @@ namespace Guru.Editor //-------- ADS Settings -------- passed = true; AddResultLine($"[ Ads ]"); - if (_serviceConfig.ad_settings == null) + if (_servicesConfig.ad_settings == null) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} settings is missing!", false); @@ -170,61 +165,61 @@ namespace Guru.Editor } else { - if (_serviceConfig.ad_settings.sdk_key.IsNullOrEmpty()) + if (_servicesConfig.ad_settings.sdk_key.IsNullOrEmpty()) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} SDK Key is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.admob_app_id)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.admob_app_id)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Admob ID is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.max_ids_android)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.max_ids_android)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} AppLovin Android IDs is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.max_ids_ios)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.max_ids_ios)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} AppLovin iOS IDs is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.amazon_ids_android)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.amazon_ids_android)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Amazon Android IDs is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.amazon_ids_ios)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.amazon_ids_ios)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Amazon iOS IDs is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.pubmatic_ids_android)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.pubmatic_ids_android)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Pubmatic Android IDs is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.pubmatic_ids_ios)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.pubmatic_ids_ios)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Pubmatic iOS IDs is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.moloco_ids_android)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.moloco_ids_android)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Moloco Android Test IDs is missing!", false); _serviceNormalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.ad_settings.moloco_ids_ios)) + if (!IsArrayNotEmpty(_servicesConfig.ad_settings.moloco_ids_ios)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Moloco iOS Test IDs is missing!", false); @@ -236,7 +231,7 @@ namespace Guru.Editor //-------- Channels Settings -------- passed = true; AddResultLine($"[ Channels ]"); - if (_serviceConfig.fb_settings == null) + if (_servicesConfig.fb_settings == null) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Facebook settings is missing!", false); @@ -244,13 +239,13 @@ namespace Guru.Editor } else { - if (_serviceConfig.fb_settings.app_id.IsNullOrEmpty()) + if (_servicesConfig.fb_settings.app_id.IsNullOrEmpty()) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Facebook AppID is missing!", false); _serviceCriticalFail++; } - if (_serviceConfig.fb_settings.client_token.IsNullOrEmpty()) + if (_servicesConfig.fb_settings.client_token.IsNullOrEmpty()) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Facebook Client Token is missing!", false); @@ -258,7 +253,7 @@ namespace Guru.Editor } } - if (_serviceConfig.adjust_settings == null) + if (_servicesConfig.adjust_settings == null) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Adjust settings is missing!", false); @@ -266,14 +261,14 @@ namespace Guru.Editor } else { - if(!IsArrayNotEmpty(_serviceConfig.adjust_settings.app_token)) + if(!IsArrayNotEmpty(_servicesConfig.adjust_settings.app_token)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Adjust AppToken is missing!", false); _serviceCriticalFail++; } - if (!IsArrayNotEmpty(_serviceConfig.adjust_settings.events)) + if (!IsArrayNotEmpty(_servicesConfig.adjust_settings.events)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Adjust Events is missing!", false); @@ -285,7 +280,7 @@ namespace Guru.Editor //-------- IAP -------- passed = true; AddResultLine($"[ IAP ]"); - if (!IsArrayNotEmpty(_serviceConfig.products)) + if (!IsArrayNotEmpty(_servicesConfig.products)) { passed = false; AddResultLine($"{MARK_INDENT}{mk_no} Product list is missing!", false); @@ -347,7 +342,7 @@ namespace Guru.Editor GUI_WindowTitle(); // CONTENT - if (_serviceConfig == null) + if (_servicesConfig == null) { GUI_OnConfigDisabled(); } @@ -447,6 +442,8 @@ namespace Guru.Editor ApplyMods(); EditorUtility.DisplayCancelableProgressBar(barTitle, "All Mods is done", 0.8f); + EditorGuruServiceIO.DeployAppServiceFile(); // 部署文件 + AssetDatabase.SaveAssets(); CompilationPipeline.RequestScriptCompilation(); @@ -473,13 +470,13 @@ namespace Guru.Editor AssetDatabase.CreateAsset(settings, GURU_SETTINGS_PATH); } settings.CompanyName = "Guru"; - settings.ProductName = _serviceConfig.app_settings.product_name; - settings.GameIdentifier = _serviceConfig.app_settings.bundle_id; - settings.PriacyUrl = _serviceConfig.app_settings.privacy_url; - settings.TermsUrl = _serviceConfig.app_settings.terms_url; - settings.SupportEmail = _serviceConfig.app_settings.support_email; - settings.AndroidStoreUrl = _serviceConfig.app_settings.android_store; - settings.IOSStoreUrl = _serviceConfig.app_settings.ios_store; + settings.ProductName = _servicesConfig.app_settings.product_name; + settings.GameIdentifier = _servicesConfig.app_settings.bundle_id; + settings.PriacyUrl = _servicesConfig.app_settings.privacy_url; + settings.TermsUrl = _servicesConfig.app_settings.terms_url; + settings.SupportEmail = _servicesConfig.app_settings.support_email; + settings.AndroidStoreUrl = _servicesConfig.app_settings.android_store; + settings.IOSStoreUrl = _servicesConfig.app_settings.ios_store; SerializedObject so = new SerializedObject(settings); SerializedProperty n; @@ -491,10 +488,13 @@ namespace Guru.Editor if (null != n) { p = n.serializedObject.FindProperty("IPMSetting.appID"); - p.stringValue = _serviceConfig.app_settings.app_id; - - p = n.serializedObject.FindProperty("IPMSetting.tokenValidTime"); - p.intValue = _serviceConfig.app_settings.token_vaild_time; + p.stringValue = _servicesConfig.app_settings.app_id; + + if (_servicesConfig.app_settings.token_vaild_time > 0) + { + p = n.serializedObject.FindProperty("IPMSetting.tokenValidTime"); + p.intValue = _servicesConfig.app_settings.token_vaild_time; + } } //---------- AMAZON ----------------------- @@ -504,7 +504,7 @@ namespace Guru.Editor p = n.serializedObject.FindProperty("AmazonSetting.Enable"); p.boolValue = true; - arr = _serviceConfig.ad_settings.amazon_ids_android; + arr = _servicesConfig.ad_settings.amazon_ids_android; if (IsArrayHasLength(arr, 4)) { p = n.serializedObject.FindProperty("AmazonSetting.Android.appID"); @@ -517,7 +517,7 @@ namespace Guru.Editor p.stringValue = arr[3]; } - arr = _serviceConfig.ad_settings.amazon_ids_ios; + arr = _servicesConfig.ad_settings.amazon_ids_ios; if (IsArrayHasLength(arr, 4)) { p = n.serializedObject.FindProperty("AmazonSetting.iOS.appID"); @@ -538,7 +538,7 @@ namespace Guru.Editor p = n.serializedObject.FindProperty("PubmaticSetting.Enable"); p.boolValue = true; - arr = _serviceConfig.ad_settings.pubmatic_ids_android; + arr = _servicesConfig.ad_settings.pubmatic_ids_android; if (IsArrayHasLength(arr, 4)) { p = n.serializedObject.FindProperty("PubmaticSetting.Android.storeUrl"); @@ -551,7 +551,7 @@ namespace Guru.Editor p.stringValue = arr[3]; } - arr = _serviceConfig.ad_settings.pubmatic_ids_ios; + arr = _servicesConfig.ad_settings.pubmatic_ids_ios; if (IsArrayHasLength(arr, 4)) { p = n.serializedObject.FindProperty("PubmaticSetting.iOS.storeUrl"); @@ -572,7 +572,7 @@ namespace Guru.Editor p = n.serializedObject.FindProperty("MolocoSetting.Enable"); p.boolValue = true; - arr = _serviceConfig.ad_settings.moloco_ids_android; + arr = _servicesConfig.ad_settings.moloco_ids_android; if (IsArrayHasLength(arr, 3)) { p = n.serializedObject.FindProperty("MolocoSetting.Android.bannerTestUnitID"); @@ -583,7 +583,7 @@ namespace Guru.Editor p.stringValue = arr[2]; } - arr = _serviceConfig.ad_settings.moloco_ids_ios; + arr = _servicesConfig.ad_settings.moloco_ids_ios; if (IsArrayHasLength(arr, 3)) { p = n.serializedObject.FindProperty("MolocoSetting.iOS.bannerTestUnitID"); @@ -600,9 +600,9 @@ namespace Guru.Editor if (null != n) { p = n.serializedObject.FindProperty("ADSetting.SDK_KEY"); - p.stringValue = _serviceConfig.ad_settings.sdk_key; + p.stringValue = _servicesConfig.ad_settings.sdk_key; - arr = _serviceConfig.ad_settings.max_ids_android; + arr = _servicesConfig.ad_settings.max_ids_android; if(IsArrayHasLength(arr, 3)) { p = n.serializedObject.FindProperty("ADSetting.Android_Banner_ID"); @@ -613,7 +613,7 @@ namespace Guru.Editor p.stringValue = arr[2]; } - arr = _serviceConfig.ad_settings.max_ids_ios; + arr = _servicesConfig.ad_settings.max_ids_ios; if (IsArrayHasLength(arr, 3)) { p = n.serializedObject.FindProperty("ADSetting.IOS_Banner_ID"); @@ -628,13 +628,13 @@ namespace Guru.Editor //----------- AdjustSetting ------------------- n = so.FindProperty("AdjustSetting"); if (null != n - && IsArrayHasLength(_serviceConfig.adjust_settings.app_token, 2)) + && IsArrayHasLength(_servicesConfig.adjust_settings.app_token, 2)) { p = n.serializedObject.FindProperty("AdjustSetting.androidAppToken"); - p.stringValue = _serviceConfig.adjust_settings.app_token[0]; + p.stringValue = _servicesConfig.adjust_settings.app_token[0]; p = n.serializedObject.FindProperty("AdjustSetting.iOSAppToken"); - p.stringValue = _serviceConfig.adjust_settings.app_token[1]; + p.stringValue = _servicesConfig.adjust_settings.app_token[1]; } //----------- AnalyticsSetting ------------------- @@ -642,20 +642,20 @@ namespace Guru.Editor if (null != n) { p = n.serializedObject.FindProperty("AnalyticsSetting.levelEndSuccessNum"); - p.intValue = _serviceConfig.app_settings.level_end_success_num; + p.intValue = _servicesConfig.app_settings.level_end_success_num; p = n.serializedObject.FindProperty("AnalyticsSetting.enalbeFirebaseAnalytics"); - p.boolValue = _serviceConfig.app_settings.enable_firebase; + p.boolValue = _servicesConfig.app_settings.enable_firebase; p = n.serializedObject.FindProperty("AnalyticsSetting.enalbeFacebookAnalytics"); - p.boolValue = _serviceConfig.app_settings.enable_facebook; + p.boolValue = _servicesConfig.app_settings.enable_facebook; p = n.serializedObject.FindProperty("AnalyticsSetting.enalbeAdjustAnalytics"); - p.boolValue = _serviceConfig.app_settings.enable_adjust; + p.boolValue = _servicesConfig.app_settings.enable_adjust; p = n.serializedObject.FindProperty("AnalyticsSetting.adjustEventList"); - if (null != p && IsArrayNotEmpty(_serviceConfig.adjust_settings.events)) + if (null != p && IsArrayNotEmpty(_servicesConfig.adjust_settings.events)) { p.ClearArray(); - for (int i = 0; i < _serviceConfig.adjust_settings.events.Length; i++) + for (int i = 0; i < _servicesConfig.adjust_settings.events.Length; i++) { - arr = _serviceConfig.adjust_settings.events[i].Split(","); + arr = _servicesConfig.adjust_settings.events[i].Split(","); if (IsArrayHasLength(arr, 3)) { p.InsertArrayElementAtIndex(i); @@ -670,12 +670,12 @@ namespace Guru.Editor //---------------- Productions ------------------------ n = so.FindProperty("Products"); - if (n != null && IsArrayNotEmpty(_serviceConfig.products)) + if (n != null && IsArrayNotEmpty(_servicesConfig.products)) { n.ClearArray(); - for (int i = 0; i < _serviceConfig.products.Length; i++) + for (int i = 0; i < _servicesConfig.products.Length; i++) { - arr = _serviceConfig.products[i].Split(","); + arr = _servicesConfig.products[i].Split(","); if (IsArrayHasLength(arr, 5)) { n.InsertArrayElementAtIndex(i); @@ -715,11 +715,11 @@ namespace Guru.Editor settings.SetAttributionReportEndpoint = true; settings.QualityServiceEnabled = true; - settings.SdkKey = _serviceConfig.ad_settings.sdk_key; - if (IsArrayHasLength(_serviceConfig.ad_settings.admob_app_id, 2)) + settings.SdkKey = _servicesConfig.ad_settings.sdk_key; + if (IsArrayHasLength(_servicesConfig.ad_settings.admob_app_id, 2)) { - settings.AdMobAndroidAppId = _serviceConfig.ad_settings.admob_app_id[0]; - settings.AdMobIosAppId = _serviceConfig.ad_settings.admob_app_id[1]; + settings.AdMobAndroidAppId = _servicesConfig.ad_settings.admob_app_id[0]; + settings.AdMobIosAppId = _servicesConfig.ad_settings.admob_app_id[1]; } settings.ConsentFlowEnabled = false; EditorUtility.SetDirty(settings); @@ -748,7 +748,7 @@ namespace Guru.Editor { n.ClearArray(); n.InsertArrayElementAtIndex(0); - n.GetArrayElementAtIndex(0).stringValue = _serviceConfig.app_settings.product_name; + n.GetArrayElementAtIndex(0).stringValue = _servicesConfig.app_settings.product_name; } n = so.FindProperty("appIds"); @@ -756,7 +756,7 @@ namespace Guru.Editor { n.ClearArray(); n.InsertArrayElementAtIndex(0); - n.GetArrayElementAtIndex(0).stringValue = _serviceConfig.fb_settings.app_id; + n.GetArrayElementAtIndex(0).stringValue = _servicesConfig.fb_settings.app_id; } n = so.FindProperty("clientTokens"); @@ -764,7 +764,7 @@ namespace Guru.Editor { n.ClearArray(); n.InsertArrayElementAtIndex(0); - n.GetArrayElementAtIndex(0).stringValue = _serviceConfig.fb_settings.client_token; + n.GetArrayElementAtIndex(0).stringValue = _servicesConfig.fb_settings.client_token; } n = so.FindProperty("androidKeystorePath"); @@ -777,7 +777,7 @@ namespace Guru.Editor private void ApplyMods() { - PlayerSettings.applicationIdentifier = _serviceConfig.app_settings.bundle_id; // 设置包名 + PlayerSettings.applicationIdentifier = _servicesConfig.app_settings.bundle_id; // 设置包名 #if UNITY_ANDROID AndroidManifestMod.Apply(); @@ -808,11 +808,6 @@ namespace Guru.Editor } private void GUI_Button(string label, Action content, GUIStyle style = null, params GUILayoutOption[] options) { - - - - - if (style != null) { if (GUILayout.Button(label,style, options)) @@ -827,8 +822,6 @@ namespace Guru.Editor content?.Invoke(); } } - - } diff --git a/Runtime/Code/Core/GuruServiceConfig.cs b/Runtime/Code/Config/GuruServicesConfig.cs similarity index 90% rename from Runtime/Code/Core/GuruServiceConfig.cs rename to Runtime/Code/Config/GuruServicesConfig.cs index d9dde6e..8db4f1a 100644 --- a/Runtime/Code/Core/GuruServiceConfig.cs +++ b/Runtime/Code/Config/GuruServicesConfig.cs @@ -6,9 +6,9 @@ namespace Guru { [Serializable] - public class GuruServiceConfig + public class GuruServicesConfig { - public string version; + public long version = 0; public GuruAppSettings app_settings; public GuruAdjustSettings adjust_settings; public GuruFbSettings fb_settings; @@ -37,8 +37,6 @@ namespace Guru ad_settings.moloco_ids_ios != null && ad_settings.moloco_ids_ios.Length > 0; //-------------------------------- 配置检测 -------------------------------- - - } [Serializable] @@ -54,10 +52,11 @@ namespace Guru public string ios_store; public int token_vaild_time = 604800; public int level_end_success_num = 50; + public bool use_keywords = true; public bool enable_firebase = true; public bool enable_facebook = true; public bool enable_adjust = true; - public bool enable_iap = false; + public bool enable_iap = true; } [Serializable] @@ -65,6 +64,9 @@ namespace Guru { public string[] app_token; public string[] events; + + public string AndroidToken => app_token != null && app_token.Length > 0 ? app_token[0] : ""; + public string iOSToken => app_token != null && app_token.Length > 1 ? app_token[1] : ""; } [Serializable] diff --git a/Runtime/Code/Core/GuruServiceConfig.cs.meta b/Runtime/Code/Config/GuruServicesConfig.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruServiceConfig.cs.meta rename to Runtime/Code/Config/GuruServicesConfig.cs.meta diff --git a/Runtime/Code/Core/GuruSDK.Callback.cs b/Runtime/Code/Core/GuruSDK.Callback.cs index 88714e5..3bf14e5 100644 --- a/Runtime/Code/Core/GuruSDK.Callback.cs +++ b/Runtime/Code/Core/GuruSDK.Callback.cs @@ -13,7 +13,26 @@ namespace Guru /// public class Callbacks { - + /// + /// APP 事件 + /// + public static class App + { + internal static Action _onAppPaused; + public static event Action OnAppPaused + { + add => _onAppPaused += value; + remove => _onAppPaused -= value; + } + + internal static Action _onAppQuit; + public static event Action OnAppQuit + { + add => _onAppQuit += value; + remove => _onAppQuit -= value; + } + } + /// /// GDPR Consent @@ -83,17 +102,29 @@ namespace Guru } } - + /// + /// 云控参数 + /// public static class Remote { internal static Action _onRemoteInitComplete; - public static event Action OnRemoteInitComplete; - - internal static Action _onRemoteFetchComplete; - public static event Action OnRemoteFetchComplete; + public static event Action OnRemoteInitComplete + { + add => _onRemoteInitComplete += value; + remove => _onRemoteInitComplete -= value; + } + + internal static Action _onRemoteFetchComplete; + public static event Action OnRemoteFetchComplete + { + add => _onRemoteFetchComplete += value; + remove => _onRemoteFetchComplete -= value; + } } - + /// + /// 支付回调 + /// public static class IAP { internal static Action _onIAPInitComplete; diff --git a/Runtime/Code/Core/GuruSDK.Remote.cs b/Runtime/Code/Core/GuruSDK.Remote.cs new file mode 100644 index 0000000..a4b6bdc --- /dev/null +++ b/Runtime/Code/Core/GuruSDK.Remote.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using Firebase.RemoteConfig; + +namespace Guru +{ + public partial class GuruSDK + { + + public static void FetchAllRemote(bool immediately = false) => RemoteConfigManager.FetchAll(immediately); + + /// + /// 注册云控配置 + /// + /// + /// + /// + public static void RegisterRemoteConfig(string key, string defaultValue) + { + RemoteConfigManager.RegisterConfig(key, defaultValue); + } + + /// + /// 获取运控配置 + /// + /// + /// + /// + public static T GetRemoteConfig(string key) where T : IRemoteConfig + { + return RemoteConfigManager.GetConfig(key); + } + public static string GetRemoteString(string key) => RemoteConfigManager.GetString(key); + public static int GetRemoteInt(string key) => RemoteConfigManager.GetInt(key); + public static long GetRemoteLong(string key) => RemoteConfigManager.GetLong(key); + public static double GetRemoteDouble(string key) => RemoteConfigManager.GetDouble(key); + public static float GetRemoteFloat(string key) => RemoteConfigManager.GetFloat(key); + public static bool GetRemoteBool(string key) => RemoteConfigManager.GetBool(key); + + + public static void RegisterOnValueChanged(string key, Action onValueChanged) + { + RemoteConfigManager.RegisterOnValueChanged(key, onValueChanged); + } + + public static void UnRegisterOnValueChanged(string key, Action onValueChanged) + { + RemoteConfigManager.UnRegisterOnValueChanged(key, onValueChanged); + } + + public static Dictionary GetRemoteAllValues() => RemoteConfigManager.GetAllValues(); + + + public static string GetRemoteStaticValue(string key) => RemoteConfigManager.GetStaticValue(key); + + } +} \ No newline at end of file diff --git a/Runtime/Code/Core/GuruSDK.Remote.cs.meta b/Runtime/Code/Core/GuruSDK.Remote.cs.meta new file mode 100644 index 0000000..2b761ed --- /dev/null +++ b/Runtime/Code/Core/GuruSDK.Remote.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e4344f1c04b64ca98a66081bbcb696aa +timeCreated: 1703588862 \ No newline at end of file diff --git a/Runtime/Code/Core/GuruSDK.cs b/Runtime/Code/Core/GuruSDK.cs index d12620c..0a9d701 100644 --- a/Runtime/Code/Core/GuruSDK.cs +++ b/Runtime/Code/Core/GuruSDK.cs @@ -1,12 +1,18 @@ +using System.Collections; + namespace Guru { using UnityEngine; using System; + using System.Collections.Generic; + using System.IO; public partial class GuruSDK: MonoBehaviour { public const string Version = "0.1.0"; - public static readonly string Tag = "[Guru]"; + public const string Tag = "[Guru]"; + public const string ServicesConfigKey = "guru_services"; + public const string ServicesConfigExtension = "cfg"; private static GuruSDK _instance; /// @@ -32,8 +38,8 @@ namespace Guru internal static GuruSDKInitConfig InitConfig => Instance._initConfig; internal static GuruSDKModel Model => GuruSDKModel.Instance; - - + private static GuruServicesConfig _appServicesConfig; + /// /// Debug Mode /// @@ -49,7 +55,8 @@ namespace Guru } #region 初始化 - + + private static GuruSDK CreateInstance() { @@ -59,6 +66,20 @@ namespace Guru return _instance; } + public static GuruSDKInitConfig BuildConfig( + bool useCustomConsent = false, + bool autoLoadAds = true, + bool iapEnabled = true, + bool autoRecordFinishedLevels = true, + bool showDebugLog = false, + Dictionary defaultRemoteData = null, + byte[] googleKeys = null, + byte[] appleRootCerts = null) + { + var config = GuruSDKInitConfig.Build(useCustomConsent, autoLoadAds, iapEnabled, + autoRecordFinishedLevels, showDebugLog, defaultRemoteData, googleKeys, appleRootCerts); + return config; + } public static void Init(Action onComplete) { @@ -88,40 +109,119 @@ namespace Guru //---------- Start Firebase ------------ FirebaseUtil.InitFirebase(OnFirebaseReady); - FirebaseUtil.OnFetchRemoteSuccess += OnFetchRemoteSuccess; + // FirebaseUtil.OnFetchRemoteSuccess+= OnFetchRemoteCallback; //---------- Start Facebook ------------ FBService.Instance.StartService(); } - private void OnFetchRemoteSuccess() - { - Callbacks.Remote._onRemoteFetchComplete?.Invoke(); - } + /// /// 开始各种组件初始化 /// private void OnFirebaseReady() { - LogI($"--- #1 SDK Init complete ---"); + LogI($"--- Firebase complete ---"); if (InitConfig.IAPEnabled) { - LogI($"--- #2 Init IAP ---"); + // LogI($"--- #2 Init IAP ---"); InitIAP(_initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP } if (!InitConfig.UseCustomConsent) { - LogI($"--- #3 Start Consent Flow ---"); + // LogI($"--- #3 Start Consent Flow ---"); StartConsentFlow(); } - //TODO: 开始Remote初始化 + // 开始Remote Manager初始化 + RemoteConfigManager.Init(BuildDefaultRemoteData(_initConfig.DefaultRemoteData)); + RemoteConfigManager.OnFetchCompleted += OnFetchRemoteCallback; if(!string.IsNullOrEmpty(IPMConfig.IPM_UID)) SetUID(IPMConfig.IPM_UID); + // 根据上次的云控配置来初始化参数 + SetupServicesConfig(); + _onCompleteCallback?.Invoke(true); } + + /// + /// 注入云控参数基础数据 + /// + /// + /// + private Dictionary BuildDefaultRemoteData(Dictionary dict) + { + string json = Model.LoadAppServicesConfigJson(); // 注入默认的Services 配置值 + if (!string.IsNullOrEmpty(json)) + { + if (dict == null) dict = new Dictionary(3); + dict[ServicesConfigKey] = json; + return dict; + } + return null; + } + + /// + /// 拉取云控参数完成 + /// + /// + 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() + { + bool useKeywords = true; + var guruSettings = GuruSettings.Instance; + + var services = GetRemoteServicesConfig(); + if (services != null) + { + _appServicesConfig = services; + useKeywords = _appServicesConfig.app_settings.use_keywords; + + + if (null != guruSettings) + { + if(_appServicesConfig.adjust_settings != null) + { + // 更新 Adjust Tokens + guruSettings.UpdateAdjustTokens(_appServicesConfig.adjust_settings.AndroidToken + ,_appServicesConfig.adjust_settings.iOSToken); + // 更新 Adjust Events + guruSettings.UpdateAdjustEvents(_appServicesConfig.adjust_settings.events); + } + } + + } + + if(useKeywords) KeywordsManager.Install(Model.IsIAPUser, Model.SuccessLevelCount); // 启动Keyword管理器 + + AdjustService.StartService(); + } + + + private GuruServicesConfig GetRemoteServicesConfig() + { + var json = GetRemoteString(ServicesConfigKey); + if (!string.IsNullOrEmpty(json)) + { + return JsonParser.ToObject(json); + } + return null; + } + #endregion + + #region 数据 private void OnBLevelChanged(int blevel) { @@ -133,10 +233,8 @@ namespace Guru SetUserBPlay(bplay); } - - #endregion - + #region Misc /// @@ -169,7 +267,92 @@ namespace Guru Debug.LogError($"{Tag} {message}"); } - #endregion + public static void LogException(string message) + { + LogException( new Exception($"{Tag} {message}")); + } + + public static void LogException(Exception e) + { + Debug.LogException(e); + } + + #endregion + + #region 生命周期 + + /// + /// 暂停时处理 + /// + /// + private void OnAppPauseHandler(bool paused) + { + if(paused) Model.Save(true); // 强制保存数据 + Callbacks.App._onAppPaused?.Invoke(paused); + } + + 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 延迟处理 + + /// + /// 启动协程 + /// + /// + /// + 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); + } + + + /// + /// 延时执行 + /// + /// + /// + 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(); + } + + + #endregion } } \ No newline at end of file diff --git a/Runtime/Code/IAP/GuruIAP.cs b/Runtime/Code/IAP/GuruIAP.cs index b7f2d27..7e5ec52 100644 --- a/Runtime/Code/IAP/GuruIAP.cs +++ b/Runtime/Code/IAP/GuruIAP.cs @@ -3,6 +3,8 @@ namespace Guru internal class GuruIAP: IAPServiceBase { + + /// /// 获取BLevel /// diff --git a/Runtime/Code/Model/GuruSDKModel.cs b/Runtime/Code/Model/GuruSDKModel.cs index cc8bcc4..b6c0d6c 100644 --- a/Runtime/Code/Model/GuruSDKModel.cs +++ b/Runtime/Code/Model/GuruSDKModel.cs @@ -1,12 +1,18 @@ -using System; -using UnityEngine; -using UnityEngine.Serialization; namespace Guru { + using System; + using UnityEngine; + using System.IO; + + [Serializable] internal class GuruSDKModel { + private const float SaveInterval = 3; + private const string SaveKey = "com.guru.sdk.model.save"; + + private static GuruSDKModel _instance; public static GuruSDKModel Instance { @@ -69,8 +75,7 @@ namespace Guru #region 初始化 - private const float SaveInterval = 3; - private const string SaveKey = "com.guru.sdk.model.save"; + public static GuruSDKModel Load() { GuruSDKModel model = null; @@ -146,7 +151,27 @@ namespace Guru } #endregion + #region 启动配置 + + /// + /// 从 Streaming 加载 AppServices 配置 + /// + /// + public string LoadAppServicesConfigJson() + { + try + { + string path = Path.Combine(Application.streamingAssetsPath, $"{GuruSDK.ServicesConfigKey}.{GuruSDK.ServicesConfigExtension}"); + return File.ReadAllText(path); + } + catch (Exception e) + { + Log.Exception(e); + } + return ""; + } + #endregion diff --git a/Runtime/Prefab.meta b/Runtime/Prefab.meta deleted file mode 100644 index 7d802c8..0000000 --- a/Runtime/Prefab.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: fc679813f31644f20b79c6f24939c6a9 -timeCreated: 1702611035 \ No newline at end of file diff --git a/package.json b/package.json index ad458f4..3551d61 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,5 @@ "license": "MIT", "category": "Game,Tool,Development", "dependencies": { - "com.guru.unity.sdk.core": "git@git.chengdu.pundit.company:castbox/com.guru.unity.sdk.core.git" } } \ No newline at end of file