From 42c7302ea364bc9d45383dab7fa61213ef114532 Mon Sep 17 00:00:00 2001 From: huyufei Date: Wed, 31 Jul 2024 12:56:01 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=20GuruSDK=20=E5=9B=9E=E8=B0=83?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=8C=20codereview?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Code/Config/GuruSDKInitConfig.cs | 8 +- Runtime/Code/SDK/GuruSDK.Ads.cs | 57 +++--- Runtime/Code/SDK/GuruSDK.Analytics.cs | 212 ++++++++-------------- Runtime/Code/SDK/GuruSDK.Callbacks.cs | 222 ++++++++++++++++------- Runtime/Code/SDK/GuruSDK.Const.cs | 17 ++ Runtime/Code/SDK/GuruSDK.Debugger.cs | 18 +- Runtime/Code/SDK/GuruSDK.IAP.cs | 23 ++- Runtime/Code/SDK/GuruSDK.cs | 151 ++++++--------- 8 files changed, 354 insertions(+), 354 deletions(-) diff --git a/Runtime/Code/Config/GuruSDKInitConfig.cs b/Runtime/Code/Config/GuruSDKInitConfig.cs index cfc2f47..24c8300 100644 --- a/Runtime/Code/Config/GuruSDKInitConfig.cs +++ b/Runtime/Code/Config/GuruSDKInitConfig.cs @@ -2,6 +2,8 @@ namespace Guru { using System.Collections.Generic; using System.Text; + using System; + /// /// 启动参数配置 /// @@ -55,7 +57,7 @@ namespace Guru /// /// 启用 AdjustDeeplink /// - public bool UseAdjustDeeplink = false; + public Action OnAdjustDeeplinkCallback = null; /// /// 支付初始化Keys @@ -77,7 +79,7 @@ namespace Guru bool isBuyNoAds = false, string bannerBackgroundColor = "#00000000", bool debugMode = false, - bool useAdjustDeeplink = false, + Action onAdjustDeeplinkCallback = null, Dictionary defaultRemoteData = null, byte[] googleKeys = null, byte[] appleRootCerts = null, @@ -93,7 +95,7 @@ namespace Guru IsBuyNoAds = isBuyNoAds, BannerBackgroundColor = bannerBackgroundColor, DebugMode = debugMode, - UseAdjustDeeplink = useAdjustDeeplink, + OnAdjustDeeplinkCallback = onAdjustDeeplinkCallback, GoogleKeys = googleKeys, AppleRootCerts = appleRootCerts, DefaultRemoteData = defaultRemoteData ?? new Dictionary(), diff --git a/Runtime/Code/SDK/GuruSDK.Ads.cs b/Runtime/Code/SDK/GuruSDK.Ads.cs index 53995e8..b4f10d5 100644 --- a/Runtime/Code/SDK/GuruSDK.Ads.cs +++ b/Runtime/Code/SDK/GuruSDK.Ads.cs @@ -128,7 +128,7 @@ namespace Guru AdServiceHandler(); // 调用回调 - Callbacks.ConsentFlow._onConsentResult?.Invoke(code); + Callbacks.ConsentFlow.InvokeOnConsentResult(code); #if UNITY_IOS CheckAttStatus(); // [iOS] Consent 启动后检查 ATT 初始值 @@ -240,7 +240,7 @@ namespace Guru /// private void InitNotiPermission() { - bool hasNotiGranted = false; + // bool hasNotiGranted = false; _notiStatue = "no_determined"; NotificationService.Initialize(); // 初始化 Noti 服务 SetNotiPerm(NotificationService.GetStatus()); @@ -256,15 +256,15 @@ namespace Guru // 如果未启用自动 Noti 授权,则直接上报状态 if (!_initConfig.AutoNotificationPermission) { - UnityEngine.Debug.LogWarning($"[SDK] ---- AutoNotificationPermission is OFF, Project should request permission own."); + Debug.LogWarning($"[SDK] ---- AutoNotificationPermission is OFF, Project should request permission own."); return; } bool isGranted = NotificationService.IsPermissionGranted(); - UnityEngine.Debug.Log($"[SDK] ---- Check Noti Permission: {isGranted}"); + Debug.Log($"[SDK] ---- Check Noti Permission: {isGranted}"); if (isGranted) { - UnityEngine.Debug.Log($"[SDK] ---- Set Notification Permission: {status}"); + Debug.Log($"[SDK] ---- Set Notification Permission: {status}"); SetNotiPerm(status); return; } @@ -280,10 +280,10 @@ namespace Guru { FirebaseUtil.StartFetchFcmToken(); - UnityEngine.Debug.Log($"[SDK] ---- RequestNotificationPermission"); + Debug.Log($"[SDK] ---- RequestNotificationPermission"); NotificationService.RequestPermission(status => { - UnityEngine.Debug.Log($"[SDK] ---- Set Notification Permission: {status}"); + Debug.Log($"[SDK] ---- Set Notification Permission: {status}"); if(!string.IsNullOrEmpty(status)) SetNotiPerm(status); callback?.Invoke(status); @@ -313,7 +313,6 @@ namespace Guru #region Ad Services private static bool _initAdsCompleted = false; - private static bool _isBannerVisible = false; public static bool IsAdsReady => _initAdsCompleted; private static int _preBannerAction = 0; @@ -347,18 +346,18 @@ namespace Guru //--------- Add Callbacks ----------- // BADS - ADService.OnBannerStartLoad = OnBannerStartLoad; - ADService.OnBannerLoaded = OnBannerLoaded; + ADService.Instance.OnBannerStartLoad = OnBannerStartLoad; + ADService.Instance.OnBannerLoaded = OnBannerLoaded; // IADS - ADService.OnInterstitialStartLoad = OnInterstitialStartLoad; - ADService.OnInterstitialLoaded = OnInterstitialLoaded; - ADService.OnInterstitialFailed = OnInterstitialFailed; - ADService.OnInterstitialClosed = OnInterstitialClosed; + ADService.Instance.OnInterstitialStartLoad = OnInterstitialStartLoad; + ADService.Instance.OnInterstitialLoaded = OnInterstitialLoaded; + ADService.Instance.OnInterstitialFailed = OnInterstitialFailed; + ADService.Instance.OnInterstitialClosed = OnInterstitialClosed; // RADS - ADService.OnRewardedStartLoad = OnRewardStartLoad; - ADService.OnRewardLoaded = OnRewardLoaded; - ADService.OnRewardFailed = OnRewardFailed; - ADService.OnRewardClosed = OnRewardClosed; + ADService.Instance.OnRewardedStartLoad = OnRewardStartLoad; + ADService.Instance.OnRewardLoaded = OnRewardLoaded; + ADService.Instance.OnRewardFailed = OnRewardFailed; + ADService.Instance.OnRewardClosed = OnRewardClosed; // ---------- Start Services ---------- ADService.Instance.StartService(OnAdsInitComplete, spec); @@ -378,25 +377,25 @@ namespace Guru } private static void OnBannerStartLoad(string adUnitId) - => Callbacks.Ads._onBannerADStartLoad?.Invoke(adUnitId); + => Callbacks.Ads.InvokeOnBannerADStartLoad(adUnitId); private static void OnBannerLoaded() - => Callbacks.Ads._onBannerADLoaded?.Invoke(); + => Callbacks.Ads.InvokeOnBannerADLoaded(); private static void OnInterstitialStartLoad(string adUnitId) - => Callbacks.Ads._onInterstitialADStartLoad?.Invoke(adUnitId); + => Callbacks.Ads.InvokeOnInterstitialADStartLoad(adUnitId); private static void OnInterstitialLoaded() - => Callbacks.Ads._onInterstitialADLoaded?.Invoke(); + => Callbacks.Ads.InvokeOnInterstitialADLoaded(); private static void OnInterstitialFailed() - => Callbacks.Ads._onInterstitialADFailed?.Invoke(); + => Callbacks.Ads.InvokeOnInterstitialADFailed(); private static void OnInterstitialClosed() - => Callbacks.Ads._onInterstitialADClosed?.Invoke(); + => Callbacks.Ads.InvokeOnInterstitialADClosed(); private static void OnRewardStartLoad(string adUnitId) - => Callbacks.Ads._onRewardedADStartLoad?.Invoke(adUnitId); + => Callbacks.Ads.InvokeOnRewardedADStartLoad(adUnitId); private static void OnRewardLoaded() - => Callbacks.Ads._onRewardedADLoaded?.Invoke(); + => Callbacks.Ads.InvokeOnRewardedADLoaded(); private static void OnRewardFailed() - => Callbacks.Ads._onRewardADFailed?.Invoke(); + => Callbacks.Ads.InvokeOnRewardADFailed(); private static void OnRewardClosed() - => Callbacks.Ads._onRewardADClosed?.Invoke(); + => Callbacks.Ads.InvokeOnRewardADClosed(); private static void OnAdsInitComplete() { @@ -416,7 +415,7 @@ namespace Guru HideBanner(); } } - Callbacks.Ads._onAdsInitComplete?.Invoke(); + Callbacks.Ads.InvokeOnAdsInitComplete(); } private static bool CheckAdsReady() diff --git a/Runtime/Code/SDK/GuruSDK.Analytics.cs b/Runtime/Code/SDK/GuruSDK.Analytics.cs index e4535e5..8e93acd 100644 --- a/Runtime/Code/SDK/GuruSDK.Analytics.cs +++ b/Runtime/Code/SDK/GuruSDK.Analytics.cs @@ -1,39 +1,16 @@ - - - - namespace Guru { using System; using System.Collections.Generic; using UnityEngine; - using System.Linq; /// /// 打点管理 /// public partial class GuruSDK { - /// - /// 主线关卡类型 - /// 只有传入此类型时才会进行 Blevel 的累加 - /// - public const string LevelTypeMain = "main"; - //----------------- 关卡开始类型 --------------------- - public const string EventLevelStartModePlay = "play"; - public const string EventLevelStartModeReplay = "replay"; - public const string EventLevelStartModeContinue= "continue"; - - //----------------- 关卡结束类型 --------------------- - public const string EventLevelEndSuccess = "success"; - public const string EventLevelEndFail = "fail"; - public const string EventLevelEndExit = "exit"; - public const string EventLevelEndTimeout = "timeout"; - - private const string KeyCachedScreen = "k_cached_screen"; - #region 通用接口 /// @@ -79,13 +56,13 @@ namespace Guru /// 关卡开始类型: play:开始游戏;replay:重玩;continue:继续游戏 /// 是否重新开始: true/false /// 扩展数据 - public static void LogLevelStart(int levelId, string startType = EventLevelStartModePlay, - string levelType = LevelTypeMain, string levelName = "", string itemId = "", + public static void LogLevelStart(int levelId, string startType = Consts.EventLevelStartModePlay, + string levelType = Consts.LevelTypeMain, string levelName = "", string itemId = "", bool isReplay = false, Dictionary extra = null) { if (!IsInitialSuccess) { - UnityEngine.Debug.LogError($"{Tag} :: LogLevelStart {levelId} :: Please call first, before you call ."); + Debug.LogError($"{Tag} :: LogLevelStart {levelId} :: Please call first, before you call ."); return; } @@ -100,10 +77,10 @@ namespace Guru /// /// /// - public static void LogLevelContinue(int levelId, string levelType = LevelTypeMain, + public static void LogLevelContinue(int levelId, string levelType = Consts.LevelTypeMain, string levelName = "", string itemId = "", Dictionary extra = null) { - LogLevelStart(levelId, EventLevelStartModeContinue, levelType, levelName, itemId, true, extra:extra); + LogLevelStart(levelId, Consts.EventLevelStartModeContinue, levelType, levelName, itemId, true, extra:extra); } /// @@ -113,10 +90,10 @@ namespace Guru /// /// /// - public static void LogLevelReplay(int levelId, string levelType = LevelTypeMain, + public static void LogLevelReplay(int levelId, string levelType = Consts.LevelTypeMain, string levelName = "", string itemId = "", Dictionary extra = null) { - LogLevelStart(levelId, EventLevelStartModeReplay,levelType, levelName, itemId, true, extra:extra); + LogLevelStart(levelId, Consts.EventLevelStartModeReplay,levelType, levelName, itemId, true, extra:extra); } /// @@ -131,13 +108,13 @@ namespace Guru /// 步数(有则上报) /// 分数(有则上报) /// 扩展数据 - public static void LogLevelEnd(int levelId, string result = EventLevelEndSuccess, - string levelType = LevelTypeMain, string levelName = "", string itemId = "", + public static void LogLevelEnd(int levelId, string result = Consts.EventLevelEndSuccess, + string levelType = Consts.LevelTypeMain, string levelName = "", string itemId = "", int duration = 0, int? step = null, int? score = null, Dictionary extra = null) { if (!IsInitialSuccess) { - UnityEngine.Debug.LogError( + Debug.LogError( $"{Tag} :: LogLevelEnd {levelId} :: Please call first, before you call ."); return; } @@ -147,9 +124,9 @@ namespace Guru // 自动记录关卡属性 if (InitConfig.AutoRecordFinishedLevels) { - if (result == EventLevelEndSuccess) + if (result == Consts.EventLevelEndSuccess) { - if (levelType == LevelTypeMain) + if (levelType == Consts.LevelTypeMain) { if (levelId > Model.SuccessLevelId) Model.SuccessLevelId = levelId; // 自动记录关卡完成次数 } @@ -175,7 +152,7 @@ namespace Guru /// /// public static void LogLevelFirstEnd(string levelType, string levelName, int level, - string result = EventLevelEndSuccess, int duration = 0, Dictionary extra = null) + string result = Consts.EventLevelEndSuccess, int duration = 0, Dictionary extra = null) { Analytics.LevelFirstEnd(levelType, levelName, level, result, duration, extra); } @@ -203,10 +180,10 @@ namespace Guru /// /// public static void LogLevelFail(int levelId, - string levelType = LevelTypeMain, string levelName = "", string itemId = "", + string levelType = Consts.LevelTypeMain, string levelName = "", string itemId = "", int duration = 0, int? step = null, int? score = null , Dictionary extra = null) { - LogLevelEnd(levelId, EventLevelEndFail, levelType, levelName, itemId, duration, step, score, extra); + LogLevelEnd(levelId, Consts.EventLevelEndFail, levelType, levelName, itemId, duration, step, score, extra); } /// @@ -221,10 +198,10 @@ namespace Guru /// /// public static void LogLevelFailExit(int levelId, - string levelType = LevelTypeMain, string levelName = "", string itemId = "", + string levelType = Consts.LevelTypeMain, string levelName = "", string itemId = "", int duration = 0, int? step = null, int? score = null, Dictionary extra = null) { - LogLevelEnd(levelId, EventLevelEndExit, levelType, levelName, itemId, duration, step, score, extra); + LogLevelEnd(levelId, Consts.EventLevelEndExit, levelType, levelName, itemId, duration, step, score, extra); } /// @@ -239,10 +216,10 @@ namespace Guru /// /// public static void LogLevelFailTimeout(int levelId, - string levelType = LevelTypeMain, string levelName = "", string itemId = "", + string levelType = Consts.LevelTypeMain, string levelName = "", string itemId = "", int duration = 0, int? step = null, int? score = null, Dictionary extra = null) { - LogLevelEnd(levelId, EventLevelEndTimeout, levelType, levelName, itemId, duration, step, score, extra); + LogLevelEnd(levelId, Consts.EventLevelEndTimeout, levelType, levelName, itemId, duration, step, score, extra); } @@ -256,7 +233,7 @@ namespace Guru { if (!IsInitialSuccess) { - UnityEngine.Debug.LogError($"{Tag} :: LogLevelUp {playerLevel} :: Please call first, before you call ."); + Debug.LogError($"{Tag} :: LogLevelUp {playerLevel} :: Please call first, before you call ."); return; } Analytics.LevelUp(playerLevel, characterName, extra); @@ -271,7 +248,7 @@ namespace Guru { if (!IsInitialSuccess) { - UnityEngine.Debug.LogError($"{Tag} :: LogAchievement {achievementId} :: Please call first, before you call ."); + Debug.LogError($"{Tag} :: LogAchievement {achievementId} :: Please call first, before you call ."); return; } Analytics.UnlockAchievement(achievementId, extra); @@ -326,7 +303,7 @@ namespace Guru { if (!IsInitialSuccess) { - UnityEngine.Debug.LogError($"{Tag} :: InitUserProperties :: Please call first, before you call ."); + Debug.LogError($"{Tag} :: InitUserProperties :: Please call first, before you call ."); return; } @@ -339,31 +316,6 @@ namespace Guru if (Model.IsNoAds) SetBuyNoAds(true); // 设置用户已经购买了去广告 } - private static Dictionary _userPropertyCacheData = new Dictionary(10); - private static HashSet _userPropertyExistKeys = new HashSet(); - - private static void RecordUserPropertyKey(string key) - { - if(_userPropertyExistKeys == null) - _userPropertyExistKeys = new HashSet(); - - if(!HasUserPropertyKey(key)) _userPropertyExistKeys.Add(key); - } - - private static bool HasUserPropertyKey(string key) - { - return _userPropertyExistKeys?.Contains(key) ?? false; - } - - private static void CacheUserProperty(string key, string value) - { - if (_userPropertyCacheData == null) _userPropertyCacheData = new Dictionary(10); - _userPropertyCacheData[key] = value; - } - - - - /// /// 设置用户属性 /// @@ -371,7 +323,6 @@ namespace Guru /// public static void SetUserProperty(string key, string value) { - RecordUserPropertyKey(key); // 记录属性打点 Analytics.SetUserProperty(key, value); } @@ -421,7 +372,7 @@ namespace Guru /// /// 上报用户付费金币的 数量 (累加值) /// - /// + /// public static void SetUserIapCoin(int paidCoins) { SetUserProperty(Consts.PropertyIAPCoin, $"{paidCoins}"); @@ -472,62 +423,41 @@ namespace Guru SetUserProperty(Consts.PropertyNetwork, Instance.GetNetworkStatus()); } + private static bool _hasUserPropertiesInitiallyUpdated = false; /// - /// 初始化时调用一下所有的属性打点
+ /// 初始化时补全一下所有的属性打点 + /// 如果用户已经设置过 Key, 则不会再次设置 /// 用户属性文档 ///
- private static void UpdateAllUserProperties() + private static void InitiallyUpdateUserProperties() { - if(!HasUserPropertyKey(Consts.PropertyFirstOpenTime)) - SetFirstOpenTime(TimeUtil.GetCurrentTimeStamp().ToString()); // first_open_time + if (_hasUserPropertiesInitiallyUpdated) return; + _hasUserPropertiesInitiallyUpdated = true; - if(!HasUserPropertyKey(Consts.PropertyIsIAPUser)) - SetUserIsIAP(Model?.IsIapUser ?? false); // is_iap_user - - if (!HasUserPropertyKey(Consts.PropertyLevel)) - SetUserBLevel(Model?.SuccessLevelId ?? 0); // b_level + SetFirstOpenTime(TimeUtil.GetCurrentTimeStamp().ToString()); // first_open_time + SetUserIsIAP(Model?.IsIapUser ?? false); // is_iap_user + SetUserBLevel(Model?.SuccessLevelId ?? 0); // b_level + SetUserBLevel(Model?.TotalPlayedCount ?? 0); // b_play + SetUserProperty(Consts.PropertyDeviceID, DeviceId); // device_id + + SetUserIapCoin(0); // iap_coin + SetUserNonIapCoin(0); // non_iap_coin + SetUserCoin(0);// coin + SetUserGrade(0); // grade + SetUserExp(0); // exp + SetUserHp(0); // hp - if (!HasUserPropertyKey(Consts.PropertyPlay)) - SetUserBLevel(Model?.TotalPlayedCount ?? 0); // b_play + if(!string.IsNullOrEmpty(UID)) + SetUID(UID); // user_id - if(!HasUserPropertyKey(Consts.PropertyUserID)) - SetUserProperty(Consts.PropertyUserID, UID); // user_id - - if(!HasUserPropertyKey(Consts.PropertyDeviceID)) - SetUserProperty(Consts.PropertyDeviceID, DeviceId); // device_id - - if(!HasUserPropertyKey(Consts.PropertyIAPCoin)) - SetUserIapCoin(0); // iap_coin - - if(!HasUserPropertyKey(Consts.PropertyNonIAPCoin)) - SetUserNonIapCoin(0); // non_iap_coin - - if(!HasUserPropertyKey(Consts.PropertyCoin)) - SetUserCoin(0);// coin - - if (!HasUserPropertyKey(Consts.PropertyGrade)) - SetUserGrade(0); // grade - - if(!HasUserPropertyKey(Consts.PropertyExp)) - SetUserExp(0); // exp - - if(!HasUserPropertyKey(Consts.PropertyHp)) - SetUserHp(0); // hp - #if UNITY_IOS - if(!HasUserPropertyKey(Consts.PropertyATTStatus)) - SetATTStatus("notDetermined"); // att_status + SetATTStatus("notDetermined"); // att_status #endif - - if(!HasUserPropertyKey(Consts.PropertyNotiPerm)) - SetNotiPerm("not_determined"); // noti_perm - - if(!HasUserPropertyKey(Consts.PropertyNetwork)) - SetNetworkStatus(); // NetworkStatus + SetNotiPerm("not_determined"); // noti_perm + SetNetworkStatus(); // NetworkStatus } - #endregion #region SDK 打点 @@ -581,7 +511,7 @@ namespace Guru /// 当付费页面打开时调用 (iap_imp) ///
/// 付费页场景名称 - /// 列表中首个商品的 ProductId + /// public static void LogIAPImp(string scene, Dictionary extra = null) { Analytics.IAPImp(scene, extra); @@ -591,7 +521,7 @@ namespace Guru /// 当付费页面关闭时调用 (iap_close) ///
/// - /// + /// public static void LogIAPClose(string scene, Dictionary extra = null) { Analytics.IAPClose(scene, extra); @@ -602,7 +532,9 @@ namespace Guru ///
/// /// + /// /// + /// public static void LogIAPClick(string scene, string productId, string basePlan = "", string offerId = "", Dictionary extra = null) { Analytics.IAPClick(scene, productId, basePlan, offerId, extra); @@ -727,6 +659,7 @@ namespace Guru /// 当前关卡名称 /// 应用场景 /// 获取的道具名称列表 + /// public static void LogEarnVirtualCurrencyBySign(string currencyName, int value = 0, int balance = 0, string levelName = "", string scene = "home_page", string[] props = null, Dictionary extra = null) @@ -750,6 +683,7 @@ namespace Guru /// 当前关卡名称 /// 应用场景 /// 获取的道具名称列表 + /// public static void LogEarnVirtualCurrencyByIAP(string currencyName, int value = 0, int balance = 0, string levelName = "", string scene = "store", string[] props = null, Dictionary extra = null) @@ -772,6 +706,7 @@ namespace Guru /// 当前关卡名称 /// 应用场景 /// 获取的道具名称列表 + /// public static void LogEarnVirtualCurrencyByAds(string currencyName, int value = 0, int balance = 0, string levelName = "", string scene = "store", string[] props = null, Dictionary extra = null) @@ -780,7 +715,7 @@ namespace Guru string itemName = "ads"; LogEarnVirtualCurrencyAndProps(currencyName, value, balance, category, itemName, levelName, scene, props, extra); } - + /// /// 使用了金币半价 + 看广告获取到货币/道具 (earn_virtual_currency) (bonus:ads) ///
  • 通常类型: Coin 收入
  • @@ -793,6 +728,7 @@ namespace Guru /// 当前关卡名称 /// 应用场景 /// 获取的道具名称列表 + /// public static void LogEarnVirtualCurrencyByPaidAds(string currencyName, int value = 0, int balance = 0, string levelName = "", string scene = Consts.ParameterDefaultScene, string[] props = null, Dictionary extra = null) @@ -814,6 +750,7 @@ namespace Guru /// 当前关卡名称 /// 应用场景 /// 获取的道具名称列表 + /// public static void LogEarnVirtualCurrencyByLevelComplete(string currencyName, int value = 0, int balance = 0, string levelName = "", string scene = "store", string[] props = null, Dictionary extra = null) @@ -843,7 +780,7 @@ namespace Guru if (string.IsNullOrEmpty(scene)) scene = Consts.ParameterDefaultScene; LogEarnVirtualCurrencyAndProps(currencyName, value, balance, category, itemName, levelName, scene, null, extra); // TODO 这里的打点不对 } - + /// /// 通过道具交换/合成或得了其他道具 (earn_virtual_currency) (igb:coin) /// @@ -853,6 +790,7 @@ namespace Guru /// /// /// + /// public static void LogEarnPropByProp(string propName, string otherName, string scene = Consts.ParameterDefaultScene, int value = 1, int balance = 0, string levelName = "", Dictionary extra = null) @@ -860,8 +798,8 @@ namespace Guru string category = Consts.CurrencyCategoryIGB; LogEarnVirtualCurrency(propName, value, balance, category, otherName, levelName, scene, extra); } - - + + /// /// 通过转盘或者抽奖, 获取货币/道具 (earn_virtual_currency) (igb:lottery) ///
  • 通常类型: Coin 收入
  • @@ -874,6 +812,7 @@ namespace Guru /// 当前关卡名称 /// 应用场景 /// 获取的道具名称列表 + /// public static void LogEarnVirtualCurrencyByLottery(string currencyName, int value = 0, int balance = 0, string levelName = "", string scene = "store", string[] props = null, Dictionary extra = null) @@ -899,6 +838,7 @@ namespace Guru /// 当前关卡或者人物等级名称 /// 购买道具名称 /// 购买场景如 Store, Workbench, Sign, Ads.... + /// public static void LogSpendVirtualCurrency(string currencyName, int value, int balance, string category = "", string itemName = "", string levelName = "", string scene = "", Dictionary extra = null) { @@ -911,7 +851,6 @@ namespace Guru /// 货币/道具名称 /// 货币消耗值 10 /// 结算后货币总量 30 -> 20 - /// /// /// /// @@ -932,6 +871,7 @@ namespace Guru /// /// /// + /// public static void LogSpendVirtualCurrencyWithProp(string currencyName, string prop, int value, int balance, string levelName = "", string scene = "", Dictionary extra = null) @@ -949,6 +889,7 @@ namespace Guru /// /// /// + /// public static void LogSpendVirtualCurrencyWithProps(string currencyName, string[] props, int value, int balance, string levelName = "", string scene = "", Dictionary extra = null) @@ -974,6 +915,7 @@ namespace Guru /// /// /// + /// public static void LogSpendVirtualCurrencyWithBundle(string currencyName, string bundle, int value, int balance, string levelName = "", string scene = "", Dictionary extra = null) @@ -990,6 +932,7 @@ namespace Guru /// /// /// + /// public static void LogSpendVirtualCurrencyWithBundles(string currencyName, string[] bundles, int value, int balance, string levelName = "", string scene = "", Dictionary extra = null) @@ -1005,16 +948,18 @@ namespace Guru } } } - + /// /// 消耗物品, 交换其他物品 (spend_virtual_currency) (prop) /// - /// - /// + /// + /// /// /// /// /// + /// + /// public static void LogSpendPropWithProp(string propName, string otherName, int value, int balance, string levelName = "", string scene = "", string extraCategory = "", Dictionary extra = null) @@ -1318,19 +1263,12 @@ namespace Guru /// public static void SetEventPriority(EventPriority priority, string[] eventNames) { - // if (!IsInitialSuccess) - // { - // UnityEngine.Debug.LogError($"{Tag} :: LogEvent {priority} :: Please call first, before you call ."); - // return; - // } - if (Model.event_priorities == null) Model.event_priorities = new Dictionary(10); int i = 0; - string evt = ""; while (i < eventNames.Length) { - evt = eventNames[i]; + var evt = eventNames[i]; if (!string.IsNullOrEmpty(evt)) { Model.event_priorities[evt] = (int)priority; @@ -1341,12 +1279,6 @@ namespace Guru public static void SetEventPriority(EventPriority priority, string eventName) { - // if (!IsInitialSuccess) - // { - // UnityEngine.Debug.LogError($"{Tag} :: LogEvent {priority} :: Please call first, before you call ."); - // return; - // } - SetEventPriority(priority, new string[]{eventName}); } diff --git a/Runtime/Code/SDK/GuruSDK.Callbacks.cs b/Runtime/Code/SDK/GuruSDK.Callbacks.cs index ccfb247..1950be5 100644 --- a/Runtime/Code/SDK/GuruSDK.Callbacks.cs +++ b/Runtime/Code/SDK/GuruSDK.Callbacks.cs @@ -1,13 +1,10 @@ namespace Guru { using System; - using UnityEngine; public partial class GuruSDK { - - /// /// 回调参数类 /// @@ -18,23 +15,29 @@ namespace Guru ///
    public static class App { - // TODO: 改为 Invoke 方法 - internal static Action _onAppPaused; + private static Action _onAppPaused; public static event Action OnAppPaused { add => _onAppPaused += value; remove => _onAppPaused -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onAppQuit; + internal static void InvokeOnAppPaused(bool isPaused) + { + _onAppPaused?.Invoke(isPaused); + } + + private static Action _onAppQuit; public static event Action OnAppQuit { add => _onAppQuit += value; remove => _onAppQuit -= value; } + internal static void InvokeOnAppQuit() + { + _onAppQuit?.Invoke(); + } } - - + /// /// GDPR Consent /// @@ -48,9 +51,12 @@ namespace Guru add => _onConsentResult += value; remove => _onConsentResult -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onConsentResult; - + private static Action _onConsentResult; + internal static void InvokeOnConsentResult(int code) + { + _onConsentResult?.Invoke(code); + } + /// /// ATT 状态返回 /// @@ -59,9 +65,11 @@ namespace Guru add => _onAttResult += value; remove => _onAttResult -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onAttResult; - + private static Action _onAttResult; + internal static void InvokeOnAttResultCallback(int code) + { + _onAttResult?.Invoke(code); + } } /// @@ -69,89 +77,129 @@ namespace Guru /// public static class Ads { - // TODO: 改为 Invoke 方法 - internal static Action _onAdsInitComplete; + private static Action _onAdsInitComplete; public static event Action OnAdsInitComplete { add => _onAdsInitComplete += value; remove => _onAdsInitComplete -= value; } + internal static void InvokeOnAdsInitComplete() + { + _onAdsInitComplete?.Invoke(); + } - // TODO: 改为 Invoke 方法 //------------ BANNER ----------------- - internal static Action _onBannerADStartLoad; + private static Action _onBannerADStartLoad; public static event Action OnBannerADStartLoad { add => _onBannerADStartLoad += value; remove => _onBannerADStartLoad -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onBannerADLoaded; + internal static void InvokeOnBannerADStartLoad(string adUnitId) + { + _onBannerADStartLoad?.Invoke(adUnitId); + } + + private static Action _onBannerADLoaded; public static event Action OnBannerADLoaded { add => _onBannerADLoaded += value; remove => _onBannerADLoaded -= value; } + internal static void InvokeOnBannerADLoaded() + { + _onBannerADLoaded?.Invoke(); + } //------------ INTER ----------------- - // TODO: 改为 Invoke 方法 - internal static Action _onInterstitialADStartLoad; + private static Action _onInterstitialADStartLoad; public static event Action OnInterstitialADStartLoad { add => _onInterstitialADStartLoad += value; remove => _onInterstitialADStartLoad -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onInterstitialADLoaded; + internal static void InvokeOnInterstitialADStartLoad(string adUnitId) + { + _onInterstitialADStartLoad?.Invoke(adUnitId); + } + + private static Action _onInterstitialADLoaded; public static event Action OnInterstitialADLoaded { add => _onInterstitialADLoaded += value; remove => _onInterstitialADLoaded -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onInterstitialADFailed; + internal static void InvokeOnInterstitialADLoaded() + { + _onInterstitialADLoaded?.Invoke(); + } + + private static Action _onInterstitialADFailed; public static event Action OnInterstitialADFailed { add => _onInterstitialADFailed += value; remove => _onInterstitialADFailed -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onInterstitialADClosed; + internal static void InvokeOnInterstitialADFailed() + { + _onInterstitialADFailed?.Invoke(); + } + + private static Action _onInterstitialADClosed; public static event Action OnInterstitialADClosed { add => _onInterstitialADClosed += value; remove => _onInterstitialADClosed -= value; } + internal static void InvokeOnInterstitialADClosed() + { + _onInterstitialADClosed?.Invoke(); + } //------------ REWARD ----------------- - // TODO: 改为 Invoke 方法 - internal static Action _onRewardedADStartLoad; + private static Action _onRewardedADStartLoad; public static event Action OnRewardedADStartLoad { add => _onRewardedADStartLoad += value; remove => _onRewardedADStartLoad -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onRewardedADLoaded; + internal static void InvokeOnRewardedADStartLoad(string adUnitId) + { + _onRewardedADStartLoad?.Invoke(adUnitId); + } + + private static Action _onRewardedADLoaded; public static event Action OnRewardedADLoaded { add => _onRewardedADLoaded += value; remove => _onRewardedADLoaded -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onRewardADClosed; + internal static void InvokeOnRewardedADLoaded() + { + _onRewardedADLoaded?.Invoke(); + } + + private static Action _onRewardADClosed; public static event Action OnRewardedADClosed { add => _onRewardADClosed += value; remove => _onRewardADClosed -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onRewardADFailed; + internal static void InvokeOnRewardADClosed() + { + _onRewardADClosed?.Invoke(); + } + + private static Action _onRewardADFailed; public static event Action OnRewardADFailed { add => _onRewardADFailed += value; remove => _onRewardADFailed -= value; } + internal static void InvokeOnRewardADFailed() + { + _onRewardADFailed?.Invoke(); + } } /// @@ -159,13 +207,16 @@ namespace Guru /// public static class Remote { - // TODO: 改为 Invoke 方法 - internal static Action _onRemoteFetchComplete; + private static Action _onRemoteFetchComplete; public static event Action OnRemoteFetchComplete { add => _onRemoteFetchComplete += value; remove => _onRemoteFetchComplete -= value; } + internal static void InvokeOnRemoteFetchComplete(bool success) + { + _onRemoteFetchComplete?.Invoke(success); + } } /// @@ -173,92 +224,137 @@ namespace Guru /// public static class IAP { - // TODO: 改为 Invoke 方法 - internal static Action _onIAPInitStart; + private static Action _onIAPInitStart; public static event Action OnIAPInitStart { add => _onIAPInitStart += value; remove => _onIAPInitStart -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onIAPInitComplete; + internal static void InvokeOnIAPInitStart() + { + _onIAPInitStart?.Invoke(); + } + + + private static Action _onIAPInitComplete; public static event Action OnIAPInitComplete { add => _onIAPInitComplete += value; remove => _onIAPInitComplete -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onPurchaseStart; + internal static void InvokeOnIAPInitComplete(bool success) + { + _onIAPInitComplete?.Invoke(success); + } + + + private static Action _onPurchaseStart; public static event Action OnPurchaseStart { add => _onPurchaseStart += value; remove => _onPurchaseStart -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onPurchaseEnd; + internal static void InvokeOnPurchaseStart(string productId) + { + _onPurchaseStart?.Invoke(productId); + } + + + private static Action _onPurchaseEnd; public static event Action OnPurchaseEnd { add => _onPurchaseEnd += value; remove => _onPurchaseEnd -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onPurchaseFailed; + internal static void InvokeOnPurchaseEnd(string productId, bool success) + { + _onPurchaseEnd?.Invoke(productId, success); + } + + + private static Action _onPurchaseFailed; public static event Action OnPurchaseFailed { add => _onPurchaseFailed += value; remove => _onPurchaseFailed -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onIAPRestored; + internal static void InvokeOnPurchaseFailed(string productId, string error) + { + _onPurchaseFailed?.Invoke(productId, error); + } + + + private static Action _onIAPRestored; public static event Action OnIAPRestored { add => _onIAPRestored += value; remove => _onIAPRestored -= value; } - + internal static void InvokeOnIAPRestored(bool success, string productId) + { + _onIAPRestored?.Invoke(success, productId); + } } public static class SDK { - // TODO: 改为 Invoke 方法 - internal static Action _onFirebaseReady; + private static Action _onFirebaseReady; public static event Action OnFirebaseReady { add => _onFirebaseReady += value; remove => _onFirebaseReady -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onGuruServiceReady; + internal static void InvokeOnFirebaseReady(bool success) + { + _onFirebaseReady?.Invoke(success); + } + + private static Action _onGuruServiceReady; public static event Action OnGuruServiceReady { add => _onGuruServiceReady += value; remove => _onGuruServiceReady -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onDebuggerDisplayed; + internal static void InvokeOnGuruServiceReady() + { + _onGuruServiceReady?.Invoke(); + } + + private static Action _onDebuggerDisplayed; public static event Action OnDisplayDebugger { add => _onDebuggerDisplayed += value; remove => _onDebuggerDisplayed -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onUserAuthResult; + internal static void InvokeOnDebuggerDisplayed(bool success) + { + _onDebuggerDisplayed?.Invoke(success); + } + + private static Action _onUserAuthResult; public static event Action OnUserAuthResult { add => _onUserAuthResult += value; remove => _onUserAuthResult -= value; } - // TODO: 改为 Invoke 方法 - internal static Action _onFirebaseAuthResult; + internal static void InvokeOnUserAuthResult(bool success) + { + _onUserAuthResult?.Invoke(success); + } + + private static Action _onFirebaseAuthResult; public static event Action OnFirebaseAuthResult { add => _onFirebaseAuthResult += value; remove => _onFirebaseAuthResult -= value; } + internal static void InvokeOnFirebaseAuthResult(bool success) + { + _onFirebaseAuthResult?.Invoke(success); + } - // TODO: 改为 Inovk 方法 // DeepLink 回调 private static Action _onDeeplinkCallback; public static event Action OnDeeplinkCallback diff --git a/Runtime/Code/SDK/GuruSDK.Const.cs b/Runtime/Code/SDK/GuruSDK.Const.cs index 54125d5..28d0923 100644 --- a/Runtime/Code/SDK/GuruSDK.Const.cs +++ b/Runtime/Code/SDK/GuruSDK.Const.cs @@ -265,6 +265,23 @@ namespace Guru // SDK public const string EventSDKInfo = "sdk_info"; + + //----------------- 关卡开始类型 --------------------- + public const string EventLevelStartModePlay = "play"; + public const string EventLevelStartModeReplay = "replay"; + public const string EventLevelStartModeContinue= "continue"; + + //----------------- 关卡结束类型 --------------------- + public const string EventLevelEndSuccess = "success"; + public const string EventLevelEndFail = "fail"; + public const string EventLevelEndExit = "exit"; + public const string EventLevelEndTimeout = "timeout"; + + /// + /// 主线关卡类型 + /// 只有传入此类型时才会进行 Blevel 的累加 + /// + public const string LevelTypeMain = "main"; #endregion diff --git a/Runtime/Code/SDK/GuruSDK.Debugger.cs b/Runtime/Code/SDK/GuruSDK.Debugger.cs index 57760a4..9ede5ed 100644 --- a/Runtime/Code/SDK/GuruSDK.Debugger.cs +++ b/Runtime/Code/SDK/GuruSDK.Debugger.cs @@ -6,8 +6,7 @@ namespace Guru public partial class GuruSDK { - private static bool _isDebuggerInited = false; - private static bool _useBaseOpions = true; + private static readonly bool _useBaseOptions = true; private static GuruDebugger _debugger; @@ -18,7 +17,7 @@ namespace Guru if (_debugger == null) { _debugger = GuruDebugger.Instance; - if (_useBaseOpions) + if (_useBaseOptions) { InitDebuggerLayout(); } @@ -26,7 +25,6 @@ namespace Guru return _debugger; } } - /// /// 显示广告状态 @@ -38,9 +36,7 @@ namespace Guru Debugger.ShowAdStatus(); return true; } - - - + /// /// 显示 Debugger /// @@ -98,17 +94,15 @@ namespace Guru GuruDebugger.OnClosed -= OnDebuggerClosed; GuruDebugger.OnClosed += OnDebuggerClosed; - Callbacks.SDK._onDebuggerDisplayed?.Invoke(true); + Callbacks.SDK.InvokeOnDebuggerDisplayed(true); } - private static void OnDebuggerClosed() { GuruDebugger.OnClosed -= OnDebuggerClosed; - Callbacks.SDK._onDebuggerDisplayed?.Invoke(false); + Callbacks.SDK.InvokeOnDebuggerDisplayed(false); } - - + /// /// 显示 Debugger /// diff --git a/Runtime/Code/SDK/GuruSDK.IAP.cs b/Runtime/Code/SDK/GuruSDK.IAP.cs index c2d9adf..7d3037e 100644 --- a/Runtime/Code/SDK/GuruSDK.IAP.cs +++ b/Runtime/Code/SDK/GuruSDK.IAP.cs @@ -1,6 +1,5 @@ namespace Guru { - using UnityEngine; using System; using System.Linq; @@ -32,7 +31,7 @@ namespace Guru GuruIAP.Instance.OnBuyFailed += OnBuyFailed; GuruIAP.Instance.OnGetProductReceipt += OnGetReceipt; - Callbacks.IAP._onIAPInitStart?.Invoke(); // 初始化之前进行调用 + Callbacks.IAP.InvokeOnIAPInitStart(); // 初始化之前进行调用 GuruIAP.Instance.InitWithKeys(uid, googleKey, appleRootCerts, IsDebugMode); } @@ -45,7 +44,7 @@ namespace Guru { LogI($"IAP init result: {success}"); IsIAPReady = success; - Callbacks.IAP._onIAPInitComplete?.Invoke(success); + Callbacks.IAP.InvokeOnIAPInitComplete(success); } private static bool CheckIAPReady() @@ -70,7 +69,7 @@ namespace Guru /// public static ProductInfo GetProductInfo(string productName) { - return GuruIAP.Instance?.GetInfo(productName) ?? null; + return GuruIAP.Instance?.GetInfo(productName); } /// @@ -80,7 +79,7 @@ namespace Guru /// public static ProductInfo GetProductInfoById(string productId) { - return GuruIAP.Instance?.GetInfoById(productId) ?? null; + return GuruIAP.Instance?.GetInfoById(productId); } @@ -127,7 +126,7 @@ namespace Guru #region Purchase - private static Action _onPurchaseCallback; + private static Action InvokeOnPurchaseCallback; /// /// 老接口, 将会被废弃 @@ -150,7 +149,7 @@ namespace Guru { if (CheckIAPReady()) { - _onPurchaseCallback = purchaseCallback; + InvokeOnPurchaseCallback = purchaseCallback; GuruIAP.Instance.Buy(productName, category); } } @@ -182,8 +181,8 @@ namespace Guru private static void OnBuyEnd(string productName, bool success) { if (success) Model.PurchasedCount++; - _onPurchaseCallback?.Invoke(productName, success); - Callbacks.IAP._onPurchaseEnd?.Invoke(productName, success); + InvokeOnPurchaseCallback?.Invoke(productName, success); + Callbacks.IAP.InvokeOnPurchaseEnd(productName, success); } /// @@ -192,7 +191,7 @@ namespace Guru /// private static void OnBuyStart(string productName) { - Callbacks.IAP._onPurchaseStart?.Invoke(productName); + Callbacks.IAP.InvokeOnPurchaseStart(productName); } /// @@ -202,7 +201,7 @@ namespace Guru /// private static void OnBuyFailed(string productName, string reason) { - Callbacks.IAP._onPurchaseFailed?.Invoke(productName, reason); + Callbacks.IAP.InvokeOnPurchaseFailed(productName, reason); } #endregion @@ -223,7 +222,7 @@ namespace Guru } private static void OnRestored(bool success, string msg) { - Callbacks.IAP._onIAPRestored?.Invoke(success, msg); // 更新回复购买回调 + Callbacks.IAP.InvokeOnIAPRestored(success, msg); // 更新回复购买回调 } #endregion diff --git a/Runtime/Code/SDK/GuruSDK.cs b/Runtime/Code/SDK/GuruSDK.cs index 6eb4345..6574708 100644 --- a/Runtime/Code/SDK/GuruSDK.cs +++ b/Runtime/Code/SDK/GuruSDK.cs @@ -14,7 +14,7 @@ namespace Guru public const string Version = "1.1.0"; // Const - public const string Tag = "[Guru]"; + private const string Tag = "[Guru]"; public const string ServicesConfigKey = "guru_services"; private static GuruSDK _instance; @@ -36,8 +36,8 @@ namespace Guru private GuruSDKInitConfig _initConfig; - internal static GuruSDKInitConfig InitConfig => Instance._initConfig; - internal static GuruSDKModel Model => GuruSDKModel.Instance; + private static GuruSDKInitConfig InitConfig => Instance._initConfig; + private static GuruSDKModel Model => GuruSDKModel.Instance; private static GuruServicesConfig _appServicesConfig; private static GuruSettings _guruSettings; private static GuruSettings GuruSettings @@ -92,6 +92,7 @@ namespace Guru // GuruSDk.Callbacks -> GuruSDkCallbacks 所有的内置回调改为成员变量, // 去掉所有的内部类, 去掉所有的 Static // Static 只用于常量 + // TODO: 下一个版本改为标准的 Builder 模式 public static GuruSDKInitConfig BuildConfig( bool useCustomConsent = false, bool autoLoadAds = true, @@ -99,8 +100,7 @@ namespace Guru bool autoRecordFinishedLevels = true, bool debugMode = false, bool isBuyNoAds = false, - // TODO 直接在此处设置回调 - bool useAdjustDeeplink = false, + Action onAdjustDeeplinkCallback = null, string bannerColor = "#00000000", Dictionary defaultRemoteData = null, byte[] googleKeys = null, @@ -109,7 +109,7 @@ namespace Guru { var config = GuruSDKInitConfig.Build(useCustomConsent, autoLoadAds, iapEnabled, autoRecordFinishedLevels, isBuyNoAds, bannerColor, - debugMode, useAdjustDeeplink, defaultRemoteData, googleKeys, appleRootCerts, debugEnableEventLog); + debugMode, onAdjustDeeplinkCallback, defaultRemoteData, googleKeys, appleRootCerts, debugEnableEventLog); return config; } @@ -123,20 +123,9 @@ namespace Guru _initTime = DateTime.Now.ToUniversalTime(); // ----- First Open Time ----- // SetFirstOpenTime(GetFirstOpenTime()); // FirstOpenTime - LogI($"#1 ---- Guru SDK [{Version}] ----\n{config.ToString()}"); + LogI($"#1 ---- Guru SDK [{Version}] ----\n{config}"); Instance.StartWithConfig(config, onComplete); } - private static string GetFirstOpenTime() - { - string firstOpenTime = IPMConfig.FirstOpenTime; - if (string.IsNullOrEmpty(firstOpenTime)) - { - firstOpenTime = TimeUtil.GetCurrentTimeStamp().ToString(); - IPMConfig.FirstOpenTime = firstOpenTime; - } - - return firstOpenTime; - } /// /// 启动SDK @@ -157,10 +146,9 @@ namespace Guru InitUpdaters(); // Updaters InitThreadHandler(); // 初始化线程处理器 - InitServices(); - + InitServices(); // 初始化所有的服务 InitNetworkMonitor(); // 网络状态 - + InitiallyUpdateUserProperties(); // 上报所有初始化用户属性 onComplete?.Invoke(true); } @@ -191,10 +179,10 @@ namespace Guru FirebaseUtil.OnUserAuthResult += OnUserAuthResult; FirebaseUtil.OnFirebaseAuthResult += OnFirebaseAuthResult; - // TODO: 应该直接判断 Callback 是否存在 - if (InitConfig.UseAdjustDeeplink) + if (InitConfig.OnAdjustDeeplinkCallback != null) { - FirebaseUtil.OnAdjustDeeplinkCallback = OnDeeplinkCallback; // 挂载 Deeplink 的回调 + //TODO: 下个版本 AdjustService 和 Firebase 解耦 + FirebaseUtil.OnAdjustDeeplinkCallback = InitConfig.OnAdjustDeeplinkCallback; // 挂载 Deeplink 的回调 } FirebaseUtil.InitFirebase(Analytics.OnFirebaseInitCompleted); // 确保所有的逻辑提前被调用到 @@ -207,7 +195,7 @@ namespace Guru { success = false; } - Callbacks.SDK._onUserAuthResult?.Invoke(success); + Callbacks.SDK.InvokeOnUserAuthResult(success); if (success) { @@ -218,13 +206,13 @@ namespace Guru GuruIAP.Instance.SetUUID(UUID); } - UpdateAllUserProperties(); // 同步所有用户属性打点 + SetUID(UID); } } private void OnFirebaseAuthResult(bool success) { - Callbacks.SDK._onFirebaseAuthResult?.Invoke(success); + Callbacks.SDK.InvokeOnFirebaseAuthResult(success); } /// @@ -235,7 +223,7 @@ namespace Guru FirebaseUtil.onInitComplete -= OnFirebaseReady; LogI($"#3 --- On FirebaseDeps: {success} ---"); IsFirebaseReady = success; - Callbacks.SDK._onFirebaseReady?.Invoke(success); + Callbacks.SDK.InvokeOnFirebaseReady(success); // LogFirebaseDeps(success); LogI($"#3.5 --- Call InitRemoteConfig ---"); @@ -245,14 +233,7 @@ namespace Guru LogI($"#4 --- Apply remote services config ---"); // 根据缓存的云控配置来初始化参数 - InitAllServices(); - - LogI($"#5 --- sync sdk time ---"); - var sp = DateTime.Now.ToUniversalTime() - _initTime; - LogSDKInitTime(sp.TotalSeconds); - - // 上报所有初始化用户属性 - UpdateAllUserProperties(); + InitAllGuruServices(); } @@ -280,7 +261,7 @@ namespace Guru { LogI($"#6 --- Remote fetch complete: {success} ---"); ABTestManager.Init(); // 启动AB测试解析器 - Callbacks.Remote._onRemoteFetchComplete?.Invoke(success); + Callbacks.Remote.InvokeOnRemoteFetchComplete(success); } @@ -298,18 +279,18 @@ namespace Guru /// /// Apply Cloud guru-service configs for sdk assets /// - private void InitAllServices() + private void InitAllGuruServices() { // -------- Init Analytics --------- InitUserProperties(); SetSDKEventPriority(); - // -------- Init Noti ----------- + // -------- Init Notification ----------- InitNotiPermission(); bool useKeywords = false; bool useIAP = _initConfig.IAPEnabled; bool appleReview = false; - bool enableAnaErrorLog = false; + // bool enableAnaErrorLog = false; //----------- Set GuruServices ---------------- var services = GetRemoteServicesConfig(); @@ -319,7 +300,7 @@ namespace Guru useKeywords = _appServicesConfig.KeywordsEnabled(); // 使用初始化配置中的 IAPEnable来联合限定, 如果本地写死关闭则不走云控开启 useIAP = _initConfig.IAPEnabled && _appServicesConfig.IsIAPEnabled(); - enableAnaErrorLog = _appServicesConfig.EnableAnaErrorLog(); + // enableAnaErrorLog = _appServicesConfig.EnableAnaErrorLog(); Try(() => { @@ -340,7 +321,7 @@ namespace Guru GuruSettings.UpdateAdjustEvents(_appServicesConfig.adjust_settings.events); } - LogI($"#4.2 --- Start GuruSttings ---"); + LogI($"#4.2 --- Start GuruSettings ---"); // GuruSettings 设置 if (null != _appServicesConfig.app_settings) { @@ -381,7 +362,7 @@ namespace Guru //--------------------------------- }, ex => { - UnityEngine.Debug.LogError($"--- ERROR on apply services: {ex.Message}"); + Debug.LogError($"--- ERROR on apply services: {ex.Message}"); }); @@ -402,7 +383,7 @@ namespace Guru InitIAP(UID, _initConfig.GoogleKeys, _initConfig.AppleRootCerts); // 初始化IAP }, ex => { - UnityEngine.Debug.LogError($"--- ERROR on useIAP: {ex.Message}"); + Debug.LogError($"--- ERROR on useIAP: {ex.Message}"); }); } //----------- Set Keywords ---------------- @@ -415,7 +396,7 @@ namespace Guru KeywordsManager.Install(Model.IsIapUser, Model.SuccessLevelId); // 启动Keyword管理器 }, ex => { - UnityEngine.Debug.LogError($"--- ERROR on Keywords: {ex.Message}"); + Debug.LogError($"--- ERROR on Keywords: {ex.Message}"); }); } @@ -439,24 +420,25 @@ namespace Guru { // LogI($"--- #3 Start Consent Flow ---"); // StartConsentFlow(); - Try(() => + Try(StartConsentFlow, ex => { - StartConsentFlow(); - }, ex => - { - UnityEngine.Debug.LogError($"--- ERROR on StartConsentFlow: {ex.Message}"); + Debug.LogError($"--- ERROR on StartConsentFlow: {ex.Message}"); }); } IsServiceReady = true; // 中台服务初始化结束 - Callbacks.SDK._onGuruServiceReady?.Invoke(); + Callbacks.SDK.InvokeOnGuruServiceReady(); #if UNITY_ANDROID // Android 命令行调试 StartAndroidDebugCmds(); #endif + + LogI($"#5 --- sync sdk time ---"); + // TODO: 本调用放在这里不合适, 应该和 Firebase 解耦 + LogSDKInitTime((DateTime.Now.ToUniversalTime() - _initTime).TotalSeconds); } /// @@ -482,7 +464,7 @@ namespace Guru { // No remote data fetched from cloud, should use default values json = defaultJson; - UnityEngine.Debug.Log($"{Tag} --- No remote data found with: {key} -> Using default key {ServicesConfigKey} and local data!!!"); + Debug.Log($"{Tag} --- No remote data found with: {key} -> Using default key {ServicesConfigKey} and local data!!!"); } if (!string.IsNullOrEmpty(json)) @@ -529,14 +511,14 @@ namespace Guru #region 数据 - private void OnBLevelChanged(int blevel) + private void OnBLevelChanged(int bLevel) { - SetUserBLevel(blevel); + SetUserBLevel(bLevel); } - private void OnBPlayChanged(int bplay) + private void OnBPlayChanged(int bPlay) { - SetUserBPlay(bplay); + SetUserBPlay(bPlay); } #endregion @@ -545,17 +527,17 @@ namespace Guru internal static void LogI(object message) { - UnityEngine.Debug.Log($"{Tag} {message}"); + Debug.Log($"{Tag} {message}"); } internal static void LogW(object message) { - UnityEngine.Debug.LogWarning($"{Tag} {message}"); + Debug.LogWarning($"{Tag} {message}"); } internal static void LogE(object message) { - UnityEngine.Debug.LogError($"{Tag} {message}"); + Debug.LogError($"{Tag} {message}"); } @@ -566,7 +548,7 @@ namespace Guru internal static void LogException(Exception e) { - UnityEngine.Debug.LogException(e); + Debug.LogException(e); } /// @@ -607,7 +589,7 @@ namespace Guru private void OnAppPauseHandler(bool paused) { if(paused) Model.Save(true); // 强制保存数据 - Callbacks.App._onAppPaused?.Invoke(paused); + Callbacks.App.InvokeOnAppPaused(paused); } private void OnApplicationPause(bool paused) @@ -623,7 +605,7 @@ namespace Guru private void OnApplicationQuit() { Model.Save(true); - Callbacks.App._onAppQuit?.Invoke(); + Callbacks.App.InvokeOnAppQuit(); } #endregion @@ -686,14 +668,13 @@ namespace Guru private void UpdateAllUpdates() { int i = 0; - IUpdater updater; // ---- Updater Trigger ---- if (_updaterRunningList.Count > 0) { i = 0; while (i < _updaterRunningList.Count) { - updater = _updaterRunningList[i]; + var updater = _updaterRunningList[i]; if (updater != null) { if (updater.State == UpdaterState.Running) @@ -759,7 +740,7 @@ namespace Guru private static int _messageRetry = 0; public static void SetPushNotificationEnabled(bool enabled) { - DeviceInfoUploadRequest request = new DeviceInfoUploadRequest() + DeviceInfoUploadRequest request = (DeviceInfoUploadRequest) new DeviceInfoUploadRequest() .SetRetryTimes(1) .SetSuccessCallBack(() => { @@ -771,13 +752,12 @@ namespace Guru double retryDelay = Math.Pow(2, _messageRetry); _messageRetry++; CoroutineHelper.Instance.StartDelayed((float)retryDelay, ()=> SetPushNotificationEnabled(enabled)); - }) as DeviceInfoUploadRequest; + }); - if (request != null) - { - request.SetPushEnabled(enabled); - request.Send(); - } + if (request == null) return; + + request.SetPushEnabled(enabled); + request.Send(); } #endregion @@ -804,36 +784,17 @@ namespace Guru private void InitNetworkMonitor() { - _networkStatusMonitor = new NetworkStatusMonitor(); - _networkStatusMonitor.Init(OnNetworkMonitorInitComplete); + // SetUserProperty(Consts.PropertyNetwork, GetNetworkStatus()); + // TODO: 下个版本加入真正的自动更新网络状态的实现 } - private void OnNetworkMonitorInitComplete(bool success) - { - if (success) - { - // 上报用户network属性 - _networkStatus = _networkStatusMonitor.GetNetworkStatus(); - SetUserProperty(Consts.PropertyNetwork, _networkStatus); - } - else - { - Debug.LogError($"[SDK] --- NetworkStatusMonitor init failed"); - } - } - - private string GetNetworkStatus() { - if(_networkStatusMonitor != null) + if(_networkStatusMonitor == null) { - _networkStatus = _networkStatusMonitor.GetNetworkStatus(); + _networkStatusMonitor = new NetworkStatusMonitor(); } - else - { - _networkStatus = "none"; - } - return _networkStatus; + return _networkStatusMonitor.GetNetworkStatus(); }