2026-06-04 17:16:17 +08:00
|
|
|
using System;
|
|
|
|
|
using Dirichlet.Mediation;
|
|
|
|
|
using Runtime.ADAggregator;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public sealed class TapadnSplashPlayer : ADPlayer, IDirichletSplashAutoAdListener
|
|
|
|
|
{
|
|
|
|
|
private DirichletAdNative _adNative;
|
|
|
|
|
private DirichletSplashAd _loadedAd;
|
2026-06-04 17:24:54 +08:00
|
|
|
private bool _showSettled;
|
2026-06-04 17:16:17 +08:00
|
|
|
|
|
|
|
|
public override int MaxLoadAttempts => TapadnAdController.CurrentOptions?.SplashMaxLoadAttempts ?? base.MaxLoadAttempts;
|
|
|
|
|
public override float LoadRetryDelaySeconds => Math.Max(0f, (TapadnAdController.CurrentOptions?.SplashLoadRetryDelayMs ?? 500) / 1000f);
|
|
|
|
|
public override float ShowPendingTimeoutSeconds => Math.Max(1f, (TapadnAdController.CurrentOptions?.SplashShowTimeoutMs ?? 20000) / 1000f);
|
|
|
|
|
public override bool AutoPreloadOnInit => TapadnAdController.CurrentOptions?.SplashPrewarmOnInit ?? false;
|
|
|
|
|
|
|
|
|
|
public override void OnInit()
|
|
|
|
|
{
|
|
|
|
|
_adNative = DirichletAdManager.CreateAdNative();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool IsReadly()
|
|
|
|
|
{
|
|
|
|
|
if (UseAutoLoad())
|
|
|
|
|
{
|
|
|
|
|
return TapadnAdRequestFactory.TryParseSlotId(Key, out _);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_loadedAd != null && _loadedAd.IsLoaded && _loadedAd.IsValid)
|
|
|
|
|
{
|
|
|
|
|
curState = 2;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void LoadAD()
|
|
|
|
|
{
|
|
|
|
|
if (!TapadnAdRequestFactory.TryParseSlotId(Key, out _))
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError($"[TapADN] Invalid splash slot id: {Key}");
|
|
|
|
|
curState = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (UseAutoLoad())
|
|
|
|
|
{
|
|
|
|
|
curState = 2;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (curState == 1 || IsReadly())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
curState = 1;
|
2026-06-17 15:40:25 +08:00
|
|
|
TapadnSmartLoadOrchestrator.OnLoadStarted(AD_Type.Splash, AdScene, Key);
|
2026-06-04 17:16:17 +08:00
|
|
|
_adNative.LoadSplashAd(
|
|
|
|
|
TapadnAdRequestFactory.BuildSplash(Key, TapadnAdController.CurrentOptions),
|
|
|
|
|
ad =>
|
|
|
|
|
{
|
2026-06-17 15:40:25 +08:00
|
|
|
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Splash, AdScene, true, Key);
|
2026-06-04 17:16:17 +08:00
|
|
|
_loadedAd?.Destroy();
|
|
|
|
|
_loadedAd = ad;
|
|
|
|
|
_loadedAd.Shown += OnManualShown;
|
|
|
|
|
_loadedAd.Clicked += OnManualClicked;
|
2026-06-04 17:24:54 +08:00
|
|
|
_loadedAd.ShowFailed += OnManualShowFailed;
|
2026-06-04 17:16:17 +08:00
|
|
|
_loadedAd.Closed += OnManualClosed;
|
|
|
|
|
curState = 2;
|
|
|
|
|
Debug.Log($"[TapADN] Splash loaded. slot={Key}");
|
|
|
|
|
},
|
|
|
|
|
error =>
|
|
|
|
|
{
|
2026-06-17 15:40:25 +08:00
|
|
|
TapadnSmartLoadOrchestrator.OnLoadResult(AD_Type.Splash, AdScene, false, Key);
|
2026-06-04 17:16:17 +08:00
|
|
|
curState = 0;
|
|
|
|
|
Debug.LogError($"[TapADN] Splash load failed. code={error.Code}, message={error.Message}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
|
|
|
|
|
{
|
|
|
|
|
adListener.onClose = onClose;
|
|
|
|
|
adListener.onVideoComplete = onVideoComplete;
|
2026-06-04 17:24:54 +08:00
|
|
|
_showSettled = false;
|
2026-06-04 17:16:17 +08:00
|
|
|
curState = 0;
|
|
|
|
|
|
|
|
|
|
if (UseAutoLoad())
|
|
|
|
|
{
|
|
|
|
|
_adNative.ShowSplashAutoAd(TapadnAdRequestFactory.BuildSplash(Key, TapadnAdController.CurrentOptions), this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_loadedAd == null || !_loadedAd.Show())
|
|
|
|
|
{
|
2026-06-04 17:24:54 +08:00
|
|
|
OnError(new DirichletError("show_failed", "ShowSplashAd returned false"));
|
2026-06-04 17:16:17 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnError(DirichletError error)
|
|
|
|
|
{
|
2026-06-04 17:24:54 +08:00
|
|
|
if (_showSettled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_showSettled = true;
|
2026-06-17 15:40:25 +08:00
|
|
|
TapadnSmartLoadOrchestrator.OnShowError(AD_Type.Splash, AdScene, Key);
|
2026-06-04 17:16:17 +08:00
|
|
|
curState = 0;
|
|
|
|
|
Debug.LogError($"[TapADN] Splash show failed. code={error?.Code}, message={error?.Message}");
|
|
|
|
|
adListener.OnShowError();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnAdShow()
|
|
|
|
|
{
|
2026-06-17 15:40:25 +08:00
|
|
|
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Splash, AdScene, Key);
|
2026-06-04 17:16:17 +08:00
|
|
|
NotifyShowStarted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnAdClose()
|
|
|
|
|
{
|
2026-06-04 17:24:54 +08:00
|
|
|
if (_showSettled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_showSettled = true;
|
2026-06-04 17:16:17 +08:00
|
|
|
adListener.OnAdClose();
|
|
|
|
|
adListener.OnShowComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnAdClick()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-05 21:44:35 +08:00
|
|
|
public override void OnPlayRequestStarted()
|
|
|
|
|
{
|
2026-06-17 15:40:25 +08:00
|
|
|
TapadnSmartLoadOrchestrator.OnPlayRequestStarted(AD_Type.Splash, AdScene, !UseAutoLoad() && IsReadly(), Key);
|
2026-06-05 21:44:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void EnterAdScenario(string scenario)
|
|
|
|
|
{
|
2026-06-17 15:40:25 +08:00
|
|
|
AdScene = string.IsNullOrWhiteSpace(scenario) ? "__default__" : scenario.Trim();
|
|
|
|
|
TapadnSmartLoadOrchestrator.OnEnterAdScenario(AD_Type.Splash, AdScene, Key);
|
2026-06-05 21:44:35 +08:00
|
|
|
}
|
|
|
|
|
|
2026-06-04 17:16:17 +08:00
|
|
|
private bool UseAutoLoad()
|
|
|
|
|
{
|
|
|
|
|
return TapadnAdController.CurrentOptions?.SplashAutoLoad ?? true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnManualShown()
|
|
|
|
|
{
|
2026-06-17 15:40:25 +08:00
|
|
|
TapadnSmartLoadOrchestrator.OnShowStart(AD_Type.Splash, AdScene, Key);
|
2026-06-04 17:16:17 +08:00
|
|
|
NotifyShowStarted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnManualClicked()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-04 17:24:54 +08:00
|
|
|
private void OnManualShowFailed(DirichletError error)
|
|
|
|
|
{
|
|
|
|
|
OnError(error);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-04 17:16:17 +08:00
|
|
|
private void OnManualClosed()
|
|
|
|
|
{
|
|
|
|
|
_loadedAd?.Destroy();
|
|
|
|
|
_loadedAd = null;
|
|
|
|
|
OnAdClose();
|
|
|
|
|
}
|
|
|
|
|
}
|