2025-08-31 02:12:10 +00:00
|
|
|
|
using System;
|
2025-08-30 13:48:51 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2025-09-01 03:39:21 +00:00
|
|
|
|
using System.Linq;
|
2025-08-31 12:48:14 +00:00
|
|
|
|
using System.Net.Security;
|
|
|
|
|
using Firebase.Analytics;
|
2025-08-30 13:48:51 +00:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2025-09-01 10:32:50 +00:00
|
|
|
|
namespace WZ
|
2025-08-30 13:48:51 +00:00
|
|
|
|
{
|
2025-09-02 09:14:49 +00:00
|
|
|
|
public class MaxAdsManager : D_MonoSingleton<MaxAdsManager>, IAdService
|
2025-08-30 13:48:51 +00:00
|
|
|
|
{
|
2025-08-31 12:48:14 +00:00
|
|
|
|
public string ClientName => "AppLovin";
|
2025-09-01 07:14:26 +00:00
|
|
|
|
public PlatformType Platfrom => PlatformType.AppLovin;
|
2025-09-01 12:53:08 +00:00
|
|
|
|
private string _max_app_key;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
// 广告单元ID字典,支持多个广告位
|
|
|
|
|
private List<string> _maxInterstitialUnits = new List<string>();
|
|
|
|
|
private List<string> _maxRewardedUnits = new List<string>();
|
|
|
|
|
// 广告信息字典,按广告位存储
|
|
|
|
|
private Dictionary<string, MaxSdkBase.AdInfo> _interAdInfos = new Dictionary<string, MaxSdkBase.AdInfo>();
|
|
|
|
|
private Dictionary<string, MaxSdkBase.AdInfo> _rewardAdInfos = new Dictionary<string, MaxSdkBase.AdInfo>();
|
|
|
|
|
// 重试次数字典,按广告位存储
|
|
|
|
|
private Dictionary<string, int> _rewardRetryAttempts = new Dictionary<string, int>();
|
|
|
|
|
private Dictionary<string, int> _interRetryAttempts = new Dictionary<string, int>();
|
|
|
|
|
// 加载时间字典,按广告位存储
|
|
|
|
|
private Dictionary<string, float> _rvStartLoadTimes = new Dictionary<string, float>();
|
|
|
|
|
private Dictionary<string, float> _ivStartLoadTimes = new Dictionary<string, float>();
|
2025-08-31 05:15:14 +00:00
|
|
|
|
private string _rvPos;
|
|
|
|
|
private string _ivPos;
|
2025-09-01 14:14:33 +00:00
|
|
|
|
private Action<bool,double> _rvCloseCallback = null;
|
|
|
|
|
private Action<double> _ivCloseCallback = null;
|
2025-08-31 05:15:14 +00:00
|
|
|
|
private Action _rvShowFailedCallback = null;
|
2025-09-02 15:25:00 +00:00
|
|
|
|
public bool _initialized { get; private set; } = false;
|
2025-09-03 11:58:43 +00:00
|
|
|
|
private bool _receivedReward = false;
|
2025-08-31 02:12:10 +00:00
|
|
|
|
public void Initialize()
|
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
|
|
|
|
|
_max_app_key = AdConfigParser.GetMaxAppKey();
|
2025-09-02 15:25:00 +00:00
|
|
|
|
if (string.IsNullOrEmpty(_max_app_key) || _initialized) return;
|
2025-08-31 02:12:10 +00:00
|
|
|
|
LoggerUtils.Debug("[Max] init max");
|
|
|
|
|
// 关闭反转debug面板
|
|
|
|
|
MaxSdk.SetCreativeDebuggerEnabled(false);
|
2025-09-10 12:23:01 +00:00
|
|
|
|
_maxInterstitialUnits = AdConfigParser.GetMaxAdUnits(AdsType.Interstitial);
|
|
|
|
|
_maxRewardedUnits = AdConfigParser.GetMaxAdUnits(AdsType.Rewarded);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
InitRewardedCallback();
|
|
|
|
|
InitInterstitialCallback();
|
|
|
|
|
|
|
|
|
|
MaxSdkCallbacks.OnSdkInitializedEvent += (MaxSdkBase.SdkConfiguration obj) =>
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] init max success");
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
MaxSdk.SetVerboseLogging(false);
|
2025-09-01 12:53:08 +00:00
|
|
|
|
MaxSdk.SetSdkKey(_max_app_key);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
MaxSdk.InitializeSdk();
|
2025-09-10 12:23:01 +00:00
|
|
|
|
|
2025-09-01 07:14:26 +00:00
|
|
|
|
LoadRewarded();
|
|
|
|
|
LoadInterstitial();
|
2025-09-02 15:25:00 +00:00
|
|
|
|
_initialized = true;
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 12:53:08 +00:00
|
|
|
|
public void RefreshAdsData()
|
|
|
|
|
{
|
|
|
|
|
_max_app_key = AdConfigParser.GetMaxAppKey();
|
2025-09-10 12:23:01 +00:00
|
|
|
|
_maxInterstitialUnits = AdConfigParser.GetMaxAdUnits(AdsType.Interstitial);
|
|
|
|
|
_maxRewardedUnits = AdConfigParser.GetMaxAdUnits(AdsType.Rewarded);
|
2025-09-01 12:53:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-31 02:12:10 +00:00
|
|
|
|
#region 激励广告功能
|
|
|
|
|
private void InitRewardedCallback()
|
2025-08-31 12:48:14 +00:00
|
|
|
|
{
|
2025-08-31 02:12:10 +00:00
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdLoadedEvent += OnRewardedAdLoadedEvent;
|
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdLoadFailedEvent += OnRewardedAdLoadFailedEvent;
|
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdDisplayFailedEvent += OnRewardedAdFailedToDisplayEvent;
|
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdDisplayedEvent += OnRewardedAdDisplayedEvent;
|
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdClickedEvent += OnRewardedAdClickedEvent;
|
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdHiddenEvent += OnRewardedAdHiddenEvent;
|
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnRewardedRevenue;
|
2025-09-03 11:58:43 +00:00
|
|
|
|
MaxSdkCallbacks.Rewarded.OnAdReceivedRewardEvent += OnRewardedAdReceivedRewardEvent;
|
2025-08-31 02:12:10 +00:00
|
|
|
|
|
|
|
|
|
}
|
2025-09-10 12:23:01 +00:00
|
|
|
|
|
|
|
|
|
|
2025-08-31 02:12:10 +00:00
|
|
|
|
public void LoadRewarded()
|
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
foreach (var kvp in _maxRewardedUnits)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[MAX] start load rewarded ad unit: "+kvp);
|
|
|
|
|
LoadRewarded(kvp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoadRewarded(string adUnitId)
|
|
|
|
|
{
|
|
|
|
|
if (!_maxRewardedUnits.Contains(adUnitId)) return;
|
|
|
|
|
if (string.IsNullOrEmpty(adUnitId)) return;
|
2025-09-15 05:59:03 +00:00
|
|
|
|
AdsActionEvents.TrackAdStartLoad(Platfrom, AdsType.Rewarded);
|
2025-09-10 12:23:01 +00:00
|
|
|
|
MaxSdk.LoadRewardedAd(adUnitId);
|
|
|
|
|
_rvStartLoadTimes[adUnitId] = Time.realtimeSinceStartup;
|
|
|
|
|
|
|
|
|
|
// 初始化重试次数
|
|
|
|
|
if (!_rewardRetryAttempts.ContainsKey(adUnitId))
|
|
|
|
|
{
|
|
|
|
|
_rewardRetryAttempts[adUnitId] = 0;
|
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
2025-09-10 12:23:01 +00:00
|
|
|
|
|
|
|
|
|
public void DisplayRewarded(string adPos, Action<bool, double> rewardCallback = null, Action showFailedCallback = null)
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
2025-08-31 05:15:14 +00:00
|
|
|
|
_rvPos = adPos;
|
|
|
|
|
_rvCloseCallback = rewardCallback;
|
|
|
|
|
_rvShowFailedCallback = showFailedCallback;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
MaxSdk.ShowRewardedAd(GetHighestPayingAdUnit(AdsType.Rewarded));
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double GetRewardedRevenue()
|
2025-08-31 12:48:14 +00:00
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
return GetHighestPayingAdRevenue(AdsType.Rewarded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private double GetHighestPayingAdRevenue(AdsType adsType)
|
|
|
|
|
{
|
|
|
|
|
var highestPayingAdUnit = GetHighestPayingAdUnit(adsType);
|
|
|
|
|
if (highestPayingAdUnit != null)
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if (adsType == AdsType.Rewarded)
|
|
|
|
|
{
|
|
|
|
|
if (!_rewardAdInfos.TryGetValue(highestPayingAdUnit, out var adInfo))
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return adInfo.Revenue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!_interAdInfos.TryGetValue(highestPayingAdUnit, out var adInfo))
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return adInfo.Revenue;
|
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
2025-09-10 12:23:01 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetHighestPayingAdUnit(AdsType adsType)
|
|
|
|
|
{
|
|
|
|
|
string highestPayingAdUnit = null;
|
|
|
|
|
double highestRevenue = -1;
|
|
|
|
|
|
|
|
|
|
foreach (var kvp in adsType == AdsType.Rewarded ? _rewardAdInfos : _interAdInfos)
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
var adUnitId = kvp.Key;
|
|
|
|
|
var revenue = kvp.Value.Revenue;
|
|
|
|
|
|
|
|
|
|
if (IsAdsAvailable(adUnitId,adsType) && revenue > highestRevenue)
|
|
|
|
|
{
|
|
|
|
|
highestRevenue = revenue;
|
|
|
|
|
highestPayingAdUnit = adUnitId;
|
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
2025-09-10 12:23:01 +00:00
|
|
|
|
return highestPayingAdUnit;
|
2025-08-31 12:48:14 +00:00
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
|
|
|
|
|
public bool IsRewardedAvailable()
|
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
List<string> availableAdUnits = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (var kvp in _maxRewardedUnits)
|
|
|
|
|
{
|
|
|
|
|
if (IsAdsAvailable(kvp, AdsType.Rewarded))
|
|
|
|
|
{
|
|
|
|
|
availableAdUnits.Add(kvp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return availableAdUnits.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool IsAdsAvailable(string adUnit, AdsType adsType)
|
|
|
|
|
{
|
2025-09-18 04:13:12 +00:00
|
|
|
|
if (string.IsNullOrEmpty(adUnit)) return false;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if (adsType == AdsType.Rewarded)
|
|
|
|
|
{
|
|
|
|
|
if (!_maxRewardedUnits.Contains(adUnit)) return false;
|
|
|
|
|
return MaxSdk.IsRewardedAdReady(adUnit);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!_maxInterstitialUnits.Contains(adUnit)) return false;
|
|
|
|
|
return MaxSdk.IsInterstitialReady(adUnit);
|
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedRevenue(string adunit, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedRevenue network: " + adInfo.NetworkName + " revenue: " + adInfo.Revenue + " NetworkPlacement: " + adInfo.NetworkPlacement + " AdUnitIdentifier: " + adInfo.AdUnitIdentifier + " Placement: " + adInfo.Placement);
|
2025-08-31 12:48:14 +00:00
|
|
|
|
TrackAdImpression(adInfo, AdsType.Rewarded);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedAdLoadedEvent(string adunit, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedAdLoadedEvent network: " + adInfo.NetworkName + " revenue: " + adInfo.Revenue + " NetworkPlacement: " + adInfo.NetworkPlacement + " AdUnitIdentifier: " + adInfo.AdUnitIdentifier + " Placement: " + adInfo.Placement);
|
2025-08-31 14:18:31 +00:00
|
|
|
|
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Rewarded);
|
2025-09-10 12:23:01 +00:00
|
|
|
|
_rewardAdInfos.TryAdd(adunit, adInfo);
|
|
|
|
|
_rewardRetryAttempts.TryAdd(adunit, 0);
|
|
|
|
|
AdsActionEvents.TrackAdLoaded(Platfrom, adInfo.NetworkName, adInfo.AdUnitIdentifier, AdsType.Rewarded, Time.realtimeSinceStartup - (_rvStartLoadTimes.TryGetValue(adunit, out var time) ? time : 0));
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedAdLoadFailedEvent(string adunit, MaxSdkBase.ErrorInfo errorInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedAdLoadFailedEvent errorInfo" + errorInfo.Message);
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if (!_rewardRetryAttempts.TryAdd(adunit, 0))
|
|
|
|
|
{
|
|
|
|
|
_rewardRetryAttempts[adunit]++;
|
|
|
|
|
}
|
|
|
|
|
double retryDelay = Math.Pow(2, Math.Min(6, _rewardRetryAttempts[adunit]));
|
|
|
|
|
TimerUtils.Instance.DelayExecute((float)retryDelay, () => LoadRewarded(adunit));
|
|
|
|
|
AdsActionEvents.TrackAdFailToLoad(Platfrom, "", "", AdsType.Rewarded, Time.realtimeSinceStartup - (_rvStartLoadTimes.TryGetValue(adunit, out var time) ? time : 0), errorInfo.Message);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedAdDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo info)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedAdDisplayedEvent network: " + info.NetworkName + " revenue: " + info.Revenue + " NetworkPlacement: " + info.NetworkPlacement + " AdUnitIdentifier: " + info.AdUnitIdentifier + " Placement: " + info.Placement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedAdClickedEvent");
|
2025-09-01 07:14:26 +00:00
|
|
|
|
AdsActionEvents.TrackAdClicked(Platfrom,adInfo.NetworkName,adInfo.AdUnitIdentifier,AdsType.Rewarded,_rvPos,adInfo.Revenue);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedAdFailedToDisplayEvent :" + errorInfo.Message + " " + errorInfo.Code + " " + errorInfo.MediatedNetworkErrorMessage + " " + errorInfo.MediatedNetworkErrorCode);
|
2025-08-31 05:15:14 +00:00
|
|
|
|
_rvShowFailedCallback?.Invoke();
|
|
|
|
|
_rvShowFailedCallback = null;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if(_rewardAdInfos.ContainsKey(adUnitId))_rewardAdInfos.Remove(adUnitId);
|
|
|
|
|
LoadRewarded(adUnitId);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedAdHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
2025-09-03 11:58:43 +00:00
|
|
|
|
_rvCloseCallback?.Invoke(_receivedReward,adInfo.Revenue);
|
2025-08-31 05:15:14 +00:00
|
|
|
|
_rvCloseCallback = null;
|
2025-09-03 11:58:43 +00:00
|
|
|
|
_receivedReward = false;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if(_rewardAdInfos.ContainsKey(adUnitId))_rewardAdInfos.Remove(adUnitId);
|
|
|
|
|
LoadRewarded(adUnitId);
|
2025-09-03 11:58:43 +00:00
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedAdHiddenEvent "+_receivedReward);
|
2025-09-01 07:14:26 +00:00
|
|
|
|
AdsActionEvents.TrackAdClosed(Platfrom,adInfo.NetworkName,adInfo.AdUnitIdentifier,AdsType.Rewarded,_rvPos,adInfo.Revenue);
|
2025-09-03 11:58:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRewardedAdReceivedRewardEvent(string adUnitId, MaxSdk.Reward reward, MaxSdkBase.AdInfo arg3)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnRewardedAdReceivedRewardEvent network: " + arg3.NetworkName + " revenue: " + arg3.Revenue + " NetworkPlacement: " + arg3.NetworkPlacement + " AdUnitIdentifier: " + arg3.AdUnitIdentifier + " Placement: " + arg3.Placement);
|
|
|
|
|
_receivedReward = true;
|
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 插页广告功能
|
|
|
|
|
private void InitInterstitialCallback()
|
|
|
|
|
{
|
|
|
|
|
MaxSdkCallbacks.Interstitial.OnAdLoadedEvent += OnInterstitialLoadedEvent;
|
|
|
|
|
MaxSdkCallbacks.Interstitial.OnAdLoadFailedEvent += OnInterstitialLoadFailedEvent;
|
|
|
|
|
MaxSdkCallbacks.Interstitial.OnAdDisplayFailedEvent += OnInterstitialAdFailedToDisplayEvent;
|
|
|
|
|
MaxSdkCallbacks.Interstitial.OnAdHiddenEvent += OnInterstitialHiddenEvent;
|
|
|
|
|
MaxSdkCallbacks.Interstitial.OnAdDisplayedEvent += OnInterstitialDisplayedEvent;
|
|
|
|
|
MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnInterstitialRevenue;
|
2025-09-01 07:14:26 +00:00
|
|
|
|
MaxSdkCallbacks.Interstitial.OnAdClickedEvent += OnInterstitialClickedEvent;
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadInterstitial()
|
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
foreach (var kvp in _maxInterstitialUnits)
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
LoggerUtils.Debug("[MAX] start load inter ad unit: "+kvp);
|
|
|
|
|
LoadInterstitial(kvp);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
2025-09-10 12:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadInterstitial(string adUnit)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (!_maxInterstitialUnits.Contains(adUnit)) return;
|
|
|
|
|
if (string.IsNullOrEmpty(adUnit)) return;
|
|
|
|
|
MaxSdk.LoadInterstitial(adUnit);
|
2025-09-15 05:59:03 +00:00
|
|
|
|
AdsActionEvents.TrackAdStartLoad(Platfrom, AdsType.Interstitial);
|
2025-09-10 12:23:01 +00:00
|
|
|
|
_ivStartLoadTimes[adUnit] = Time.realtimeSinceStartup;
|
|
|
|
|
// 初始化重试次数
|
|
|
|
|
if (!_interRetryAttempts.ContainsKey(adUnit))
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
_interRetryAttempts[adUnit] = 0;
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-10 12:23:01 +00:00
|
|
|
|
public double GetInterstitialRevenue()
|
|
|
|
|
{
|
|
|
|
|
return GetHighestPayingAdRevenue(AdsType.Interstitial);
|
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
|
2025-09-01 14:14:33 +00:00
|
|
|
|
public void DisplayInterstitial(string ivPos, IvType _IvType = IvType.IV1, Action<double> closeCallback = null)
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
2025-08-31 05:15:14 +00:00
|
|
|
|
_ivPos = ivPos;
|
|
|
|
|
_ivCloseCallback = closeCallback;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
MaxSdk.ShowInterstitial(GetHighestPayingAdUnit(AdsType.Interstitial));
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsInterstitialAvailable()
|
|
|
|
|
{
|
2025-09-10 12:23:01 +00:00
|
|
|
|
List<string> availableAdUnits = new List<string>();
|
|
|
|
|
|
|
|
|
|
foreach (var kvp in _maxInterstitialUnits)
|
|
|
|
|
{
|
|
|
|
|
if (IsInterstitialAvailable(kvp))
|
|
|
|
|
{
|
|
|
|
|
availableAdUnits.Add(kvp);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return availableAdUnits.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsInterstitialAvailable(string adUnit)
|
|
|
|
|
{
|
|
|
|
|
return IsAdsAvailable(adUnit,AdsType.Interstitial);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnInterstitialLoadedEvent(string adunit, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnInterstitialLoadedEvent network: " + adInfo.NetworkName + " revenue: " + adInfo.Revenue + " NetworkPlacement: " + adInfo.NetworkPlacement + " AdUnitIdentifier: " + adInfo.AdUnitIdentifier + " Placement: " + adInfo.Placement);
|
2025-08-31 14:18:31 +00:00
|
|
|
|
AdsKeyEvents.Instance.LogAdFPUEvents(AdsType.Interstitial);
|
2025-09-10 12:23:01 +00:00
|
|
|
|
_interRetryAttempts.TryAdd(adunit, 0);
|
|
|
|
|
_interAdInfos.TryAdd(adunit, adInfo);
|
|
|
|
|
AdsActionEvents.TrackAdLoaded(Platfrom, adInfo.NetworkName, adInfo.AdUnitIdentifier, AdsType.Interstitial, Time.realtimeSinceStartup - (_ivStartLoadTimes.TryGetValue(adunit, out var time) ? time : 0));
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnInterstitialLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnInterstitialLoadFailedEvent :" + errorInfo);
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if (!_interRetryAttempts.TryAdd(adUnitId, 0))
|
|
|
|
|
{
|
|
|
|
|
_interRetryAttempts[adUnitId]++;
|
|
|
|
|
}
|
|
|
|
|
double retryDelay = Math.Pow(2, Math.Min(6, _interRetryAttempts[adUnitId]));
|
|
|
|
|
TimerUtils.Instance.DelayExecute((float)retryDelay, () => LoadInterstitial(adUnitId));
|
|
|
|
|
AdsActionEvents.TrackAdFailToLoad(Platfrom, "", "", AdsType.Interstitial, Time.realtimeSinceStartup - (_ivStartLoadTimes.TryGetValue(adUnitId, out var time) ? time : 0), errorInfo.Message);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-08-31 12:48:14 +00:00
|
|
|
|
private void OnInterstitialAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo, MaxSdkBase.AdInfo arg3)
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnInterstitialAdFailedToDisplayEvent :" + errorInfo.Message + " " + errorInfo.Code + " " + errorInfo.MediatedNetworkErrorMessage + " " + errorInfo.MediatedNetworkErrorCode);
|
2025-09-01 14:14:33 +00:00
|
|
|
|
_ivCloseCallback?.Invoke(0);
|
2025-08-31 05:15:14 +00:00
|
|
|
|
_ivCloseCallback = null;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if(_interAdInfos.ContainsKey(adUnitId))_interAdInfos.Remove(adUnitId);
|
|
|
|
|
LoadInterstitial(adUnitId);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnInterstitialDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo info)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug($"[Max] OnInterstitialDisplayedEvent network: {info.NetworkName}, revenue: {info.Revenue},NetworkPlacement: {info.NetworkPlacement}, AdUnitIdentifier: {info.AdUnitIdentifier},Placement: {info.Placement}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 07:14:26 +00:00
|
|
|
|
private void OnInterstitialHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
2025-08-31 02:12:10 +00:00
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug($"[Max] OnInterstitialHiddenEvent");
|
2025-09-09 06:19:16 +00:00
|
|
|
|
AdsActionEvents.TrackAdClosed(Platfrom,adInfo.NetworkName,adInfo.AdUnitIdentifier,AdsType.Interstitial, _ivPos,adInfo.Revenue);
|
2025-09-01 14:14:33 +00:00
|
|
|
|
_ivCloseCallback?.Invoke(adInfo.Revenue);
|
2025-08-31 05:15:14 +00:00
|
|
|
|
_ivCloseCallback = null;
|
2025-09-10 12:23:01 +00:00
|
|
|
|
if(_interAdInfos.ContainsKey(adUnitId))_interAdInfos.Remove(adUnitId);
|
|
|
|
|
LoadInterstitial(adUnitId);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnInterstitialRevenue(string adunit, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
|
|
|
|
LoggerUtils.Debug("[Max] OnInterstitialRevenue network: " + adInfo.NetworkName + " revenue: " + adInfo.Revenue + " NetworkPlacement: " + adInfo.NetworkPlacement + " AdUnitIdentifier: " + adInfo.AdUnitIdentifier + " Placement: " + adInfo.Placement);
|
2025-08-31 12:48:14 +00:00
|
|
|
|
TrackAdImpression(adInfo, AdsType.Interstitial);
|
2025-08-31 02:12:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 07:14:26 +00:00
|
|
|
|
private void OnInterstitialClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
|
|
|
|
|
{
|
2025-09-09 06:19:16 +00:00
|
|
|
|
AdsActionEvents.TrackAdClicked(Platfrom,adInfo.NetworkName,adInfo.AdUnitIdentifier,AdsType.Interstitial,_ivPos, adInfo.Revenue);
|
2025-09-01 07:14:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-08-31 02:12:10 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 开屏广告功能
|
|
|
|
|
public void LoadSplash() { }
|
|
|
|
|
public bool IsSplashAvailable() { return false; }
|
2025-08-31 12:48:14 +00:00
|
|
|
|
public void DisplaySplash() { }
|
|
|
|
|
public double GetSplashRevenue() { return 0; }
|
2025-08-31 02:12:10 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 原生广告功能
|
2025-08-31 12:48:14 +00:00
|
|
|
|
public void LoadNative() { }
|
2025-09-02 02:07:10 +00:00
|
|
|
|
public bool IsNativeAvailable(string adUnitId)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveNative(string adUnitId)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double GetNativeRevenue(string adUnitId)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 横幅广告功能
|
2025-08-31 12:48:14 +00:00
|
|
|
|
public void LoadBanner() { }
|
2025-09-16 13:29:51 +00:00
|
|
|
|
public bool IsBannerAvailable(BannerType bannerType) { return false; }
|
|
|
|
|
public void HideBanner(BannerType bannerType) { }
|
|
|
|
|
public double GetBannerRevenue(BannerType bannerType) { return 0; }
|
|
|
|
|
public void DisplayBanner(BannerType bannerType,BannerAlignType bannerAlignType) { }
|
2025-08-31 12:48:14 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 广告收益上报
|
|
|
|
|
public void TrackAdImpression(MaxSdkBase.AdInfo adInfo, AdsType type)
|
|
|
|
|
{
|
|
|
|
|
AdjustTrackEvent.Instance.TrackAdEvent(adInfo.Revenue,
|
|
|
|
|
adInfo.NetworkName,
|
|
|
|
|
adInfo.AdUnitIdentifier,
|
|
|
|
|
adInfo.Placement);
|
|
|
|
|
|
|
|
|
|
FireBaseAnalyticsManager.Instance.OnAdRevenueEvent(ClientName,
|
|
|
|
|
adInfo.NetworkName,
|
|
|
|
|
adInfo.AdUnitIdentifier,
|
2025-08-31 14:18:31 +00:00
|
|
|
|
type,
|
2025-08-31 12:48:14 +00:00
|
|
|
|
adInfo.Revenue,
|
2025-09-09 06:19:16 +00:00
|
|
|
|
type == AdsType.Rewarded ? _rvPos : _ivPos,
|
2025-09-04 09:19:05 +00:00
|
|
|
|
AdPlayCountManager.GetAdsActionCount(type,AdPlayCountManager.PLAY_COUNT_SUFFIX));
|
2025-08-31 12:48:14 +00:00
|
|
|
|
|
|
|
|
|
ShuShuEvent.Instance.OnAdRevenueEvent(ClientName,
|
|
|
|
|
adInfo.NetworkName,
|
|
|
|
|
adInfo.AdUnitIdentifier,
|
|
|
|
|
type.ToString(),
|
|
|
|
|
adInfo.Revenue,
|
2025-09-09 06:19:16 +00:00
|
|
|
|
type == AdsType.Rewarded ? _rvPos : _ivPos,
|
2025-09-04 09:19:05 +00:00
|
|
|
|
AdPlayCountManager.GetAdsActionCount(type,AdPlayCountManager.PLAY_COUNT_SUFFIX));
|
2025-08-31 12:48:14 +00:00
|
|
|
|
}
|
2025-08-31 02:12:10 +00:00
|
|
|
|
#endregion
|
2025-08-30 13:48:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|