6 Commits

Author SHA1 Message Date
b56b47912e release: 1.0.13 2026-04-22 20:58:58 +08:00
957c4e4045 release: 1.0.12 2026-04-22 17:41:45 +08:00
377a279ac3 1.0.11 2023-10-19 15:07:16 +08:00
b53846c98f update core 2023-09-14 14:23:12 +08:00
89f5f66322 update core 2023-09-14 14:21:41 +08:00
acff3d126b update core 2023-07-31 09:57:20 +08:00
6 changed files with 206 additions and 49 deletions

View File

@@ -1,3 +1,21 @@
# [1.0.13]
### 修复
* 修复插屏成功关闭时误触发 `GLOBAL_ShowAwardVideoComplete` 全局奖励视频完成事件的问题。
# [1.0.12]
### 新增
* `ADManager` 新增 `EnterAdScenario(AD_Type, string)`,支持应用层显式上报广告场景到达。
* `ADPlayer` 增加预热、重试和播放前钩子能力,用于平台层策略化调度。
### 修复
* `AsyncAdPlayer` 增强首播失败补偿和多次加载尝试,降低冷启动首次播放失败概率。
* 初始化后可按广告位配置自动预热,避免高价值广告位首次点击才开始建链。
# [1.0.0]
基础版本.

View File

