admob拉取线上广告id后销毁无效id广告
This commit is contained in:
parent
95e4a2303b
commit
b9fe36c2e0
|
@ -42,6 +42,7 @@ namespace WZ
|
||||||
if (_initialized) return;
|
if (_initialized) return;
|
||||||
MobileAds.RaiseAdEventsOnUnityMainThread = true;
|
MobileAds.RaiseAdEventsOnUnityMainThread = true;
|
||||||
_initialized = true;
|
_initialized = true;
|
||||||
|
|
||||||
MobileAds.Initialize(initStatus =>
|
MobileAds.Initialize(initStatus =>
|
||||||
{
|
{
|
||||||
if (_bannerAdUnits.Count > 0) LoadBanner();
|
if (_bannerAdUnits.Count > 0) LoadBanner();
|
||||||
|
@ -62,6 +63,12 @@ namespace WZ
|
||||||
_nativeAdUnits = AdConfigParser.GetAdmobAdUnits(AdsType.Native);
|
_nativeAdUnits = AdConfigParser.GetAdmobAdUnits(AdsType.Native);
|
||||||
_splashAdUnits = AdConfigParser.GetAdmobAdUnits(AdsType.Splash);
|
_splashAdUnits = AdConfigParser.GetAdmobAdUnits(AdsType.Splash);
|
||||||
_rewardedAdUnits = AdConfigParser.GetAdmobAdUnits(AdsType.Rewarded);
|
_rewardedAdUnits = AdConfigParser.GetAdmobAdUnits(AdsType.Rewarded);
|
||||||
|
|
||||||
|
_admobBannerAdManager?.ClearAds(_bannerAdUnits.ToArray());
|
||||||
|
_admobInterstitialAdManager?.ClearAds(_interstitialAdUnits.ToArray());
|
||||||
|
_admobNativeAdManager?.ClearAds(_nativeAdUnits.ToArray());
|
||||||
|
_admobSplashAdManager?.ClearAds(_splashAdUnits.ToArray());
|
||||||
|
_admobRewardedAdManager?.ClearAds(_rewardedAdUnits.ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 激励广告功能
|
#region 激励广告功能
|
||||||
|
@ -108,7 +115,7 @@ namespace WZ
|
||||||
|
|
||||||
private void OnRewardedAdLoadFailed(string adUnitId, int errorCode, string errorMsg)
|
private void OnRewardedAdLoadFailed(string adUnitId, int errorCode, string errorMsg)
|
||||||
{
|
{
|
||||||
AdsActionEvents.TrackAdFailToLoad(Platfrom,"","",AdsType.Rewarded,Time.realtimeSinceStartup - _rvStartLoadTime,errorMsg);
|
AdsActionEvents.TrackAdFailToLoad(Platfrom,"",adUnitId,AdsType.Rewarded,Time.realtimeSinceStartup - _rvStartLoadTime,errorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRewardedAdShowed(string adUnitId)
|
private void OnRewardedAdShowed(string adUnitId)
|
||||||
|
|
|
@ -194,6 +194,31 @@ namespace WZ
|
||||||
_loadCallbacks.Clear();
|
_loadCallbacks.Clear();
|
||||||
_adRevenueCache.Clear();
|
_adRevenueCache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearAds(string[] adUnitIds)
|
||||||
|
{
|
||||||
|
// 将数组转换为HashSet以提高查找性能
|
||||||
|
HashSet<string> validKeys = new HashSet<string>(adUnitIds);
|
||||||
|
// 收集需要移除的key
|
||||||
|
List<string> keysToRemove = new List<string>();
|
||||||
|
|
||||||
|
foreach (var key in _bannerAds.Keys)
|
||||||
|
{
|
||||||
|
if (!validKeys.Contains(key))
|
||||||
|
{
|
||||||
|
keysToRemove.Add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除不在数组中的key
|
||||||
|
foreach (string key in keysToRemove)
|
||||||
|
{
|
||||||
|
_bannerAds.Remove(key);
|
||||||
|
_retryCounters.Remove(key);
|
||||||
|
_loadCallbacks.Remove(key);
|
||||||
|
_adRevenueCache.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,5 +188,28 @@ namespace WZ
|
||||||
_interstitialAds.Clear();
|
_interstitialAds.Clear();
|
||||||
_adRevenueCache.Clear();
|
_adRevenueCache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearAds(string[] adUnitIds)
|
||||||
|
{
|
||||||
|
// 将数组转换为HashSet以提高查找性能
|
||||||
|
HashSet<string> validKeys = new HashSet<string>(adUnitIds);
|
||||||
|
// 收集需要移除的key
|
||||||
|
List<string> keysToRemove = new List<string>();
|
||||||
|
|
||||||
|
foreach (var key in _interstitialAds.Keys)
|
||||||
|
{
|
||||||
|
if (!validKeys.Contains(key))
|
||||||
|
{
|
||||||
|
keysToRemove.Add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除不在数组中的key
|
||||||
|
foreach (string key in keysToRemove)
|
||||||
|
{
|
||||||
|
_interstitialAds.Remove(key);
|
||||||
|
_adRevenueCache.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,5 +267,30 @@ namespace WZ
|
||||||
LoadAd(adUnitId);
|
LoadAd(adUnitId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearAds(string[] adUnitIds)
|
||||||
|
{
|
||||||
|
// 将数组转换为HashSet以提高查找性能
|
||||||
|
HashSet<string> validKeys = new HashSet<string>(adUnitIds);
|
||||||
|
// 收集需要移除的key
|
||||||
|
List<string> keysToRemove = new List<string>();
|
||||||
|
|
||||||
|
foreach (var key in _nativeAds.Keys)
|
||||||
|
{
|
||||||
|
if (!validKeys.Contains(key))
|
||||||
|
{
|
||||||
|
keysToRemove.Add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除不在数组中的key
|
||||||
|
foreach (string key in keysToRemove)
|
||||||
|
{
|
||||||
|
_nativeAds.Remove(key);
|
||||||
|
_retryCounters.Remove(key);
|
||||||
|
_adStartLoadTimes.Remove(key);
|
||||||
|
_adRevenueCache.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -188,5 +188,29 @@ namespace WZ
|
||||||
_rewardedAds.Clear();
|
_rewardedAds.Clear();
|
||||||
_adRevenueCache.Clear();
|
_adRevenueCache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void ClearAds(string[] adUnitIds)
|
||||||
|
{
|
||||||
|
// 将数组转换为HashSet以提高查找性能
|
||||||
|
HashSet<string> validKeys = new HashSet<string>(adUnitIds);
|
||||||
|
// 收集需要移除的key
|
||||||
|
List<string> keysToRemove = new List<string>();
|
||||||
|
|
||||||
|
foreach (var key in _rewardedAds.Keys)
|
||||||
|
{
|
||||||
|
if (!validKeys.Contains(key))
|
||||||
|
{
|
||||||
|
keysToRemove.Add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除不在数组中的key
|
||||||
|
foreach (string key in keysToRemove)
|
||||||
|
{
|
||||||
|
_rewardedAds.Remove(key);
|
||||||
|
_adRevenueCache.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,5 +187,28 @@ namespace WZ
|
||||||
_appOpenAds.Clear();
|
_appOpenAds.Clear();
|
||||||
_adRevenueCache.Clear();
|
_adRevenueCache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearAds(string[] adUnitIds)
|
||||||
|
{
|
||||||
|
// 将数组转换为HashSet以提高查找性能
|
||||||
|
HashSet<string> validKeys = new HashSet<string>(adUnitIds);
|
||||||
|
// 收集需要移除的key
|
||||||
|
List<string> keysToRemove = new List<string>();
|
||||||
|
|
||||||
|
foreach (var key in _appOpenAds.Keys)
|
||||||
|
{
|
||||||
|
if (!validKeys.Contains(key))
|
||||||
|
{
|
||||||
|
keysToRemove.Add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除不在数组中的key
|
||||||
|
foreach (string key in keysToRemove)
|
||||||
|
{
|
||||||
|
_appOpenAds.Remove(key);
|
||||||
|
_adRevenueCache.Remove(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue