You've already forked CC-Framework.Commercialization
release: 1.0.14
This commit is contained in:
@@ -1,3 +1,11 @@
|
||||
# [1.0.14]
|
||||
|
||||
### 修复
|
||||
|
||||
* `AsyncAdPlayer` 增加展示确认阶段和统一失败收口,避免 `show` 发起后无回调时主链失联。
|
||||
* 抽象播放器补充展示超时配置与内部展示开始通知,保持外部调用接口不变。
|
||||
* 清理广告源级失败对主链的误接线,避免 `AdSource` 过程回调误判为最终失败。
|
||||
|
||||
# [1.0.13]
|
||||
|
||||
### 修复
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Runtime.ADAggregator
|
||||
public string AdScene;
|
||||
protected ADListener adListener;
|
||||
public Action OnErrorAction;
|
||||
public Action OnShowStartedAction;
|
||||
|
||||
public AD_Type ADType { get; internal set; }
|
||||
public int State => curState;
|
||||
@@ -33,6 +34,14 @@ namespace Runtime.ADAggregator
|
||||
}
|
||||
}
|
||||
|
||||
public virtual float ShowPendingTimeoutSeconds
|
||||
{
|
||||
get
|
||||
{
|
||||
return 5f;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool AutoPreloadOnInit
|
||||
{
|
||||
get
|
||||
@@ -83,6 +92,11 @@ namespace Runtime.ADAggregator
|
||||
{
|
||||
}
|
||||
|
||||
protected void NotifyShowStarted()
|
||||
{
|
||||
OnShowStartedAction?.Invoke();
|
||||
}
|
||||
|
||||
public void OnError(object code, string message)
|
||||
{
|
||||
this.OnErrorAction?.Invoke();
|
||||
|
||||
@@ -5,29 +5,40 @@ namespace Runtime.ADAggregator
|
||||
{
|
||||
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 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;
|
||||
private AdTimeHandler _showPendingHandler;
|
||||
private string _adScene;
|
||||
private AsyncPlayPhase _phase;
|
||||
private float _loadElapsed;
|
||||
|
||||
public AsyncAdPlayer(ADPlayer player , string adScene, Action<bool> callback)
|
||||
{
|
||||
|
||||
this._Ad_scene = adScene;
|
||||
this._outTime = 0;
|
||||
this._callback = callback;
|
||||
this.isKill = false;
|
||||
this.firstLoad = true;
|
||||
this.loadAttempts = 0;
|
||||
this.nextLoadRetryTime = 0f;
|
||||
this._adPlayer = player;
|
||||
_adScene = adScene;
|
||||
_loadElapsed = 0f;
|
||||
_callback = callback;
|
||||
isKill = false;
|
||||
loadAttempts = 0;
|
||||
nextLoadRetryTime = 0f;
|
||||
_adPlayer = player;
|
||||
_phase = AsyncPlayPhase.Loading;
|
||||
if (_adPlayer == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@@ -39,7 +50,8 @@ namespace Runtime.ADAggregator
|
||||
}
|
||||
ADManager.Instance.OpenMask();
|
||||
_adPlayer.OnErrorAction = OnError;
|
||||
_adPlayer.AdScene = this._Ad_scene;
|
||||
_adPlayer.OnShowStartedAction = OnShowStarted;
|
||||
_adPlayer.AdScene = _adScene;
|
||||
_adPlayer.OnPlayRequestStarted();
|
||||
isUpdate = true;
|
||||
ADManager.Instance.AddUpdater(DoUpdate);
|
||||
@@ -50,47 +62,47 @@ namespace Runtime.ADAggregator
|
||||
#if UNITY_EDITOR
|
||||
Debug.LogError("广告异常: " + this._adPlayer.Key);
|
||||
#endif
|
||||
// return;
|
||||
// if (isUpdate)
|
||||
// {
|
||||
// isUpdate = false;
|
||||
// ADManager.Instance.RemoveUpdater(DoUpdate);
|
||||
// }
|
||||
// ADManager.Instance.CloseMask();
|
||||
// _callback?.Invoke(false);
|
||||
// Clear();
|
||||
if (_phase == AsyncPlayPhase.Loading)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Fail(false);
|
||||
}
|
||||
|
||||
private void DoUpdate()
|
||||
{
|
||||
if (!isUpdate)
|
||||
return;
|
||||
_outTime += Time.deltaTime;
|
||||
var callback = _callback;
|
||||
if (this._outTime >= 15)
|
||||
{
|
||||
callback?.Invoke(false);
|
||||
Kill();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (_phase)
|
||||
{
|
||||
case AsyncPlayPhase.Loading:
|
||||
UpdateLoading();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateLoading()
|
||||
{
|
||||
_loadElapsed += Time.deltaTime;
|
||||
if (_loadElapsed >= LoadTimeoutSeconds)
|
||||
{
|
||||
Fail(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_adPlayer.IsReadly())
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Debug.LogError("开始播放广告: " + this._adPlayer.Key);
|
||||
#endif
|
||||
_adPlayer.ShowAD(OnCloseAD, OnComplete);
|
||||
if (_adPlayer.ADType != AD_Type.AwardVideo)
|
||||
{
|
||||
ADManager.Instance.CloseMask();
|
||||
}
|
||||
isUpdate = false;
|
||||
ADManager.Instance.RemoveUpdater(DoUpdate);
|
||||
BeginShow();
|
||||
}
|
||||
else if (!_adPlayer.IsLoading())
|
||||
{
|
||||
if (loadAttempts < _adPlayer.MaxLoadAttempts)
|
||||
{
|
||||
if (this._outTime < nextLoadRetryTime)
|
||||
if (_loadElapsed < nextLoadRetryTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -100,27 +112,62 @@ namespace Runtime.ADAggregator
|
||||
#endif
|
||||
_adPlayer.LoadAD();
|
||||
loadAttempts++;
|
||||
firstLoad = false;
|
||||
nextLoadRetryTime = this._outTime + _adPlayer.LoadRetryDelaySeconds;
|
||||
nextLoadRetryTime = _loadElapsed + _adPlayer.LoadRetryDelaySeconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
callback?.Invoke(false);
|
||||
Kill();
|
||||
Fail(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Debug.LogError("关闭广告: " + this._adPlayer.Key);
|
||||
Debug.LogError("关闭广告: " + _adPlayer.Key);
|
||||
#endif
|
||||
_phase = AsyncPlayPhase.Closing;
|
||||
_showPendingHandler?.Kill();
|
||||
if (overHandler == null)
|
||||
{
|
||||
overHandler = ADManager.Instance.CreateTimer(1.5f, () =>
|
||||
{
|
||||
this._callback?.Invoke(false);
|
||||
_callback?.Invoke(false);
|
||||
Clear();
|
||||
});
|
||||
}
|
||||
@@ -128,8 +175,10 @@ namespace Runtime.ADAggregator
|
||||
|
||||
private void OnComplete(bool obj)
|
||||
{
|
||||
this.overHandler?.Kill();
|
||||
this.overHandler = ADManager.Instance.CreateTimer(0.05f, () =>
|
||||
_phase = AsyncPlayPhase.Completed;
|
||||
_showPendingHandler?.Kill();
|
||||
overHandler?.Kill();
|
||||
overHandler = ADManager.Instance.CreateTimer(0.05f, () =>
|
||||
{
|
||||
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()
|
||||
{
|
||||
@@ -153,9 +208,16 @@ namespace Runtime.ADAggregator
|
||||
{
|
||||
ADManager.Instance.CloseMask();
|
||||
isKill = true;
|
||||
isUpdate = false;
|
||||
if (_adPlayer != null)
|
||||
{
|
||||
_adPlayer.OnErrorAction = null;
|
||||
_adPlayer.OnShowStartedAction = null;
|
||||
}
|
||||
_callback = null;
|
||||
_adPlayer = null;
|
||||
this.overHandler = null;
|
||||
overHandler = null;
|
||||
_showPendingHandler = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "com.foldcc.cc-framework.commercialization",
|
||||
"displayName": "CC-Framework.commercialization",
|
||||
"description": "商业化sdk通用组件,包含广告、内购、用户统计、归因统计等",
|
||||
"version": "1.0.13",
|
||||
"version": "1.0.14",
|
||||
"unity": "2021.1",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user