@@ -7,8 +7,8 @@ namespace Runtime.ADAggregator
public class ADManager : MonoBehaviour
{
private static ADManager _instance;
private static bool mIsCreate = false;
private static bool mIsGMModel = false;
private static bool mIsCreate = false;
private static bool mIsGMModel = false;
public static ADManager Instance
{
@@ -22,7 +22,7 @@ namespace Runtime.ADAggregator
Destroy(objs[i]);
}
_instance = new GameObject().AddComponent<ADManager>();
_instance = new GameObject().AddComponent<ADManager>();
_instance.name = "[GameUpdater] <color=yellow>NoInit<color>";
DontDestroyOnLoad(_instance);
_instance.InitTimeSystem();
@@ -51,25 +51,36 @@ namespace Runtime.ADAggregator
private string _userId;
/// <summary>
/// 全局任意视频广告播放结束后事件, bool 表示是否完成奖励
/// </summary>
public event Action<bool> GLOBAL_ShowAwardVideoComplete;
/// <summary>
/// 全局任意视频广告玩家点击播放时
/// </summary>
public event Action<string , string> GLOBAL_ShowAwardVideoBefore;
public string UserId => _userId;
#pragma warning disable CS0414
private bool _isInit = false;
#pragma warning restore CS0414
public void Init(Action onCallback, string userId, ADConfig adConfig, IAdController controller,
params object[] args)
public void Init(Action onCallback, string userId, ADConfig adConfig, IAdController controller,
params object[] args)
{
_isInit = true;
_isInit = true;
_instance.name = "[GameUpdater] <color=green>Init<color>";
AD_Dicts = new Dictionary<AD_Type, ADPlayer>();
_userId = userId;
AD_Dicts = new Dictionary<AD_Type, ADPlayer>();
_userId = userId;
#if UNITY_EDITOR
onCallback?.Invoke();
#else
controller.Init(adConfig , args);
_adController = controller;
_adConfig = adConfig;
PrewarmConfiguredPlayers();
onCallback?.Invoke();
#endif
}
@@ -92,12 +103,12 @@ namespace Runtime.ADAggregator
return true;
}
#pragma warning disable CS0162
if (AD_Dicts.ContainsKey(adType) == false)
if (!TryGetOrCreatePlayer(adType, out var player))
{
AD_Dicts[adType] = PlayerCreate(adType);
return false;
}
return AD_Dicts[adType].IsReadly();
return player.IsReadly();
#pragma warning restore CS0162
}
@@ -112,9 +123,9 @@ namespace Runtime.ADAggregator
}
// Debug.LogError("准备加载广告" + adType);
#pragma warning disable CS0162
if (!IsRealy(adType))
if (!IsRealy(adType) && TryGetOrCreatePlayer(adType, out var player))
{
AD_Dicts[adType].LoadAD();
player.LoadAD();
}
#pragma warning restore CS0162
}
@@ -135,7 +146,13 @@ namespace Runtime.ADAggregator
/// <param name="callback"></param>
public void AsyncPlayAD(AD_Type adType, string adScene, Action<bool> callback)
{
#if UNITY_EDITOR
if (adType == AD_Type.AwardVideo)
{
this.OnVideoComplete(true);
}
callback?.Invoke(true);
return;
#endif
@@ -144,17 +161,20 @@ namespace Runtime.ADAggregator
callback?.Invoke(true);
return;
}
_adController.EventLog("adScene", adScene);
try
{
_curAsyncPlayer?.Kill();
if (AD_Dicts.ContainsKey(adType) == false)
if (!TryGetOrCreatePlayer(adType, out var player))
{
AD_Dicts[adType] = PlayerCreate(adType);
callback?.Invoke(false);
return;
}
var player = AD_Dicts[adType];
_curAsyncPlayer = new AsyncAdPlayer(player, callback);
if (adType == AD_Type.AwardVideo)
GLOBAL_ShowAwardVideoBefore?.Invoke(player.Key , NormalizeScenario(adScene));
_curAsyncPlayer = new AsyncAdPlayer(player, NormalizeScenario(adScene), callback);
}
catch (Exception e)
{
@@ -174,10 +194,75 @@ namespace Runtime.ADAggregator
return null;
}
#pragma warning disable CS0162
return _adController.CreateAdPlayer(type);
var adPlayer = _adController.CreateAdPlayer(type);
if (adPlayer == null)
{
return null;
}
adPlayer.ADType = type;
return adPlayer;
#pragma warning restore CS0162
}
public void EnterAdScenario(AD_Type adType, string adScene)
{
#if UNITY_EDITOR
return;
#endif
if (!_isInit || mIsGMModel)
{
return;
}
#pragma warning disable CS0162
if (!TryGetOrCreatePlayer(adType, out var player))
{
return;
}
player.EnterAdScenario(NormalizeScenario(adScene));
#pragma warning restore CS0162
}
private bool TryGetOrCreatePlayer(AD_Type type, out ADPlayer player)
{
if (AD_Dicts.TryGetValue(type, out player) && player != null)
{
return true;
}
player = PlayerCreate(type);
if (player == null)
{
return false;
}
AD_Dicts[type] = player;
return true;
}
private void PrewarmConfiguredPlayers()
{
foreach (AD_Type adType in Enum.GetValues(typeof(AD_Type)))
{
if (!TryGetOrCreatePlayer(adType, out var player))
{
continue;
}
if (!player.AutoPreloadOnInit)
{
continue;
}
player.LoadAD();
}
}
private static string NormalizeScenario(string scenario)
{
return string.IsNullOrWhiteSpace(scenario) ? "__default__" : scenario.Trim();
}
public void CloseAd(AD_Type adType)
{
#if UNITY_EDITOR
@@ -201,13 +286,13 @@ namespace Runtime.ADAggregator
#region TimeSystem
private List<Action> _updateList;
private const int DefaultLength = 1024;
private List<AdTimeHandler> _timeHandlers;
private List<Action> _updateList;
private const int DefaultLength = 1024;
private List<AdTimeHandler> _timeHandlers;
private void InitTimeSystem()
{
this._updateList = new List<Action>(DefaultLength);
this._updateList = new List<Action>(DefaultLength);
this._timeHandlers = new List<AdTimeHandler>();
}
@@ -296,5 +381,10 @@ namespace Runtime.ADAggregator
{
_adController.SetMask(true);
}
internal void OnVideoComplete(bool isComplete)
{
GLOBAL_ShowAwardVideoComplete?.Invoke(isComplete);
}
}
}
}

View File

@@ -10,11 +10,37 @@ namespace Runtime.ADAggregator
protected int curState;
public string Key;
public string AdScene;
protected ADListener adListener;
public Action OnErrorAction;
public AD_Type ADType { get; internal set; }
public int State => curState;
public virtual int MaxLoadAttempts
{
get
{
return ADType == AD_Type.AwardVideo ? 2 : 1;
}
}
public virtual float LoadRetryDelaySeconds
{
get
{
return ADType == AD_Type.AwardVideo ? 0.75f : 0f;
}
}
public virtual bool AutoPreloadOnInit
{
get
{
return false;
}
}
public ADPlayer Init(string key)
{
this.Key = key;
@@ -42,6 +68,14 @@ namespace Runtime.ADAggregator
{
}
public virtual void OnPlayRequestStarted()
{
}
public virtual void EnterAdScenario(string scenario)
{
}
/// <summary>
/// 主动关闭广告
/// </summary>
@@ -56,4 +90,4 @@ namespace Runtime.ADAggregator
curState = 0;
}
}
}
}

View File

@@ -5,22 +5,28 @@ namespace Runtime.ADAggregator
{
public class AsyncAdPlayer
{
private Action<bool> _callback;
private ADPlayer _adPlayer;
private bool firstLoad;
private bool isKill;
private bool isUpdate;
private Action<bool> _callback;
private ADPlayer _adPlayer;
private bool firstLoad;
private bool isKill;
private bool isUpdate;
private int loadAttempts;
private float nextLoadRetryTime;
private AdTimeHandler overHandler;
private string _Ad_scene;
private float _outTime;
public AsyncAdPlayer(ADPlayer player , Action<bool> callback)
public AsyncAdPlayer(ADPlayer player , string adScene, Action<bool> callback)
{
this._outTime = 0;
this._Ad_scene = adScene;
this._outTime = 0;
this._callback = callback;
this.isKill = false;
this.isKill = false;
this.firstLoad = true;
this.loadAttempts = 0;
this.nextLoadRetryTime = 0f;
this._adPlayer = player;
if (_adPlayer == null)
{
@@ -33,7 +39,9 @@ namespace Runtime.ADAggregator
}
ADManager.Instance.OpenMask();
_adPlayer.OnErrorAction = OnError;
isUpdate = true;
_adPlayer.AdScene = this._Ad_scene;
_adPlayer.OnPlayRequestStarted();
isUpdate = true;
ADManager.Instance.AddUpdater(DoUpdate);
}
@@ -58,10 +66,12 @@ namespace Runtime.ADAggregator
if (!isUpdate)
return;
_outTime += Time.deltaTime;
var callback = _callback;
if (this._outTime >= 15)
{
_callback?.Invoke(false);
callback?.Invoke(false);
Kill();
return;
}
if (_adPlayer.IsReadly())
{
@@ -69,24 +79,33 @@ namespace Runtime.ADAggregator
Debug.LogError("开始播放广告: " + this._adPlayer.Key);
#endif
_adPlayer.ShowAD(OnCloseAD, OnComplete);
ADManager.Instance.CloseMask();
if (_adPlayer.ADType != AD_Type.AwardVideo)
{
ADManager.Instance.CloseMask();
}
isUpdate = false;
ADManager.Instance.RemoveUpdater(DoUpdate);
}
else if(!_adPlayer.IsLoading())
{
if (firstLoad)
if (loadAttempts < _adPlayer.MaxLoadAttempts)
{
if (this._outTime < nextLoadRetryTime)
{
return;
}
#if UNITY_EDITOR
Debug.LogError("开始加载广告: " + this._adPlayer.Key);
#endif
this._outTime = 0;
_adPlayer.LoadAD();
loadAttempts++;
firstLoad = false;
nextLoadRetryTime = this._outTime + _adPlayer.LoadRetryDelaySeconds;
}
else
{
_callback?.Invoke(false);
callback?.Invoke(false);
Kill();
}
}
@@ -112,6 +131,10 @@ namespace Runtime.ADAggregator
this.overHandler?.Kill();
this.overHandler = ADManager.Instance.CreateTimer(0.05f, () =>
{
if (_adPlayer != null && _adPlayer.ADType == AD_Type.AwardVideo)
{
ADManager.Instance.OnVideoComplete(obj);
}
_callback?.Invoke(obj);
Clear();
});
@@ -122,13 +145,13 @@ namespace Runtime.ADAggregator
{
if (isKill)
return;
ADManager.Instance.CloseMask();
ADManager.Instance.RemoveUpdater(DoUpdate);
Clear();
}
private void Clear()
{
ADManager.Instance.CloseMask();
isKill = true;
_callback = null;
_adPlayer = null;

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 094f67b7dbe0a8d4bb32d358c57004c6
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,7 +2,7 @@
"name": "com.foldcc.cc-framework.commercialization",
"displayName": "CC-Framework.commercialization",
"description": "商业化sdk通用组件包含广告、内购、用户统计、归因统计等",
"version": "1.0.5",
"version": "1.0.13",
"unity": "2021.1",
"license": "MIT",
"repository": {