release: 1.0.14

This commit is contained in:
2026-04-23 17:14:27 +08:00
parent a2969c34ff
commit 781837a769
5 changed files with 136 additions and 52 deletions

View File

@@ -1,3 +1,11 @@
# [1.0.14]
### 修复
* `AsyncAdPlayer` 增加展示确认阶段和统一失败收口,避免 `show` 发起后无回调时主链失联。
* 抽象播放器补充展示超时配置与内部展示开始通知,保持外部调用接口不变。
* 清理广告源级失败对主链的误接线,避免 `AdSource` 过程回调误判为最终失败。
# [1.0.13] # [1.0.13]
### 修复 ### 修复

View File

@@ -13,6 +13,7 @@ namespace Runtime.ADAggregator
public string AdScene; public string AdScene;
protected ADListener adListener; protected ADListener adListener;
public Action OnErrorAction; public Action OnErrorAction;
public Action OnShowStartedAction;
public AD_Type ADType { get; internal set; } public AD_Type ADType { get; internal set; }
public int State => curState; public int State => curState;
@@ -33,6 +34,14 @@ namespace Runtime.ADAggregator
} }
} }
public virtual float ShowPendingTimeoutSeconds
{
get
{
return 5f;
}
}
public virtual bool AutoPreloadOnInit public virtual bool AutoPreloadOnInit
{ {
get get
@@ -83,6 +92,11 @@ namespace Runtime.ADAggregator
{ {
} }
protected void NotifyShowStarted()
{
OnShowStartedAction?.Invoke();
}
public void OnError(object code, string message) public void OnError(object code, string message)
{ {
this.OnErrorAction?.Invoke(); this.OnErrorAction?.Invoke();

View File

@@ -5,29 +5,40 @@ namespace Runtime.ADAggregator
{ {
public class AsyncAdPlayer public class AsyncAdPlayer
{ {
private enum AsyncPlayPhase
{
Loading,
ShowPending,
Playing,
Closing,
Completed
}
private const float LoadTimeoutSeconds = 15f;
private const float ShowAckTimeoutSeconds = 2f;
private Action<bool> _callback; private Action<bool> _callback;
private ADPlayer _adPlayer; private ADPlayer _adPlayer;
private bool firstLoad;
private bool isKill; private bool isKill;
private bool isUpdate; private bool isUpdate;
private int loadAttempts; private int loadAttempts;
private float nextLoadRetryTime; private float nextLoadRetryTime;
private AdTimeHandler overHandler; private AdTimeHandler overHandler;
private string _Ad_scene; private AdTimeHandler _showPendingHandler;
private string _adScene;
private float _outTime; private AsyncPlayPhase _phase;
private float _loadElapsed;
public AsyncAdPlayer(ADPlayer player , string adScene, Action<bool> callback) public AsyncAdPlayer(ADPlayer player , string adScene, Action<bool> callback)
{ {
_adScene = adScene;
this._Ad_scene = adScene; _loadElapsed = 0f;
this._outTime = 0; _callback = callback;
this._callback = callback; isKill = false;
this.isKill = false; loadAttempts = 0;
this.firstLoad = true; nextLoadRetryTime = 0f;
this.loadAttempts = 0; _adPlayer = player;
this.nextLoadRetryTime = 0f; _phase = AsyncPlayPhase.Loading;
this._adPlayer = player;
if (_adPlayer == null) if (_adPlayer == null)
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
@@ -39,7 +50,8 @@ namespace Runtime.ADAggregator
} }
ADManager.Instance.OpenMask(); ADManager.Instance.OpenMask();
_adPlayer.OnErrorAction = OnError; _adPlayer.OnErrorAction = OnError;
_adPlayer.AdScene = this._Ad_scene; _adPlayer.OnShowStartedAction = OnShowStarted;
_adPlayer.AdScene = _adScene;
_adPlayer.OnPlayRequestStarted(); _adPlayer.OnPlayRequestStarted();
isUpdate = true; isUpdate = true;
ADManager.Instance.AddUpdater(DoUpdate); ADManager.Instance.AddUpdater(DoUpdate);
@@ -50,47 +62,47 @@ namespace Runtime.ADAggregator
#if UNITY_EDITOR #if UNITY_EDITOR
Debug.LogError("广告异常: " + this._adPlayer.Key); Debug.LogError("广告异常: " + this._adPlayer.Key);
#endif #endif
// return; if (_phase == AsyncPlayPhase.Loading)
// if (isUpdate) {
// { return;
// isUpdate = false; }
// ADManager.Instance.RemoveUpdater(DoUpdate);
// } Fail(false);
// ADManager.Instance.CloseMask();
// _callback?.Invoke(false);
// Clear();
} }
private void DoUpdate() private void DoUpdate()
{ {
if (!isUpdate) if (!isUpdate)
return;
_outTime += Time.deltaTime;
var callback = _callback;
if (this._outTime >= 15)
{ {
callback?.Invoke(false);
Kill();
return; return;
} }
switch (_phase)
{
case AsyncPlayPhase.Loading:
UpdateLoading();
break;
}
}
private void UpdateLoading()
{
_loadElapsed += Time.deltaTime;
if (_loadElapsed >= LoadTimeoutSeconds)
{
Fail(false);
return;
}
if (_adPlayer.IsReadly()) if (_adPlayer.IsReadly())
{ {
#if UNITY_EDITOR BeginShow();
Debug.LogError("开始播放广告: " + this._adPlayer.Key);
#endif
_adPlayer.ShowAD(OnCloseAD, OnComplete);
if (_adPlayer.ADType != AD_Type.AwardVideo)
{
ADManager.Instance.CloseMask();
} }
isUpdate = false; else if (!_adPlayer.IsLoading())
ADManager.Instance.RemoveUpdater(DoUpdate);
}
else if(!_adPlayer.IsLoading())
{ {
if (loadAttempts < _adPlayer.MaxLoadAttempts) if (loadAttempts < _adPlayer.MaxLoadAttempts)
{ {
if (this._outTime < nextLoadRetryTime) if (_loadElapsed < nextLoadRetryTime)
{ {
return; return;
} }
@@ -100,27 +112,62 @@ namespace Runtime.ADAggregator
#endif #endif
_adPlayer.LoadAD(); _adPlayer.LoadAD();
loadAttempts++; loadAttempts++;
firstLoad = false; nextLoadRetryTime = _loadElapsed + _adPlayer.LoadRetryDelaySeconds;
nextLoadRetryTime = this._outTime + _adPlayer.LoadRetryDelaySeconds;
} }
else else
{ {
callback?.Invoke(false); Fail(false);
Kill();
} }
} }
} }
private void BeginShow()
{
#if UNITY_EDITOR
Debug.LogError("开始播放广告: " + _adPlayer.Key);
#endif
try
{
_phase = AsyncPlayPhase.ShowPending;
_showPendingHandler = ADManager.Instance.CreateTimer(
_adPlayer.ShowPendingTimeoutSeconds > 0 ? _adPlayer.ShowPendingTimeoutSeconds : ShowAckTimeoutSeconds,
() => Fail(false));
_adPlayer.ShowAD(OnCloseAD, OnComplete);
isUpdate = false;
ADManager.Instance.RemoveUpdater(DoUpdate);
}
catch (Exception exception)
{
Debug.LogError(exception);
_showPendingHandler?.Kill();
Fail(false);
}
}
private void OnShowStarted()
{
if (isKill)
{
return;
}
_phase = AsyncPlayPhase.Playing;
_showPendingHandler?.Kill();
ADManager.Instance.CloseMask();
}
private void OnCloseAD() private void OnCloseAD()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
Debug.LogError("关闭广告: " + this._adPlayer.Key); Debug.LogError("关闭广告: " + _adPlayer.Key);
#endif #endif
_phase = AsyncPlayPhase.Closing;
_showPendingHandler?.Kill();
if (overHandler == null) if (overHandler == null)
{ {
overHandler = ADManager.Instance.CreateTimer(1.5f, () => overHandler = ADManager.Instance.CreateTimer(1.5f, () =>
{ {
this._callback?.Invoke(false); _callback?.Invoke(false);
Clear(); Clear();
}); });
} }
@@ -128,8 +175,10 @@ namespace Runtime.ADAggregator
private void OnComplete(bool obj) private void OnComplete(bool obj)
{ {
this.overHandler?.Kill(); _phase = AsyncPlayPhase.Completed;
this.overHandler = ADManager.Instance.CreateTimer(0.05f, () => _showPendingHandler?.Kill();
overHandler?.Kill();
overHandler = ADManager.Instance.CreateTimer(0.05f, () =>
{ {
if (_adPlayer != null && _adPlayer.ADType == AD_Type.AwardVideo) if (_adPlayer != null && _adPlayer.ADType == AD_Type.AwardVideo)
{ {
@@ -140,6 +189,12 @@ namespace Runtime.ADAggregator
}); });
} }
private void Fail(bool result)
{
_callback?.Invoke(result);
Kill();
}
//销毁广告 //销毁广告
public void Kill() public void Kill()
{ {
@@ -153,9 +208,16 @@ namespace Runtime.ADAggregator
{ {
ADManager.Instance.CloseMask(); ADManager.Instance.CloseMask();
isKill = true; isKill = true;
isUpdate = false;
if (_adPlayer != null)
{
_adPlayer.OnErrorAction = null;
_adPlayer.OnShowStartedAction = null;
}
_callback = null; _callback = null;
_adPlayer = null; _adPlayer = null;
this.overHandler = null; overHandler = null;
_showPendingHandler = null;
} }
} }
} }

View File

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