更新在线参数解析,不配时走本地,配了为空时刷新广告位
This commit is contained in:
parent
95e4a2303b
commit
a700df6a78
|
@ -29,6 +29,7 @@ namespace WZ
|
|||
Action<AdValue> OnAdPaid,
|
||||
Action<string,string,double> onAdClicked)
|
||||
{
|
||||
if (string.IsNullOrEmpty(adUnitId)) return;
|
||||
if (_bannerAds.ContainsKey(adUnitId))
|
||||
{
|
||||
LoggerUtils.Debug($"Bigo banner Ad unit {adUnitId} already exists");
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace WZ
|
|||
Action<AdValue> onAdPaid,
|
||||
Action<string,string,double> onAdClicked)
|
||||
{
|
||||
if (string.IsNullOrEmpty(adUnitId)) return;
|
||||
if (_interstitialAds.ContainsKey(adUnitId))
|
||||
{
|
||||
LoggerUtils.Debug($"[Admob] Interstitial Ad unit {adUnitId} already exists");
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace WZ
|
|||
|
||||
private void CreateNativeAd(string adUnitId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(adUnitId)) return;
|
||||
if (_nativeAds.ContainsKey(adUnitId))
|
||||
{
|
||||
LoggerUtils.Debug($"[Admob] Native Ad unit {adUnitId} already exists");
|
||||
|
|
|
@ -34,6 +34,7 @@ namespace WZ
|
|||
Action<bool> onEarnRewarded,
|
||||
Action<string,string,double> onAdClicked)
|
||||
{
|
||||
if (string.IsNullOrEmpty(adUnitId)) return;
|
||||
if (_rewardedAds.ContainsKey(adUnitId))
|
||||
{
|
||||
LoggerUtils.Debug($"[Admob] rewarded Ad unit {adUnitId} already exists");
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace WZ
|
|||
Action<AdValue> onAdPaid,
|
||||
Action<string,string,double> onAdClicked)
|
||||
{
|
||||
if (string.IsNullOrEmpty(adUnitId)) return;
|
||||
if (_appOpenAds.ContainsKey(adUnitId))
|
||||
{
|
||||
LoggerUtils.Debug($"[Admob] appopen Ad unit {adUnitId} already exists");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WZ
|
||||
|
@ -9,6 +9,7 @@ namespace WZ
|
|||
public static class AdConfigParser
|
||||
{
|
||||
private static AdConfig _config;
|
||||
private static Dictionary<string,object> _configDict = new Dictionary<string, object>();
|
||||
public static AdConfig Parse(string json)
|
||||
{
|
||||
try
|
||||
|
@ -22,6 +23,7 @@ namespace WZ
|
|||
|
||||
// 使用 JsonUtility 解析 JSON
|
||||
_config = JsonUtility.FromJson<AdConfig>(json);
|
||||
_configDict = JsonToDictionary(json);
|
||||
|
||||
if (_config == null)
|
||||
{
|
||||
|
@ -39,6 +41,12 @@ namespace WZ
|
|||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string,object> JsonToDictionary(string jsonStr)
|
||||
{
|
||||
Dictionary<string,object> dic= JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonStr);
|
||||
return dic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Admob 广告单元ID
|
||||
/// </summary>
|
||||
|
@ -56,16 +64,62 @@ namespace WZ
|
|||
_ => new List<string>()
|
||||
};
|
||||
}
|
||||
|
||||
return adType switch
|
||||
|
||||
switch (adType)
|
||||
{
|
||||
AdsType.Interstitial => _config.admob_interstitial_units ?? new List<string>(),
|
||||
AdsType.Splash => _config.admob_splash_units ?? new List<string>(),
|
||||
AdsType.Rewarded => _config.admob_rewarded_units ?? new List<string>(),
|
||||
AdsType.Banner => _config.admob_banner_units ?? new List<string>(),
|
||||
AdsType.Native => _config.admob_native_units ?? new List<string>(),
|
||||
_ => new List<string>()
|
||||
};
|
||||
case AdsType.Banner:
|
||||
if (_configDict.ContainsKey("admob_banner_units"))
|
||||
{
|
||||
return _config.admob_banner_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.AdmobNormalBannerId };
|
||||
}
|
||||
case AdsType.Rewarded:
|
||||
if (_configDict.ContainsKey("admob_rewarded_units"))
|
||||
{
|
||||
return _config.admob_rewarded_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.AdmobRewardId };
|
||||
}
|
||||
case AdsType.Native:
|
||||
if (_configDict.ContainsKey("admob_native_units"))
|
||||
{
|
||||
return _config.admob_native_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.AdmobNativeId,
|
||||
StaticValue.AdmobMinddleNativeId,
|
||||
StaticValue.AdmobSmallNativeId,
|
||||
StaticValue.AdmobFullNativeId };
|
||||
}
|
||||
case AdsType.Splash:
|
||||
if (_configDict.ContainsKey("admob_splash_units"))
|
||||
{
|
||||
return _config.admob_splash_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.AdmobSplashId };
|
||||
}
|
||||
case AdsType.Interstitial:
|
||||
if (_configDict.ContainsKey("admob_interstitial_units"))
|
||||
{
|
||||
return _config.admob_interstitial_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.AdmobInterId };
|
||||
}
|
||||
default:
|
||||
return new List<string>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -83,15 +137,29 @@ namespace WZ
|
|||
};
|
||||
}
|
||||
|
||||
return adType switch
|
||||
switch (adType)
|
||||
{
|
||||
AdsType.Interstitial => _config.topon_interstitial_units ?? new List<string>(),
|
||||
AdsType.Splash => _config.topon_splash_units ?? new List<string>(),
|
||||
AdsType.Rewarded => _config.topon_rewarded_units ?? new List<string>(),
|
||||
AdsType.Banner => _config.topon_banner_units ?? new List<string>(),
|
||||
AdsType.Native => _config.topon_native_units ?? new List<string>(),
|
||||
_ => new List<string>()
|
||||
};
|
||||
case AdsType.Interstitial:
|
||||
if (_configDict.ContainsKey("topon_interstitial_units"))
|
||||
{
|
||||
return _config.topon_interstitial_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.TopOnInterAdUnitID };
|
||||
}
|
||||
case AdsType.Rewarded:
|
||||
if (_configDict.ContainsKey("topon_rewarded_units"))
|
||||
{
|
||||
return _config.topon_rewarded_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.TopOnRewardAdUnitID };;
|
||||
}
|
||||
default:
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -109,17 +177,30 @@ namespace WZ
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
return adType switch
|
||||
switch (adType)
|
||||
{
|
||||
AdsType.Interstitial => _config.max_interstitial_units ?? new List<string>(),
|
||||
AdsType.Splash => _config.max_splash_units ?? new List<string>(),
|
||||
AdsType.Rewarded => _config.max_rewarded_units ?? new List<string>(),
|
||||
AdsType.Banner => _config.max_banner_units ?? new List<string>(),
|
||||
AdsType.Native => _config.max_native_units ?? new List<string>(),
|
||||
_ => new List<string>()
|
||||
};
|
||||
|
||||
case AdsType.Interstitial:
|
||||
if (_configDict.ContainsKey("max_interstitial_units"))
|
||||
{
|
||||
return _config.max_interstitial_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.InterAdUnitID };
|
||||
}
|
||||
|
||||
case AdsType.Rewarded:
|
||||
if (_configDict.ContainsKey("max_rewarded_units"))
|
||||
{
|
||||
return _config.max_rewarded_units ?? new List<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new List<string>{ StaticValue.RewardAdUnitID };
|
||||
}
|
||||
default:
|
||||
return new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -151,23 +232,39 @@ namespace WZ
|
|||
_ => new List<string>()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取 TopOn App ID
|
||||
/// </summary>
|
||||
public static string GetTopOnAppId()
|
||||
{
|
||||
if (_config == null) return StaticValue.TopOnAppID;
|
||||
return _config?.topon_app_id;
|
||||
if (_configDict.ContainsKey("topon_app_id"))
|
||||
{
|
||||
return _config?.topon_app_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return StaticValue.TopOnAppID;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取 TopOn App Key
|
||||
/// </summary>
|
||||
public static string GetTopOnAppKey()
|
||||
{
|
||||
if (_config == null) return StaticValue.TopOnAppKey;
|
||||
return _config?.topon_app_key;
|
||||
|
||||
if (_configDict.ContainsKey("topon_app_key"))
|
||||
{
|
||||
return _config?.topon_app_key;
|
||||
}
|
||||
else
|
||||
{
|
||||
return StaticValue.TopOnAppKey;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue