You've already forked Commercialization.tapadn
Fix TapADN ad lifecycle callbacks
This commit is contained in:
@@ -752,6 +752,11 @@ namespace Dirichlet.Mediation
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action Closed;
|
public event Action Closed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised when the native layer reports that a loaded ad failed to show.
|
||||||
|
/// </summary>
|
||||||
|
public event Action<DirichletError> ShowFailed;
|
||||||
|
|
||||||
internal DirichletAd(IDirichletPlatformBridge bridge, DirichletPlatformAdHandle platformHandle, long spaceId)
|
internal DirichletAd(IDirichletPlatformBridge bridge, DirichletPlatformAdHandle platformHandle, long spaceId)
|
||||||
{
|
{
|
||||||
this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));
|
this.bridge = bridge ?? throw new ArgumentNullException(nameof(bridge));
|
||||||
@@ -812,6 +817,9 @@ namespace Dirichlet.Mediation
|
|||||||
case DirichletNativeEventNames.Close:
|
case DirichletNativeEventNames.Close:
|
||||||
OnClosed();
|
OnClosed();
|
||||||
break;
|
break;
|
||||||
|
case DirichletNativeEventNames.ShowError:
|
||||||
|
OnShowFailed(nativeEvent.Data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -829,6 +837,13 @@ namespace Dirichlet.Mediation
|
|||||||
{
|
{
|
||||||
Closed?.Invoke();
|
Closed?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void OnShowFailed(DirichletNativeEventData data)
|
||||||
|
{
|
||||||
|
var code = data != null && data.Code != 0 ? data.Code.ToString(CultureInfo.InvariantCulture) : "show_error";
|
||||||
|
var message = data?.Message;
|
||||||
|
ShowFailed?.Invoke(new DirichletError(code, string.IsNullOrEmpty(message) ? "Ad failed to show" : message));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class DirichletRewardAdBase : DirichletAd
|
public abstract class DirichletRewardAdBase : DirichletAd
|
||||||
@@ -1085,6 +1100,7 @@ namespace Dirichlet.Mediation
|
|||||||
internal const string Click = "click";
|
internal const string Click = "click";
|
||||||
internal const string Close = "close";
|
internal const string Close = "close";
|
||||||
internal const string Reward = "reward";
|
internal const string Reward = "reward";
|
||||||
|
internal const string ShowError = "show_error";
|
||||||
}
|
}
|
||||||
|
|
||||||
internal readonly struct DirichletNativeEvent
|
internal readonly struct DirichletNativeEvent
|
||||||
@@ -1373,4 +1389,3 @@ namespace Dirichlet.Mediation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,15 @@ using UnityEngine;
|
|||||||
|
|
||||||
public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAutoAdListener
|
public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAutoAdListener
|
||||||
{
|
{
|
||||||
|
private const float RewardCloseSettleDelaySeconds = 0.25f;
|
||||||
|
|
||||||
private DirichletAdNative _adNative;
|
private DirichletAdNative _adNative;
|
||||||
private DirichletRewardVideoAd _loadedAd;
|
private DirichletRewardVideoAd _loadedAd;
|
||||||
private bool _rewardVerified;
|
private bool _rewardVerified;
|
||||||
|
private bool _rewardVerifyReceived;
|
||||||
|
private bool _closePendingRewardVerify;
|
||||||
|
private bool _showSettled;
|
||||||
|
private AdTimeHandler _rewardCloseSettleHandler;
|
||||||
|
|
||||||
public override int MaxLoadAttempts => TapadnAdController.CurrentOptions?.RewardedMaxLoadAttempts ?? base.MaxLoadAttempts;
|
public override int MaxLoadAttempts => TapadnAdController.CurrentOptions?.RewardedMaxLoadAttempts ?? base.MaxLoadAttempts;
|
||||||
public override float LoadRetryDelaySeconds => Math.Max(0f, (TapadnAdController.CurrentOptions?.RewardedLoadRetryDelayMs ?? 500) / 1000f);
|
public override float LoadRetryDelaySeconds => Math.Max(0f, (TapadnAdController.CurrentOptions?.RewardedLoadRetryDelayMs ?? 500) / 1000f);
|
||||||
@@ -72,6 +78,7 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
|||||||
_loadedAd = ad;
|
_loadedAd = ad;
|
||||||
_loadedAd.Shown += OnManualShown;
|
_loadedAd.Shown += OnManualShown;
|
||||||
_loadedAd.Clicked += OnManualClicked;
|
_loadedAd.Clicked += OnManualClicked;
|
||||||
|
_loadedAd.ShowFailed += OnManualShowFailed;
|
||||||
_loadedAd.RewardVerified += OnManualRewardVerify;
|
_loadedAd.RewardVerified += OnManualRewardVerify;
|
||||||
_loadedAd.Closed += OnManualClosed;
|
_loadedAd.Closed += OnManualClosed;
|
||||||
curState = 2;
|
curState = 2;
|
||||||
@@ -89,6 +96,11 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
|||||||
adListener.onClose = onClose;
|
adListener.onClose = onClose;
|
||||||
adListener.onVideoComplete = onVideoComplete;
|
adListener.onVideoComplete = onVideoComplete;
|
||||||
_rewardVerified = false;
|
_rewardVerified = false;
|
||||||
|
_rewardVerifyReceived = false;
|
||||||
|
_closePendingRewardVerify = false;
|
||||||
|
_showSettled = false;
|
||||||
|
_rewardCloseSettleHandler?.Kill();
|
||||||
|
_rewardCloseSettleHandler = null;
|
||||||
curState = 0;
|
curState = 0;
|
||||||
|
|
||||||
if (UseAutoLoad())
|
if (UseAutoLoad())
|
||||||
@@ -99,13 +111,21 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
|||||||
|
|
||||||
if (_loadedAd == null || !_loadedAd.Show())
|
if (_loadedAd == null || !_loadedAd.Show())
|
||||||
{
|
{
|
||||||
adListener.OnShowError();
|
OnError(new DirichletError("show_failed", "ShowRewardVideoAd returned false"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnError(DirichletError error)
|
public void OnError(DirichletError error)
|
||||||
{
|
{
|
||||||
|
if (_showSettled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_showSettled = true;
|
||||||
|
_rewardCloseSettleHandler?.Kill();
|
||||||
|
_rewardCloseSettleHandler = null;
|
||||||
curState = 0;
|
curState = 0;
|
||||||
Debug.LogError($"[TapADN] Rewarded show failed. code={error?.Code}, message={error?.Message}");
|
Debug.LogError($"[TapADN] Rewarded show failed. code={error?.Code}, message={error?.Message}");
|
||||||
adListener.OnShowError();
|
adListener.OnShowError();
|
||||||
@@ -118,13 +138,30 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
|||||||
|
|
||||||
public void OnAdClose()
|
public void OnAdClose()
|
||||||
{
|
{
|
||||||
adListener.OnRewardVerify(_rewardVerified, TapadnAdController.CurrentOptions?.RewardAmount ?? 1, TapadnAdController.CurrentOptions?.RewardName ?? string.Empty);
|
if (_showSettled)
|
||||||
adListener.OnAdClose();
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_rewardVerifyReceived)
|
||||||
|
{
|
||||||
|
CompleteRewardedClose();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_closePendingRewardVerify = true;
|
||||||
|
_rewardCloseSettleHandler?.Kill();
|
||||||
|
_rewardCloseSettleHandler = ADManager.Instance.CreateTimer(RewardCloseSettleDelaySeconds, CompleteRewardedClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnRewardVerify(DirichletRewardVerificationEventArgs args)
|
public void OnRewardVerify(DirichletRewardVerificationEventArgs args)
|
||||||
{
|
{
|
||||||
|
_rewardVerifyReceived = true;
|
||||||
_rewardVerified = args != null && args.IsVerified;
|
_rewardVerified = args != null && args.IsVerified;
|
||||||
|
if (_closePendingRewardVerify)
|
||||||
|
{
|
||||||
|
CompleteRewardedClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnAdClick()
|
public void OnAdClick()
|
||||||
@@ -145,9 +182,14 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnManualShowFailed(DirichletError error)
|
||||||
|
{
|
||||||
|
OnError(error);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnManualRewardVerify(DirichletRewardVerificationEventArgs args)
|
private void OnManualRewardVerify(DirichletRewardVerificationEventArgs args)
|
||||||
{
|
{
|
||||||
_rewardVerified = args != null && args.IsVerified;
|
OnRewardVerify(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnManualClosed()
|
private void OnManualClosed()
|
||||||
@@ -156,4 +198,19 @@ public sealed class TapadnAwardVideoPlayer : ADPlayer, IDirichletRewardVideoAuto
|
|||||||
_loadedAd = null;
|
_loadedAd = null;
|
||||||
OnAdClose();
|
OnAdClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CompleteRewardedClose()
|
||||||
|
{
|
||||||
|
if (_showSettled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_showSettled = true;
|
||||||
|
_closePendingRewardVerify = false;
|
||||||
|
_rewardCloseSettleHandler?.Kill();
|
||||||
|
_rewardCloseSettleHandler = null;
|
||||||
|
adListener.OnRewardVerify(_rewardVerified, TapadnAdController.CurrentOptions?.RewardAmount ?? 1, TapadnAdController.CurrentOptions?.RewardName ?? string.Empty);
|
||||||
|
adListener.OnAdClose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
|||||||
{
|
{
|
||||||
private DirichletAdNative _adNative;
|
private DirichletAdNative _adNative;
|
||||||
private DirichletInterstitialAd _loadedAd;
|
private DirichletInterstitialAd _loadedAd;
|
||||||
|
private bool _showSettled;
|
||||||
|
|
||||||
public override int MaxLoadAttempts => TapadnAdController.CurrentOptions?.InterstitialMaxLoadAttempts ?? base.MaxLoadAttempts;
|
public override int MaxLoadAttempts => TapadnAdController.CurrentOptions?.InterstitialMaxLoadAttempts ?? base.MaxLoadAttempts;
|
||||||
public override float LoadRetryDelaySeconds => Math.Max(0f, (TapadnAdController.CurrentOptions?.InterstitialLoadRetryDelayMs ?? 500) / 1000f);
|
public override float LoadRetryDelaySeconds => Math.Max(0f, (TapadnAdController.CurrentOptions?.InterstitialLoadRetryDelayMs ?? 500) / 1000f);
|
||||||
@@ -63,6 +64,7 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
|||||||
_loadedAd = ad;
|
_loadedAd = ad;
|
||||||
_loadedAd.Shown += OnManualShown;
|
_loadedAd.Shown += OnManualShown;
|
||||||
_loadedAd.Clicked += OnManualClicked;
|
_loadedAd.Clicked += OnManualClicked;
|
||||||
|
_loadedAd.ShowFailed += OnManualShowFailed;
|
||||||
_loadedAd.Closed += OnManualClosed;
|
_loadedAd.Closed += OnManualClosed;
|
||||||
curState = 2;
|
curState = 2;
|
||||||
Debug.Log($"[TapADN] Interstitial loaded. slot={Key}");
|
Debug.Log($"[TapADN] Interstitial loaded. slot={Key}");
|
||||||
@@ -78,6 +80,7 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
|||||||
{
|
{
|
||||||
adListener.onClose = onClose;
|
adListener.onClose = onClose;
|
||||||
adListener.onVideoComplete = onVideoComplete;
|
adListener.onVideoComplete = onVideoComplete;
|
||||||
|
_showSettled = false;
|
||||||
curState = 0;
|
curState = 0;
|
||||||
|
|
||||||
if (UseAutoLoad())
|
if (UseAutoLoad())
|
||||||
@@ -88,12 +91,18 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
|||||||
|
|
||||||
if (_loadedAd == null || !_loadedAd.Show())
|
if (_loadedAd == null || !_loadedAd.Show())
|
||||||
{
|
{
|
||||||
adListener.OnShowError();
|
OnError(new DirichletError("show_failed", "ShowInterstitialAd returned false"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnError(DirichletError error)
|
public void OnError(DirichletError error)
|
||||||
{
|
{
|
||||||
|
if (_showSettled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_showSettled = true;
|
||||||
curState = 0;
|
curState = 0;
|
||||||
Debug.LogError($"[TapADN] Interstitial show failed. code={error?.Code}, message={error?.Message}");
|
Debug.LogError($"[TapADN] Interstitial show failed. code={error?.Code}, message={error?.Message}");
|
||||||
adListener.OnShowError();
|
adListener.OnShowError();
|
||||||
@@ -106,6 +115,12 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
|||||||
|
|
||||||
public void OnAdClose()
|
public void OnAdClose()
|
||||||
{
|
{
|
||||||
|
if (_showSettled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_showSettled = true;
|
||||||
adListener.OnAdClose();
|
adListener.OnAdClose();
|
||||||
adListener.OnShowComplete();
|
adListener.OnShowComplete();
|
||||||
}
|
}
|
||||||
@@ -128,6 +143,11 @@ public sealed class TapadnInteractionPlayer : ADPlayer, IDirichletInterstitialAu
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnManualShowFailed(DirichletError error)
|
||||||
|
{
|
||||||
|
OnError(error);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnManualClosed()
|
private void OnManualClosed()
|
||||||
{
|
{
|
||||||
_loadedAd?.Destroy();
|
_loadedAd?.Destroy();
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
|||||||
{
|
{
|
||||||
private DirichletAdNative _adNative;
|
private DirichletAdNative _adNative;
|
||||||
private DirichletSplashAd _loadedAd;
|
private DirichletSplashAd _loadedAd;
|
||||||
|
private bool _showSettled;
|
||||||
|
|
||||||
public override int MaxLoadAttempts => TapadnAdController.CurrentOptions?.SplashMaxLoadAttempts ?? base.MaxLoadAttempts;
|
public override int MaxLoadAttempts => TapadnAdController.CurrentOptions?.SplashMaxLoadAttempts ?? base.MaxLoadAttempts;
|
||||||
public override float LoadRetryDelaySeconds => Math.Max(0f, (TapadnAdController.CurrentOptions?.SplashLoadRetryDelayMs ?? 500) / 1000f);
|
public override float LoadRetryDelaySeconds => Math.Max(0f, (TapadnAdController.CurrentOptions?.SplashLoadRetryDelayMs ?? 500) / 1000f);
|
||||||
@@ -63,6 +64,7 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
|||||||
_loadedAd = ad;
|
_loadedAd = ad;
|
||||||
_loadedAd.Shown += OnManualShown;
|
_loadedAd.Shown += OnManualShown;
|
||||||
_loadedAd.Clicked += OnManualClicked;
|
_loadedAd.Clicked += OnManualClicked;
|
||||||
|
_loadedAd.ShowFailed += OnManualShowFailed;
|
||||||
_loadedAd.Closed += OnManualClosed;
|
_loadedAd.Closed += OnManualClosed;
|
||||||
curState = 2;
|
curState = 2;
|
||||||
Debug.Log($"[TapADN] Splash loaded. slot={Key}");
|
Debug.Log($"[TapADN] Splash loaded. slot={Key}");
|
||||||
@@ -78,6 +80,7 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
|||||||
{
|
{
|
||||||
adListener.onClose = onClose;
|
adListener.onClose = onClose;
|
||||||
adListener.onVideoComplete = onVideoComplete;
|
adListener.onVideoComplete = onVideoComplete;
|
||||||
|
_showSettled = false;
|
||||||
curState = 0;
|
curState = 0;
|
||||||
|
|
||||||
if (UseAutoLoad())
|
if (UseAutoLoad())
|
||||||
@@ -88,12 +91,18 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
|||||||
|
|
||||||
if (_loadedAd == null || !_loadedAd.Show())
|
if (_loadedAd == null || !_loadedAd.Show())
|
||||||
{
|
{
|
||||||
adListener.OnShowError();
|
OnError(new DirichletError("show_failed", "ShowSplashAd returned false"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnError(DirichletError error)
|
public void OnError(DirichletError error)
|
||||||
{
|
{
|
||||||
|
if (_showSettled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_showSettled = true;
|
||||||
curState = 0;
|
curState = 0;
|
||||||
Debug.LogError($"[TapADN] Splash show failed. code={error?.Code}, message={error?.Message}");
|
Debug.LogError($"[TapADN] Splash show failed. code={error?.Code}, message={error?.Message}");
|
||||||
adListener.OnShowError();
|
adListener.OnShowError();
|
||||||
@@ -106,6 +115,12 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
|||||||
|
|
||||||
public void OnAdClose()
|
public void OnAdClose()
|
||||||
{
|
{
|
||||||
|
if (_showSettled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_showSettled = true;
|
||||||
adListener.OnAdClose();
|
adListener.OnAdClose();
|
||||||
adListener.OnShowComplete();
|
adListener.OnShowComplete();
|
||||||
}
|
}
|
||||||
@@ -128,6 +143,11 @@ public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListene
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnManualShowFailed(DirichletError error)
|
||||||
|
{
|
||||||
|
OnError(error);
|
||||||
|
}
|
||||||
|
|
||||||
private void OnManualClosed()
|
private void OnManualClosed()
|
||||||
{
|
{
|
||||||
_loadedAd?.Destroy();
|
_loadedAd?.Destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user