using System; using System.Runtime.InteropServices; using UnityEngine; namespace WeChatWASM { /// /// 激励视频广告,详见 https://developers.weixin.qq.com/minigame/dev/guide/open-ability/ad/rewarded-video-ad.html /// public class WXRewardedVideoAd : WXBaseAd, IWXAdVideoCloseable { #if UNITY_WEBGL [DllImport("__Internal")] #endif private static extern string WXRewardedVideoAdReportShareBehavior(string id, string conf); public WXRewardedVideoAd(string id) : base(id) { } public void OnCloseCallback(WXRewardedVideoAdOnCloseResponse res) { onCloseAction?.Invoke(res); } public Action onCloseAction; /// /// 加载激励视频广告 /// public void Load(Action success = null, Action failed = null) { WXSDKManagerHandler.Instance.ADLoad(instanceId, WXCallBackHandler.Add(success), WXCallBackHandler.Add(failed)); } /// /// 监听用户点击 关闭广告 按钮的事件。 /// /// 用户点击 关闭广告 按钮的事件的回调函数 public void OnClose(Action action) { onCloseAction += action; } /// /// 取消监听用户点击 关闭广告 按钮的事件 /// /// 用户点击 关闭广告 按钮的事件的回调函数 public void OffClose(Action action) { onCloseAction -= action; } /// /// 上报行为 /// 需要基础库: `2.24.5` /// public WXRewardedVideoAdReportShareBehaviorResponse ReportShareBehavior(RequestAdReportShareBehaviorParam param) { var res = WXRewardedVideoAdReportShareBehavior(instanceId, JsonUtility.ToJson(param)); return JsonUtility.FromJson(res); } } }