using TTSDK; using TTSDK.UNBridgeLib.LitJson; using UnityEngine; /// /// 广告管理器 /// public class AdMgr : MonoBehaviour { private static AdMgr instance; public static AdMgr Instance => instance; private void Awake() { if (instance != null) { Destroy(gameObject); return; } instance = this; } private TTRewardedVideoAd adInstance; //全局唯一的激励视频实例 private AdCallback callback; //广告播放完成回调 private object args; //回调参数 private void Start() { DontDestroyOnLoad(gameObject); Init(); } /// /// 初始化激励视频广告 /// private void Init() { string videoAdId = "8k6krp0rjl87k356al"; //激励视频广告id adInstance = TT.CreateRewardedVideoAd( videoAdId, (isClose, closeCode) => { Debug.Log("激励视频关闭 state: " + isClose + ", code: " + closeCode); if (isClose) { //广告数据ROI TT.SendToTAQ(new JsonData { ["event_type"] = "lt_roi" }); if (callback != null) { callback(args); } } }, (errorCode, errorMsg) => { Debug.Log("激励视频错误 " + errorCode); } ); } /// /// 显示激励视频广告 /// /// 广告显示完成回调 /// 回调参数 public void ShowAd(AdCallback callback, object args = null) { this.callback = callback; this.args = args; adInstance?.Show(); } } /// /// 广告显示完成回调 /// /// public delegate void AdCallback(object args);