From fde37d807aa9c70f62a48cd61e5a4773dfe1c553 Mon Sep 17 00:00:00 2001 From: huyufei Date: Fri, 8 Mar 2024 20:15:33 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E6=9B=B4=E6=96=B0=E5=92=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=90=AF=E5=8A=A8=E6=97=B6=E7=A9=BA=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E9=80=A0=E6=88=90=20Crash=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Pubmatic/Runtime/AdChannelPubMatic.cs | 6 ++ .../Tradplus/Runtime/GuruSettigs.Tradplus.cs | 3 + Runtime/GuruCore/Runtime/Ads/ADService.cs | 9 +-- Runtime/GuruCore/Runtime/Ads/AdsModel.cs | 55 ++++++++++---- .../Runtime/Analytics/Analytics.Custom.cs | 14 ++-- .../GuruCore/Runtime/Analytics/Analytics.cs | 71 ++++++++++++++++++- .../Runtime/ExtensionKit/CDNLoader.cs | 2 - .../GuruCore/Runtime/Firebase/FirebaseUtil.cs | 6 +- .../GuruIAP/Runtime/Code/IAPServiceBase.cs | 21 ++++++ .../Runtime/Code/Settings/GuruSettings.IAP.cs | 1 - 10 files changed, 157 insertions(+), 31 deletions(-) diff --git a/Runtime/GuruAds/Pubmatic/Runtime/AdChannelPubMatic.cs b/Runtime/GuruAds/Pubmatic/Runtime/AdChannelPubMatic.cs index f901f12..7909b9d 100644 --- a/Runtime/GuruAds/Pubmatic/Runtime/AdChannelPubMatic.cs +++ b/Runtime/GuruAds/Pubmatic/Runtime/AdChannelPubMatic.cs @@ -60,6 +60,12 @@ namespace Guru Debug.Log($"[Ads] --- PubMatic is not enabled"); return; } + + if (string.IsNullOrEmpty(PMStoreUrl)) + { + Debug.Log($"[Ads] --- PubMatic with empty store url. skip initialize..."); + return; + } var appInfo = new POBApplicationInfo(); appInfo.StoreURL = new Uri(PMStoreUrl); diff --git a/Runtime/GuruAds/Tradplus/Runtime/GuruSettigs.Tradplus.cs b/Runtime/GuruAds/Tradplus/Runtime/GuruSettigs.Tradplus.cs index 9bcbfa0..87fe601 100644 --- a/Runtime/GuruAds/Tradplus/Runtime/GuruSettigs.Tradplus.cs +++ b/Runtime/GuruAds/Tradplus/Runtime/GuruSettigs.Tradplus.cs @@ -10,6 +10,9 @@ namespace Guru { [Header("Tradplus 广告配置")] public AdChannelSettings TradplusSetting; + + + } } \ No newline at end of file diff --git a/Runtime/GuruCore/Runtime/Ads/ADService.cs b/Runtime/GuruCore/Runtime/Ads/ADService.cs index 28a09ef..9ca592e 100644 --- a/Runtime/GuruCore/Runtime/Ads/ADService.cs +++ b/Runtime/GuruCore/Runtime/Ads/ADService.cs @@ -49,8 +49,7 @@ namespace Guru //------------ 以下为扩展的广告渠道 ------------------ // 请根据项目需求实现各渠道接入的逻辑 // 开启渠道需要添加对应的宏 - -// #if AD_AMAZON + channel = new AdChanelAmazon(); channel.Initialize(); _adChannels.Add(channel); // Amazon @@ -73,13 +72,11 @@ namespace Guru // if (success && firstLoad) OnLoadMaxRV(); }; } -// #endif - -// #if AD_PUBMATIC + channel = new AdChannelPubMatic(); channel.Initialize(); _adChannels.Add(channel); // PubMatic -// #endif + } #endregion diff --git a/Runtime/GuruCore/Runtime/Ads/AdsModel.cs b/Runtime/GuruCore/Runtime/Ads/AdsModel.cs index d93cfbd..34e4b19 100644 --- a/Runtime/GuruCore/Runtime/Ads/AdsModel.cs +++ b/Runtime/GuruCore/Runtime/Ads/AdsModel.cs @@ -1,11 +1,13 @@ + + namespace Guru { using UnityEngine; - + using System; public class AdsModel { - private AdsModelStorage _storage; + internal AdsModelStorage _storage; public int radsRewardCount = 0; public double tchAd001Value = 0; @@ -42,12 +44,7 @@ namespace Guru } } - - - private void Save() - { - _storage.Save(ToJson()); - } + private void Save() => _storage.Save(); public string ToJson() { @@ -73,7 +70,9 @@ namespace Guru { private const string INSTANCE_NAME = "GuruSDK"; private bool _needToSave = false; - private string _jsonData = ""; + private float _lastSavedTime = 0; + private float _saveInterval = 2; + private AdsModel _model; public static void Create(out AdsModel model, out AdsModelStorage storage) { @@ -98,27 +97,53 @@ namespace Guru { model = new AdsModel(); } + + model._storage = storage; + storage._model = model; } - - public void Save(string json) + + public void Save(bool forceSave = false) { - _jsonData = json; - _needToSave = true; + _needToSave = forceSave || (Time.realtimeSinceStartup - _lastSavedTime > _saveInterval); } #region 生命周期 + + // 主线程进行写入操作 void Update() { if (_needToSave) { - PlayerPrefs.SetString(nameof(AdsModel), _jsonData); - _needToSave = false; + var json = _model?.ToJson() ?? ""; + if (!string.IsNullOrEmpty(json)) + { + PlayerPrefs.SetString(nameof(AdsModel), json); + _needToSave = false; + _lastSavedTime = Time.realtimeSinceStartup; + } } } + // 监听特殊事件 + private void OnApplicationPause(bool pauseStatus) + { + if (pauseStatus) + { + Save( true); + } + } + + // 监听特殊事件 + private void OnApplicationFocus(bool hasFocus) + { + if (!hasFocus) + { + Save( true); + } + } #endregion } diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs index 4f29672..06fafbf 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.Custom.cs @@ -24,11 +24,17 @@ namespace Guru public static bool IsDebug { get; set; } = false; + private static bool _hasInited = false; + + public static bool IsReady => _hasInited; + /// /// 初始化Guru自打点系统 (请优先于 Firebase 初始化调用) /// public static void InstallGuruAnalytics(bool isDebug = false) { + if (_hasInited) return; + try { #if UNITY_EDITOR @@ -49,17 +55,15 @@ namespace Guru _reportSuccessInterval = 120; // 2分钟上报一次 UpdateAllValues(); + + _hasInited = true; } catch (Exception e) { Crashlytics.LogException(e); } } - - - - - + #region 各ID上报信息 /// diff --git a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs index a52c014..5042e96 100644 --- a/Runtime/GuruCore/Runtime/Analytics/Analytics.cs +++ b/Runtime/GuruCore/Runtime/Analytics/Analytics.cs @@ -1,5 +1,7 @@ +using System.Collections; + namespace Guru { using System; @@ -136,6 +138,7 @@ namespace Guru { Log.I(TAG, $"eventName:{eventName}"); CustomLogEvent(eventName); // 自定义打点上报 + CheckLogCache(eventName, null, eventSetting); // log缓存和消费 if (!IsEnable) return; @@ -167,6 +170,8 @@ namespace Guru { Log.I(TAG, $"eventName:{eventName}, params:{string.Join(",", extras)}"); CustomLogEvent(eventName, extras); // 自定义打点上报 + + CheckLogCache(eventName, extras, eventSetting); // log缓存和消费 if (!IsEnable) return; @@ -263,6 +268,70 @@ namespace Guru } #endregion - + + #region 打点缓存 + + private static Queue _savedLogs; + + internal static Queue SavedLogs + { + get + { + if (_savedLogs == null) _savedLogs = new Queue(20); + return _savedLogs; + } + } + + + private static void CheckLogCache(string key, Dictionary data = null, EventSetting setting = null) + { + try + { + if (!_isInited) + { + if (data == null) data = new Dictionary(); + data["log_stamp"] = TimeUtil.GetCurrentTimeStamp().ToString(); + SavedLogs.Enqueue(new SavedLog(key, data, setting)); + } + else + { + int len = SavedLogs.Count; + if (len > 0) + { + while (SavedLogs.Count > 0) + { + var log = SavedLogs.Dequeue(); + LogEvent(log.key, log.data, log.setting); + } + } + } + } + catch (Exception ex) + { + Crashlytics.LogException(ex); + } + } + + + #endregion + } + + + internal class SavedLog + { + public string key; + public Dictionary data; + public Analytics.EventSetting setting; + + public SavedLog() + { + } + + public SavedLog(string _key, Dictionary _data = null, Analytics.EventSetting _setting = null) + { + key = _key; + data = _data; + setting = _setting; + } } } \ No newline at end of file diff --git a/Runtime/GuruCore/Runtime/ExtensionKit/CDNLoader.cs b/Runtime/GuruCore/Runtime/ExtensionKit/CDNLoader.cs index 137b0e6..1512653 100644 --- a/Runtime/GuruCore/Runtime/ExtensionKit/CDNLoader.cs +++ b/Runtime/GuruCore/Runtime/ExtensionKit/CDNLoader.cs @@ -398,8 +398,6 @@ public class CDNLoader : MonoBehaviour public string text = ""; public byte[] data = null; public Texture2D texture = null; - public AssetBundle assetBundle = null; - internal static LoadResult Create(LoadTask task, bool success = false, string error = "") { diff --git a/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.cs b/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.cs index a9d01a2..80ed20a 100644 --- a/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.cs +++ b/Runtime/GuruCore/Runtime/Firebase/FirebaseUtil.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Firebase; using Firebase.Analytics; using Firebase.Extensions; @@ -9,6 +10,8 @@ namespace Guru { private static readonly string LOG_TAG = "Firebase"; private static bool _isDebug = false; + private static bool _isReady = false; + public static bool IsReady => _isReady; public static DependencyStatus DependencyStatus = DependencyStatus.UnavailableOther; public static bool IsFirebaseInitialized => DependencyStatus == DependencyStatus.Available; @@ -18,8 +21,9 @@ namespace Guru GuruRepoter.Install(); FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => { DependencyStatus = task.Result; - if (DependencyStatus == DependencyStatus.Available) + if (DependencyStatus == DependencyStatus.Available) { + _isReady = true; InitializeFirebaseComp(); callback?.Invoke(); } diff --git a/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs b/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs index 847628f..9778fa0 100644 --- a/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs +++ b/Runtime/GuruIAP/Runtime/Code/IAPServiceBase.cs @@ -147,6 +147,7 @@ namespace Guru ProductSetting item; IDs ids; + bool emptyIDs = false; for (int i = 0; i < len; i++) { item = settings[i]; @@ -155,12 +156,32 @@ namespace Guru { ids.Add(item.GooglePlayProductId, GooglePlay.Name); } + else + { +#if UNITY_ADNROID + emptyIDs = true; + LogE($"[IAP] --- GoogleProductId is empty, please check the product setting: {item.ProductName}"); +#endif + } + if (!string.IsNullOrEmpty(item.AppStoreProductId)) { ids.Add(item.AppStoreProductId, AppleAppStore.Name); } + else + { +#if UNITY_IOS + emptyIDs = true; + LogE($"[IAP] --- AppleProductId is empty, please check the product setting: {item.ProductName}"); +#endif + } + if (emptyIDs) + { + continue; + } + _configBuilder.AddProduct(item.ProductId, item.Type, ids); // 添加商品 // 建立本地的商品信息列表 diff --git a/Runtime/GuruIAP/Runtime/Code/Settings/GuruSettings.IAP.cs b/Runtime/GuruIAP/Runtime/Code/Settings/GuruSettings.IAP.cs index b2b65b1..d6555a2 100644 --- a/Runtime/GuruIAP/Runtime/Code/Settings/GuruSettings.IAP.cs +++ b/Runtime/GuruIAP/Runtime/Code/Settings/GuruSettings.IAP.cs @@ -7,7 +7,6 @@ namespace Guru /// public partial class GuruSettings { - [Header("IAP 商品配置")] public ProductSetting[] Products;