根据IvRules判断是否可以展示插屏
This commit is contained in:
parent
3e2a9d42f9
commit
e166aa143f
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -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; //广告最小时间间隔
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c6b65276a19841fdbf20d1ed0aa81ec4
|
||||||
|
timeCreated: 1756695913
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Script.Common
|
||||||
|
{
|
||||||
|
[System.Serializable]
|
||||||
|
public class RevenueData
|
||||||
|
{
|
||||||
|
public string name;
|
||||||
|
public int rate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -48,7 +48,7 @@ public class AdjustTrackEvent : NormalSingleton<AdjustTrackEvent>
|
||||||
{
|
{
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
var revenueAdjs = JsonConvert.DeserializeObject<RevenueAdjItem[]>(json);
|
var revenueAdjs = JsonConvert.DeserializeObject<RevenueData[]>(json);
|
||||||
if (revenueAdjs == null && revenueAdjs.Length == 0)
|
if (revenueAdjs == null && revenueAdjs.Length == 0)
|
||||||
{
|
{
|
||||||
return source;
|
return source;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Firebase.RemoteConfig;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Script.Common;
|
using Script.Common;
|
||||||
using Script.SDKManager.AdsSDKManager.AdmobAdsManager;
|
using Script.SDKManager.AdsSDKManager.AdmobAdsManager;
|
||||||
using Script.SDKManager.AdsSDKManager.BigoAdsManager;
|
using Script.SDKManager.AdsSDKManager.BigoAdsManager;
|
||||||
|
|
@ -289,9 +291,11 @@ public class AdsSDKManager : NormalSingleton<AdsSDKManager>
|
||||||
{
|
{
|
||||||
case AdsType.Rewarded:
|
case AdsType.Rewarded:
|
||||||
// todo: 刷新激励广告
|
// todo: 刷新激励广告
|
||||||
|
KwaiAdsManager.Instance.LoadRewardAd();
|
||||||
break;
|
break;
|
||||||
case AdsType.Interstitial:
|
case AdsType.Interstitial:
|
||||||
// todo: 刷新插屏广告
|
// todo: 刷新插屏广告
|
||||||
|
KwaiAdsManager.Instance.LoadInterstitialAd();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -306,4 +310,67 @@ public class AdsSDKManager : NormalSingleton<AdsSDKManager>
|
||||||
AdRewardCallback?.Invoke(price);
|
AdRewardCallback?.Invoke(price);
|
||||||
AdRewardCallback = null;
|
AdRewardCallback = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据IvRules判断是否可以展示插屏
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool IvRulesShow(IvType ivadType)
|
||||||
|
{
|
||||||
|
//1.获取远程配置
|
||||||
|
string json = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("IV_RULES");
|
||||||
|
if (string.IsNullOrEmpty(json))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//2.解析配置
|
||||||
|
var dates = JsonConvert.DeserializeObject<IvRulesData[]>(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Script.Common;
|
||||||
|
using Script.SDKManager.AdsSDKManager.Constant;
|
||||||
|
using Script.Utils;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class AppSDKManager : MonoBehaviour
|
public class AppSDKManager : MonoBehaviour
|
||||||
|
|
@ -17,7 +21,6 @@ public class AppSDKManager : MonoBehaviour
|
||||||
AdjustManager.Instance.Init();
|
AdjustManager.Instance.Init();
|
||||||
ShuShuMangage.Instance.Init();
|
ShuShuMangage.Instance.Init();
|
||||||
AdsSDKManager.Instance.InitSDK();
|
AdsSDKManager.Instance.InitSDK();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -28,4 +31,33 @@ public class AppSDKManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
StartCoroutine(coroutine);
|
StartCoroutine(coroutine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShowInterstitial(string position, IvType ivadType = IvType.IV1, Action<double> 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<double> callback = null)
|
||||||
|
{
|
||||||
|
bool isRewardAdReady = AdsSDKManager.Instance.IsRewardAdReady();
|
||||||
|
if (isRewardAdReady)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ public class FireBaseAnalyticsManager : NormalSingleton<FireBaseAnalyticsManager
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
var revenueAdjs = JsonConvert.DeserializeObject<RevenueAdjItem[]>(json);
|
var revenueAdjs = JsonConvert.DeserializeObject<RevenueData[]>(json);
|
||||||
if (revenueAdjs == null && revenueAdjs.Length == 0)
|
if (revenueAdjs == null && revenueAdjs.Length == 0)
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2de9cb6fc3ca46bd9ece75b1a6fe337e
|
||||||
|
timeCreated: 1756698647
|
||||||
Loading…
Reference in New Issue