From e166aa143f3512baed6abd6e0519988d82b65edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=89=E5=B3=B0?= Date: Mon, 1 Sep 2025 13:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AEIvRules=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=8F=AF=E4=BB=A5=E5=B1=95=E7=A4=BA=E6=8F=92?= =?UTF-8?q?=E5=B1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Script/Common/CommonData.cs | 15 ----- Assets/Script/Common/IvRulesData.cs | 25 +++++++ Assets/Script/Common/IvRulesData.cs.meta | 3 + Assets/Script/Common/RevenueData.cs | 9 +++ ...CommonData.cs.meta => RevenueData.cs.meta} | 0 .../AdjustManager/AdjustTrackEvent.cs | 2 +- .../SDKManager/AdsSDKManager/AdsSDKManager.cs | 67 +++++++++++++++++++ Assets/Script/SDKManager/AppSDKManager.cs | 34 +++++++++- .../FireBaseAnalyticsManager.cs | 2 +- Assets/Script/Utils/TimeUtils.cs | 34 ++++++++++ Assets/Script/Utils/TimeUtils.cs.meta | 3 + 11 files changed, 176 insertions(+), 18 deletions(-) delete mode 100644 Assets/Script/Common/CommonData.cs create mode 100644 Assets/Script/Common/IvRulesData.cs create mode 100644 Assets/Script/Common/IvRulesData.cs.meta create mode 100644 Assets/Script/Common/RevenueData.cs rename Assets/Script/Common/{CommonData.cs.meta => RevenueData.cs.meta} (100%) create mode 100644 Assets/Script/Utils/TimeUtils.cs create mode 100644 Assets/Script/Utils/TimeUtils.cs.meta diff --git a/Assets/Script/Common/CommonData.cs b/Assets/Script/Common/CommonData.cs deleted file mode 100644 index cd9bed2..0000000 --- a/Assets/Script/Common/CommonData.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Script.Common -{ - [System.Serializable] - public class RevenueAdjItem - { - public string name; - public int rate; - } - - [System.Serializable] - public class RevenueAdj - { - public RevenueAdjItem[] tevenueAdjs; - } -} \ No newline at end of file diff --git a/Assets/Script/Common/IvRulesData.cs b/Assets/Script/Common/IvRulesData.cs new file mode 100644 index 0000000..51d21d4 --- /dev/null +++ b/Assets/Script/Common/IvRulesData.cs @@ -0,0 +1,25 @@ +using System; + +namespace Script.Common +{ + [System.Serializable] + public class IvRulesData + { + public int type; + public int overLevel; //每跳过几次触发 + public int interval; //广告最小时间间隔 + public int skipLevel; //首次安装跳过几次触发不展示广告 + } + + public static class IvRulesKey + { + //首次安装跳过几次触发不展示广告 + public const string KEY_SKIPLEVEL = "KEY_IVRULES_SKIPLEVEL"; + } + + public static class IvRulesConst + { + public static int CurrentOverLevel = 0; //每跳过几次触发 + public static long CurrentInterval = 0; //广告最小时间间隔 + } +} \ No newline at end of file diff --git a/Assets/Script/Common/IvRulesData.cs.meta b/Assets/Script/Common/IvRulesData.cs.meta new file mode 100644 index 0000000..b3aad55 --- /dev/null +++ b/Assets/Script/Common/IvRulesData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c6b65276a19841fdbf20d1ed0aa81ec4 +timeCreated: 1756695913 \ No newline at end of file diff --git a/Assets/Script/Common/RevenueData.cs b/Assets/Script/Common/RevenueData.cs new file mode 100644 index 0000000..9e3026b --- /dev/null +++ b/Assets/Script/Common/RevenueData.cs @@ -0,0 +1,9 @@ +namespace Script.Common +{ + [System.Serializable] + public class RevenueData + { + public string name; + public int rate; + } +} \ No newline at end of file diff --git a/Assets/Script/Common/CommonData.cs.meta b/Assets/Script/Common/RevenueData.cs.meta similarity index 100% rename from Assets/Script/Common/CommonData.cs.meta rename to Assets/Script/Common/RevenueData.cs.meta diff --git a/Assets/Script/SDKManager/AdjustManager/AdjustTrackEvent.cs b/Assets/Script/SDKManager/AdjustManager/AdjustTrackEvent.cs index e89535f..db74554 100644 --- a/Assets/Script/SDKManager/AdjustManager/AdjustTrackEvent.cs +++ b/Assets/Script/SDKManager/AdjustManager/AdjustTrackEvent.cs @@ -48,7 +48,7 @@ public class AdjustTrackEvent : NormalSingleton { return source; } - var revenueAdjs = JsonConvert.DeserializeObject(json); + var revenueAdjs = JsonConvert.DeserializeObject(json); if (revenueAdjs == null && revenueAdjs.Length == 0) { return source; diff --git a/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs b/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs index 07dc342..cebad05 100644 --- a/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs +++ b/Assets/Script/SDKManager/AdsSDKManager/AdsSDKManager.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using Firebase.RemoteConfig; +using Newtonsoft.Json; using Script.Common; using Script.SDKManager.AdsSDKManager.AdmobAdsManager; using Script.SDKManager.AdsSDKManager.BigoAdsManager; @@ -289,9 +291,11 @@ public class AdsSDKManager : NormalSingleton { case AdsType.Rewarded: // todo: 刷新激励广告 + KwaiAdsManager.Instance.LoadRewardAd(); break; case AdsType.Interstitial: // todo: 刷新插屏广告 + KwaiAdsManager.Instance.LoadInterstitialAd(); break; default: break; @@ -306,4 +310,67 @@ public class AdsSDKManager : NormalSingleton AdRewardCallback?.Invoke(price); AdRewardCallback = null; } + + /// + /// 根据IvRules判断是否可以展示插屏 + /// + /// + public bool IvRulesShow(IvType ivadType) + { + //1.获取远程配置 + string json = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("IV_RULES"); + if (string.IsNullOrEmpty(json)) + { + return true; + } + //2.解析配置 + var dates = JsonConvert.DeserializeObject(json); + if (dates == null && dates.Length == 0) + { + return true; + } + //3.获取IVADType对应的配置 + IvRulesData ivRulesData = null; + foreach (var data in dates) + { + if (data.type == (int)ivadType) + { + ivRulesData = data; + } + } + if (ivRulesData == null) + { + return true; + } + //4.判断skip(次安装跳过几次触发不展示广告) + int skipLevel = ivRulesData.skipLevel; + int currentSkipLevel = PlayerPrefsUtils.GetPlayerPrefsInt(IvRulesKey.KEY_SKIPLEVEL, 0); + LoggerUtils.Debug($"[SDK] skipLevel is {skipLevel}, currentSkipLevel is {currentSkipLevel}"); + if (currentSkipLevel < skipLevel) + { + PlayerPrefsUtils.SavePlayerPrefsInt(IvRulesKey.KEY_SKIPLEVEL, currentSkipLevel + 1); + return false; + } + //5.判断overLevel(没跳过几次触发) + int overLevel = ivRulesData.overLevel; + int currentOverLevel = IvRulesConst.CurrentOverLevel; + LoggerUtils.Debug($"[SDK] overLevel is {overLevel}, currentOverLevel is {currentOverLevel}"); + if (currentOverLevel < overLevel) + { + IvRulesConst.CurrentOverLevel++; + return false; + } + + //6.判断interval(广告时间间隔) + int interval = ivRulesData.interval; + long currentInterval = IvRulesConst.CurrentInterval; + long localTimestamp = TimeUtils.GetLocalTimestamp(); + LoggerUtils.Debug($"[SDK] interval is {interval}, currentInterval is {currentInterval}, localTimestamp is {localTimestamp}"); + if (localTimestamp < currentInterval + (interval * 1000L)) + { + return false; + } + + return true; + } } diff --git a/Assets/Script/SDKManager/AppSDKManager.cs b/Assets/Script/SDKManager/AppSDKManager.cs index 9b4a483..f96c27b 100644 --- a/Assets/Script/SDKManager/AppSDKManager.cs +++ b/Assets/Script/SDKManager/AppSDKManager.cs @@ -1,5 +1,9 @@ +using System; using System.Collections; using System.Collections.Generic; +using Script.Common; +using Script.SDKManager.AdsSDKManager.Constant; +using Script.Utils; using UnityEngine; public class AppSDKManager : MonoBehaviour @@ -17,7 +21,6 @@ public class AppSDKManager : MonoBehaviour AdjustManager.Instance.Init(); ShuShuMangage.Instance.Init(); AdsSDKManager.Instance.InitSDK(); - } /// @@ -28,4 +31,33 @@ public class AppSDKManager : MonoBehaviour { StartCoroutine(coroutine); } + + public void ShowInterstitial(string position, IvType ivadType = IvType.IV1, Action callback = null) + { + //插屏展示逻辑 + bool ivRulesShow = AdsSDKManager.Instance.IvRulesShow(ivadType); + if (ivRulesShow) + { + //是否有缓存 + bool isInterstitialReady = AdsSDKManager.Instance.IsInterstitialReady(); + if (isInterstitialReady) + { + AdsSDKManager.Instance.ShowInterstitialAd(position, ivadType, () => + { + //展示完一个插屏之后调用 + IvRulesConst.CurrentOverLevel = 0; + IvRulesConst.CurrentInterval = TimeUtils.GetLocalTimestamp(); + }); + } + } + } + + public void ShowRewardAd(string position, string videoId, Action callback = null) + { + bool isRewardAdReady = AdsSDKManager.Instance.IsRewardAdReady(); + if (isRewardAdReady) + { + + } + } } diff --git a/Assets/Script/SDKManager/FirebaseManager/FireBaseAnalyticsManager.cs b/Assets/Script/SDKManager/FirebaseManager/FireBaseAnalyticsManager.cs index d4f21ef..0938c1b 100644 --- a/Assets/Script/SDKManager/FirebaseManager/FireBaseAnalyticsManager.cs +++ b/Assets/Script/SDKManager/FirebaseManager/FireBaseAnalyticsManager.cs @@ -93,7 +93,7 @@ public class FireBaseAnalyticsManager : NormalSingleton(json); + var revenueAdjs = JsonConvert.DeserializeObject(json); if (revenueAdjs == null && revenueAdjs.Length == 0) { return name; diff --git a/Assets/Script/Utils/TimeUtils.cs b/Assets/Script/Utils/TimeUtils.cs new file mode 100644 index 0000000..a94b203 --- /dev/null +++ b/Assets/Script/Utils/TimeUtils.cs @@ -0,0 +1,34 @@ +using System; + +namespace Script.Utils +{ + public class TimeUtils + { + #region 本地时间 + + // 获取当前本地时间的毫秒级时间戳 + public static long GetLocalTimestamp() + { + DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local); + TimeSpan diff = GetNowDateTime() - origin; + return (long)diff.TotalMilliseconds; + } + + public static DateTime TimestampToLocalDateTime(long timestamp) + { + // 以UTC时间为基准计算(避免时区转换问题) + DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local); + DateTime utcDateTime = origin.AddMilliseconds(timestamp); + + // 转换为本地时间 + return utcDateTime.ToLocalTime(); + } + + public static DateTime GetNowDateTime() + { + return DateTime.Now; + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Script/Utils/TimeUtils.cs.meta b/Assets/Script/Utils/TimeUtils.cs.meta new file mode 100644 index 0000000..ae063db --- /dev/null +++ b/Assets/Script/Utils/TimeUtils.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2de9cb6fc3ca46bd9ece75b1a6fe337e +timeCreated: 1756698647 \ No newline at end of file