2026-06-04 17:16:17 +08:00
|
|
|
using System;
|
|
|
|
|
using Dirichlet.Mediation;
|
|
|
|
|
using Runtime.ADAggregator;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2026-06-17 18:21:53 +08:00
|
|
|
public sealed class TapadnAdController : IAdController, IAdEditorDiagnostics
|
2026-06-04 17:16:17 +08:00
|
|
|
{
|
|
|
|
|
public static TapadnControllerOptions CurrentOptions { get; private set; }
|
|
|
|
|
public static string LastSdkVersion { get; private set; }
|
|
|
|
|
public static string LastInitError { get; private set; }
|
|
|
|
|
|
|
|
|
|
private Action<bool> _maskAction;
|
|
|
|
|
private Action<string, string> _logEventAction;
|
|
|
|
|
private ADConfig _adConfig;
|
|
|
|
|
private TapadnControllerOptions _options;
|
|
|
|
|
|
|
|
|
|
public void Init(ADConfig adConfig, object[] args)
|
|
|
|
|
{
|
|
|
|
|
_adConfig = adConfig;
|
|
|
|
|
_options = TapadnControllerOptions.Resolve(adConfig, args);
|
|
|
|
|
CurrentOptions = _options;
|
2026-06-05 21:44:35 +08:00
|
|
|
TapadnSmartLoadOrchestrator.Initialize(_options);
|
2026-06-04 17:16:17 +08:00
|
|
|
|
|
|
|
|
var sdkConfig = _options.BuildSdkConfig();
|
|
|
|
|
DirichletSdk.Init(
|
|
|
|
|
sdkConfig,
|
|
|
|
|
result =>
|
|
|
|
|
{
|
|
|
|
|
LastInitError = null;
|
|
|
|
|
LastSdkVersion = DirichletSdk.GetVersion();
|
|
|
|
|
EventLog("tapadn_init", "success", result?.Message);
|
|
|
|
|
Debug.Log($"[TapADN] Init success. version={LastSdkVersion}, message={result?.Message}");
|
|
|
|
|
if (_options.RequestPermissionOnInit)
|
|
|
|
|
{
|
|
|
|
|
DirichletSdk.RequestPermissionIfNecessary();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error =>
|
|
|
|
|
{
|
|
|
|
|
LastInitError = $"{error?.Code}:{error?.Message}";
|
|
|
|
|
EventLog("tapadn_init_error", error?.Code ?? "unknown", error?.Message);
|
|
|
|
|
Debug.LogError($"[TapADN] Init failed. code={error?.Code}, message={error?.Message}");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetListener(Action<bool> adMaskAction, Action<string, string> logEventAction)
|
|
|
|
|
{
|
|
|
|
|
_maskAction = adMaskAction;
|
|
|
|
|
_logEventAction = logEventAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ADPlayer CreateAdPlayer(AD_Type type)
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case AD_Type.AwardVideo:
|
|
|
|
|
return new TapadnAwardVideoPlayer().Init(_adConfig?.BaseAwardAdKeyValue?.value);
|
|
|
|
|
case AD_Type.Interaction:
|
|
|
|
|
return new TapadnInteractionPlayer().Init(_adConfig?.BaseInteractionAdKeyValue?.value);
|
|
|
|
|
case AD_Type.Splash:
|
|
|
|
|
return new TapadnSplashPlayer().Init(_adConfig?.BaseSplashAdKeyValue?.value);
|
|
|
|
|
default:
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void EventLog(string eventTable, string eventValue, string eventMessage = null)
|
|
|
|
|
{
|
|
|
|
|
_logEventAction?.Invoke(eventTable, eventValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetMask(bool isOpen)
|
|
|
|
|
{
|
|
|
|
|
_maskAction?.Invoke(isOpen);
|
|
|
|
|
}
|
2026-06-17 18:21:53 +08:00
|
|
|
|
|
|
|
|
public void LogEditorAdPlacement(ADConfig adConfig, AD_Type adType, string adScene, string action, object[] args)
|
|
|
|
|
{
|
|
|
|
|
var options = TapadnControllerOptions.Resolve(adConfig, args);
|
|
|
|
|
var normalizedScene = string.IsNullOrWhiteSpace(adScene) ? "__default__" : adScene.Trim();
|
|
|
|
|
var slotSource = "default";
|
|
|
|
|
var slotId = ResolveEditorSlotId(adConfig, options, adType, normalizedScene, out slotSource);
|
|
|
|
|
Debug.Log($"[TapADN] Editor ad {action}. type={adType}, scene={normalizedScene}, slot={DisplayEditorValue(slotId)}, source={slotSource}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string ResolveEditorSlotId(ADConfig adConfig, TapadnControllerOptions options, AD_Type adType, string adScene, out string slotSource)
|
|
|
|
|
{
|
|
|
|
|
slotSource = "default";
|
|
|
|
|
switch (adType)
|
|
|
|
|
{
|
|
|
|
|
case AD_Type.AwardVideo:
|
|
|
|
|
var defaultRewardedSlotId = adConfig?.BaseAwardAdKeyValue?.value;
|
|
|
|
|
var rewardedSlotId = options?.ResolveRewardedSlotId(defaultRewardedSlotId, adScene, out var mapped) ?? defaultRewardedSlotId;
|
|
|
|
|
slotSource = mapped ? "scene" : "default";
|
|
|
|
|
return rewardedSlotId;
|
|
|
|
|
case AD_Type.Interaction:
|
|
|
|
|
return adConfig?.BaseInteractionAdKeyValue?.value;
|
|
|
|
|
case AD_Type.Splash:
|
|
|
|
|
return adConfig?.BaseSplashAdKeyValue?.value;
|
|
|
|
|
default:
|
|
|
|
|
slotSource = "unsupported";
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string DisplayEditorValue(string value)
|
|
|
|
|
{
|
|
|
|
|
return string.IsNullOrWhiteSpace(value) ? "<empty>" : value.Trim();
|
|
|
|
|
}
|
2026-06-04 17:16:17 +08:00
|
|
|
}
|