2025-08-30 04:15:48 +00:00
|
|
|
|
using System;
|
2025-09-12 07:56:39 +00:00
|
|
|
|
using System.Collections;
|
2025-08-31 05:15:14 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2025-09-01 05:59:06 +00:00
|
|
|
|
using Firebase.RemoteConfig;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2025-08-30 04:15:48 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2025-09-01 10:32:50 +00:00
|
|
|
|
namespace WZ
|
2025-08-30 04:15:48 +00:00
|
|
|
|
{
|
2025-09-02 09:14:49 +00:00
|
|
|
|
public class AdsSDKManager : D_MonoSingleton<AdsSDKManager>
|
2025-08-30 04:15:48 +00:00
|
|
|
|
{
|
2025-09-01 10:32:50 +00:00
|
|
|
|
// 是否有激励视频或者插屏广告在展示
|
|
|
|
|
|
public bool otherAdsOnShow = false;
|
2025-11-03 07:58:12 +00:00
|
|
|
|
public void InitSDK()
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2025-09-02 13:42:07 +00:00
|
|
|
|
LoggerUtils.Debug("init ads sdk");
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
2025-08-31 07:12:52 +00:00
|
|
|
|
|
2026-01-04 10:20:54 +00:00
|
|
|
|
|
2025-09-01 15:29:31 +00:00
|
|
|
|
#region 激励视频广告
|
2026-01-06 03:04:34 +00:00
|
|
|
|
public bool IsRewardAdReady(PlatformType _platformType)
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2026-01-06 03:04:34 +00:00
|
|
|
|
if(_platformType == PlatformType.Admob)
|
|
|
|
|
|
{
|
|
|
|
|
|
return AdmobAdsManager.Instance.IsRewardedAvailable();
|
|
|
|
|
|
}
|
|
|
|
|
|
return TpnAdsManager.Instance.IsRewardedAvailable();
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
2025-09-01 10:32:50 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 展示激励广告
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="callback"></param>
|
2026-01-06 03:04:34 +00:00
|
|
|
|
public void ShowRewardAd(string _adPos, Action<bool, double> _rewardCallback, Action _showFailedCallback,PlatformType _platformType)
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2026-01-06 03:04:34 +00:00
|
|
|
|
LoggerUtils.Debug("ShowRewardAd _adPos:"+_adPos+" ready:"+IsRewardAdReady(_platformType));
|
2025-09-02 10:11:18 +00:00
|
|
|
|
otherAdsOnShow = true;
|
2025-09-04 09:19:05 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Rewarded,AdPlayCountManager.PLAY_COUNT_SUFFIX);
|
2026-01-06 08:29:08 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Rewarded,_adPos+AdPlayCountManager.POS_SUFFIX);
|
|
|
|
|
|
|
2025-09-02 13:57:18 +00:00
|
|
|
|
AdjustTrackEvent.Instance.TrackEventName("RV_Show", new Dictionary<string, object>());
|
2026-01-06 03:04:34 +00:00
|
|
|
|
if(_platformType == PlatformType.Admob)
|
|
|
|
|
|
{
|
|
|
|
|
|
AdmobAdsManager.Instance.DisplayRewarded(_adPos,_rewardCallback,_showFailedCallback);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
TpnAdsManager.Instance.DisplayRewarded(_adPos,_rewardCallback,_showFailedCallback);
|
|
|
|
|
|
}
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
2025-09-01 15:29:31 +00:00
|
|
|
|
#endregion
|
2025-09-01 10:32:50 +00:00
|
|
|
|
|
2025-09-01 15:29:31 +00:00
|
|
|
|
#region 插屏广告
|
2026-01-06 03:04:34 +00:00
|
|
|
|
public bool IsInterstitialReady(PlatformType _platformType)
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2026-01-06 03:04:34 +00:00
|
|
|
|
if(_platformType == PlatformType.Admob)
|
|
|
|
|
|
{
|
|
|
|
|
|
return AdmobAdsManager.Instance.IsInterstitialAvailable();
|
|
|
|
|
|
}
|
|
|
|
|
|
return TpnAdsManager.Instance.IsInterstitialAvailable();
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-01 10:32:50 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 展示激励广告
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="callback"></param>
|
2026-01-06 03:04:34 +00:00
|
|
|
|
public void ShowInterstitialAd(string _adPos, IvType _IvType, Action<double> _closeCallback,PlatformType _platformType)
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2025-09-02 09:14:49 +00:00
|
|
|
|
AdsSDKManager.Instance.otherAdsOnShow = true;
|
2025-09-04 09:19:05 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Interstitial,AdPlayCountManager.PLAY_COUNT_SUFFIX);
|
2026-01-06 08:29:08 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Interstitial,_adPos+AdPlayCountManager.POS_SUFFIX);
|
2025-09-02 13:57:18 +00:00
|
|
|
|
AdjustTrackEvent.Instance.TrackEventName("IV_Show", new Dictionary<string, object>());
|
2026-01-04 10:20:54 +00:00
|
|
|
|
|
2026-01-06 03:04:34 +00:00
|
|
|
|
if(_platformType == PlatformType.Admob)
|
|
|
|
|
|
{
|
|
|
|
|
|
AdmobAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
TpnAdsManager.Instance.DisplayInterstitial(_adPos, _IvType, _closeCallback);
|
|
|
|
|
|
}
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
2025-09-08 08:36:59 +00:00
|
|
|
|
|
2025-09-01 15:29:31 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 横幅广告
|
2026-01-06 03:04:34 +00:00
|
|
|
|
public bool IsBannerAdReady(BannerType bannerType,PlatformType platformType)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2026-01-06 03:04:34 +00:00
|
|
|
|
if(platformType == PlatformType.Admob)
|
|
|
|
|
|
{
|
|
|
|
|
|
return AdmobAdsManager.Instance.IsBannerAvailable(bannerType);
|
|
|
|
|
|
}else
|
|
|
|
|
|
{
|
|
|
|
|
|
return TpnAdsManager.Instance.IsBannerAvailable();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-01 15:29:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-06 03:04:34 +00:00
|
|
|
|
public void ShowBanner(BannerType bannerType,BannerAlignType bannerAlignType,PlatformType platformType)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2026-01-06 03:04:34 +00:00
|
|
|
|
|
2025-09-04 09:19:05 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Banner,AdPlayCountManager.PLAY_COUNT_SUFFIX);
|
2026-01-06 08:29:08 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Rewarded, "Banner"+AdPlayCountManager.POS_SUFFIX);
|
2025-09-03 11:58:43 +00:00
|
|
|
|
AdjustTrackEvent.Instance.TrackEventName("Banner_Show", new Dictionary<string, object>());
|
2026-01-06 03:04:34 +00:00
|
|
|
|
if (platformType == PlatformType.Admob)
|
|
|
|
|
|
{
|
|
|
|
|
|
AdmobAdsManager.Instance.DisplayBanner(bannerType,bannerAlignType);
|
|
|
|
|
|
}else
|
|
|
|
|
|
{
|
|
|
|
|
|
TpnAdsManager.Instance.ShowBanner();
|
|
|
|
|
|
}
|
2025-09-01 15:29:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-16 13:29:51 +00:00
|
|
|
|
public void HideBanner(BannerType bannerType)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2025-09-16 13:29:51 +00:00
|
|
|
|
AdmobAdsManager.Instance.HideBanner(bannerType);
|
2026-01-06 03:04:34 +00:00
|
|
|
|
TpnAdsManager.Instance.HideBanner();
|
2025-09-01 15:29:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region 原生广告
|
2025-09-02 02:07:10 +00:00
|
|
|
|
public bool IsNativeAdReady(string adUnitId)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2025-09-02 02:07:10 +00:00
|
|
|
|
return AdmobAdsManager.Instance.IsNativeAvailable(adUnitId);
|
2025-09-01 15:29:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-06 08:29:08 +00:00
|
|
|
|
public void ShowNativeAd(string _adPos, string adUnitId, NativeAdPosition position,NativeType nativeType)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2026-01-06 08:29:08 +00:00
|
|
|
|
AdmobAdsManager.Instance.DisplayNative(_adPos, adUnitId, position, nativeType);
|
2025-09-03 11:58:43 +00:00
|
|
|
|
AdjustTrackEvent.Instance.TrackEventName("NA_Show", new Dictionary<string, object>());
|
2025-09-04 09:19:05 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Native,AdPlayCountManager.PLAY_COUNT_SUFFIX);
|
2026-01-06 08:29:08 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Native,_adPos+AdPlayCountManager.POS_SUFFIX);
|
2025-09-01 15:29:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-02 02:07:10 +00:00
|
|
|
|
public void RemoveNativeAd(string adUnitId)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2025-09-02 02:07:10 +00:00
|
|
|
|
AdmobAdsManager.Instance.RemoveNative(adUnitId);
|
2025-09-01 15:29:31 +00:00
|
|
|
|
}
|
2025-09-08 08:36:59 +00:00
|
|
|
|
|
|
|
|
|
|
public double GetNativeAdRevenue(string adUnitId)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!IsNativeAdReady(adUnitId))
|
|
|
|
|
|
{
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
}
|
|
|
|
|
|
return AdmobAdsManager.Instance.GetNativeRevenue(adUnitId);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-01 15:29:31 +00:00
|
|
|
|
#endregion
|
2025-08-31 07:12:52 +00:00
|
|
|
|
|
2025-09-01 10:32:50 +00:00
|
|
|
|
#region 开屏广告
|
|
|
|
|
|
public bool IsSplashAvailable()
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2026-01-06 03:51:50 +00:00
|
|
|
|
return AdmobAdsManager.Instance.IsSplashAvailable() && TransferAndroidClass.IsVpnConnected();
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
2025-09-01 10:32:50 +00:00
|
|
|
|
|
|
|
|
|
|
public void ShowSplashAd()
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2025-09-02 13:57:18 +00:00
|
|
|
|
AdjustTrackEvent.Instance.TrackEventName("SP_Show", new Dictionary<string, object>());
|
2025-09-04 09:19:05 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Splash,AdPlayCountManager.PLAY_COUNT_SUFFIX);
|
2026-01-06 08:29:08 +00:00
|
|
|
|
AdPlayCountManager.IncrementAdsActionCount(AdsType.Splash,"Splash"+AdPlayCountManager.POS_SUFFIX);
|
2025-09-01 10:32:50 +00:00
|
|
|
|
AdmobAdsManager.Instance.DisplaySplash();
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
2025-09-01 10:32:50 +00:00
|
|
|
|
|
|
|
|
|
|
public void LoadSplashAd()
|
2025-08-31 05:15:14 +00:00
|
|
|
|
{
|
2025-09-01 10:32:50 +00:00
|
|
|
|
AdmobAdsManager.Instance.LoadSplash();
|
2025-08-31 05:15:14 +00:00
|
|
|
|
}
|
2025-09-01 10:32:50 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2026-01-04 10:20:54 +00:00
|
|
|
|
|
2025-08-31 05:15:14 +00:00
|
|
|
|
|
2025-09-02 06:20:54 +00:00
|
|
|
|
#region IvRules
|
2025-09-02 06:29:21 +00:00
|
|
|
|
|
2025-09-18 07:03:56 +00:00
|
|
|
|
public bool IvRulesShow(IvType ivadType, bool isShow = true)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2025-09-03 14:11:37 +00:00
|
|
|
|
//1.获取远程配置
|
2026-01-06 03:51:50 +00:00
|
|
|
|
string json = FireBaseRemoteConfigManager.Instance.GetRemoteConfigString("AD_Game");
|
2025-09-04 08:50:26 +00:00
|
|
|
|
if (string.IsNullOrEmpty(json))
|
|
|
|
|
|
{
|
|
|
|
|
|
LoggerUtils.Debug("[SDK] 获取远程配置IV_RULES是空 没有限制");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//2.解析配置
|
|
|
|
|
|
var dates = JsonConvert.DeserializeObject<IvRulesData[]>(json);
|
|
|
|
|
|
if (dates == null && dates.Length == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoggerUtils.Debug("[SDK] 获取远程配置信息是空");
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//3.获取IVADType对应的配置
|
2025-09-01 15:29:31 +00:00
|
|
|
|
IvRulesData ivRulesData = null;
|
|
|
|
|
|
foreach (var data in dates)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (data.type == (int)ivadType)
|
|
|
|
|
|
{
|
|
|
|
|
|
ivRulesData = data;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (ivRulesData == null)
|
|
|
|
|
|
{
|
2025-09-03 14:11:37 +00:00
|
|
|
|
LoggerUtils.Debug("[SDK] 远程配置没有配置对应的IvType");
|
2025-09-01 15:29:31 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//4.判断skip(次安装跳过几次触发不展示广告)
|
|
|
|
|
|
int skipLevel = ivRulesData.skipLevel;
|
2025-09-02 06:20:54 +00:00
|
|
|
|
int currentSkipLevel = PlayerPrefsUtils.GetPlayerPrefsInt($"{IvRulesKey.KEY_SKIPLEVEL}_{ivadType.ToString()}", 0);
|
2025-09-04 08:50:26 +00:00
|
|
|
|
LoggerUtils.Debug($"[SDK] {ivadType.ToString()} 前N次不展示插屏, 本地次数是{currentSkipLevel + 1}, 远程参数是{skipLevel}");
|
2025-09-01 15:29:31 +00:00
|
|
|
|
if (currentSkipLevel < skipLevel)
|
|
|
|
|
|
{
|
2025-09-18 07:03:56 +00:00
|
|
|
|
if (isShow)
|
|
|
|
|
|
{
|
|
|
|
|
|
PlayerPrefsUtils.SavePlayerPrefsInt($"{IvRulesKey.KEY_SKIPLEVEL}_{ivadType.ToString()}", currentSkipLevel + 1);
|
|
|
|
|
|
}
|
2025-09-01 15:29:31 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-09-04 08:50:26 +00:00
|
|
|
|
//5.判断overLevel(每跳过几次触发) 第一次会展示 之后每展示一次间隔+1
|
2025-09-01 15:29:31 +00:00
|
|
|
|
int overLevel = ivRulesData.overLevel;
|
2025-09-02 06:20:54 +00:00
|
|
|
|
int currentOverLevel = IvRulesConst.OverLevels.ContainsKey(ivadType.ToString()) ? IvRulesConst.OverLevels[ivadType.ToString()] : 0;
|
2025-09-04 08:50:26 +00:00
|
|
|
|
LoggerUtils.Debug($"[SDK] {ivadType.ToString()} 当前间隔次数: 本地次数是{currentOverLevel + 1}, 远程参数是{overLevel}");
|
|
|
|
|
|
if (currentOverLevel != 0)
|
2025-09-01 15:29:31 +00:00
|
|
|
|
{
|
2025-09-18 07:03:56 +00:00
|
|
|
|
if (isShow)
|
2025-09-04 08:50:26 +00:00
|
|
|
|
{
|
2025-09-18 07:03:56 +00:00
|
|
|
|
if (currentOverLevel >= overLevel)
|
|
|
|
|
|
{
|
|
|
|
|
|
IvRulesConst.OverLevels[ivadType.ToString()] = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
IvRulesConst.OverLevels[ivadType.ToString()] += 1;
|
|
|
|
|
|
}
|
2025-09-04 08:50:26 +00:00
|
|
|
|
}
|
2025-09-18 07:03:56 +00:00
|
|
|
|
|
2025-09-01 15:29:31 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//6.判断interval(广告时间间隔)
|
|
|
|
|
|
int interval = ivRulesData.interval;
|
2025-09-02 06:20:54 +00:00
|
|
|
|
long currentInterval = IvRulesConst.Intervals.ContainsKey(ivadType.ToString()) ? IvRulesConst.Intervals[ivadType.ToString()] : 0;
|
2025-09-01 15:29:31 +00:00
|
|
|
|
long localTimestamp = TimeUtils.GetLocalTimestamp();
|
2025-09-03 14:11:37 +00:00
|
|
|
|
LoggerUtils.Debug($"[SDK] {ivadType.ToString()} 远程参数是: {interval}, CanShowFlag: {localTimestamp > (currentInterval + (interval * 1000L))}");
|
2025-09-01 15:29:31 +00:00
|
|
|
|
if (localTimestamp < currentInterval + (interval * 1000L))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-09-04 08:50:26 +00:00
|
|
|
|
|
|
|
|
|
|
return true;
|
2025-09-01 15:29:31 +00:00
|
|
|
|
}
|
2025-09-02 06:20:54 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 看激励广告之后调用
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ClearIvRules()
|
|
|
|
|
|
{
|
|
|
|
|
|
var localTimestamp = TimeUtils.GetLocalTimestamp();
|
|
|
|
|
|
foreach (var key in IvRulesConst.Intervals.Keys.ToList())
|
|
|
|
|
|
{
|
|
|
|
|
|
IvRulesConst.Intervals[key] = localTimestamp;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-02 06:29:21 +00:00
|
|
|
|
|
2025-09-02 06:20:54 +00:00
|
|
|
|
#endregion
|
2025-09-02 06:29:21 +00:00
|
|
|
|
|
2025-09-01 15:29:31 +00:00
|
|
|
|
|
2025-09-01 05:59:06 +00:00
|
|
|
|
}
|
2025-09-01 10:32:50 +00:00
|
|
|
|
}
|