赞
踩
Google 广告接入参考
a.地址
GoogleAdMob网址:
https://apps.admob.com/v2/apps/5239834645/overview?utm_source=internal&utm_medium=et&utm_campaign=helpcentrecontextualopt&utm_term=http%3A%2F%2Fgoo.gl%2F6Xkfcf&subid=ww-ww-et-amhelpv4&pli=1
Unity SDK 地址: https://developers.google.cn/admob/unity/quick-start
示例工程地址:
https://github.com/googleads/googleads-mobile-unity/tree/main/samples/HelloWorld
插件下载:如下图
下载之后直接导入,然后需要设置在GoogleAdMob中申请的应用id
b. 插件导入之后unity设置如下:
Assets > Google Mobile Ads > Settings之后出现如下图:
using UnityEngine.Events; using UnityEngine; using GoogleMobileAds.Api; using GoogleMobileAds.Common; using UnityEngine.UI; using System; using System.Collections.Generic; public class GoogleAdMobSDK : MonoBehaviour { public Text infoText; #region #if UNITY_IPHONE /// <summary> /// 开屏广告 /// </summary> private readonly string AppOpenAdID = "ca-app-pub-3940256099942544/5662855259"; /// <summary> /// 横幅广告 /// </summary> private readonly string BannerAdID = "ca-app-pub-3940256099942544/2934735716"; /// <summary> /// 插页式广告 /// </summary> private readonly string InterstitialAdID = "ca-app-pub-3940256099942544/4411468910"; /// <summary> /// 激励广告 /// </summary> private readonly string RewardedAdID = "ca-app-pub-3940256099942544/1712485313"; /// <summary> /// 插页式激励广告 /// </summary> private readonly string RewardedInterstitialAdID = "ca-app-pub-3940256099942544/6978759866"; /// <summary> /// 原生广告 /// </summary> private readonly string NativeAdID = "ca-app-pub-3940256099942544/3986624511"; #elif UNITY_ANDROID /// <summary> /// 开屏广告 /// </summary> private readonly string AppOpenAdID = "ca-app-pub-3940256099942544/3419835294"; /// <summary> /// 横幅广告 /// </summary> private readonly string BannerAdID = "ca-app-pub-3940256099942544/6300978111"; /// <summary> /// 插页式广告 /// </summary> private readonly string InterstitialAdID = "ca-app-pub-3940256099942544/1033173712"; /// <summary> /// 激励广告 /// </summary> private readonly string RewardedAdID = "ca-app-pub-3940256099942544/5224354917"; /// <summary> /// 插页式激励广告 /// </summary> private readonly string RewardedInterstitialAdID = "ca-app-pub-3940256099942544/5354046379"; /// <summary> /// 原生广告 /// </summary> private readonly string NativeAdID = "ca-app-pub-3940256099942544/2247696110"; #endif #endregion private readonly TimeSpan APPOPEN_TIMEOUT = TimeSpan.FromHours(4); private DateTime appOpenExpireTime; private AppOpenAd appOpenAd; private BannerView bannerView; private InterstitialAd interstitialAd; private RewardedAd rewardedAd; private RewardedInterstitialAd rewardedInterstitialAd; private float deltaTime; private bool isShowingAppOpenAd; public UnityEvent OnAdLoadedEvent; public UnityEvent OnAdFailedToLoadEvent; public UnityEvent OnAdOpeningEvent; public UnityEvent OnAdFailedToShowEvent; public UnityEvent OnUserEarnedRewardEvent; public UnityEvent OnAdClosedEvent; public bool showFpsMeter = true; #region UNITY MONOBEHAVIOR METHODS public void Start() { MobileAds.SetiOSAppPauseOnBackground(true); List<String> deviceIds = new List<String>() { AdRequest.TestDeviceSimulator }; // 添加一些测试设备 ID(替换为您自己的设备 ID)。 #if UNITY_IPHONE deviceIds.Add("96e23e80653bb28980d3f40beb58915c"); #elif UNITY_ANDROID deviceIds.Add("75EF8D155528C04DACBBA6F36F433035"); #endif //配置 TagForChildDirectedTreatment 并测试设备 ID。 RequestConfiguration requestConfiguration = new RequestConfiguration.Builder() .SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.Unspecified) .SetTestDeviceIds(deviceIds).build(); MobileAds.SetRequestConfiguration(requestConfiguration); // 初始化 Google 移动广告 SDK。 MobileAds.Initialize(HandleInitCompleteAction); // 监听应用程序前台/后台事件。 AppStateEventNotifier.AppStateChanged += OnAppStateChanged; } private void HandleInitCompleteAction(InitializationStatus initstatus) { PrintStatus("Initialization complete."); // 不能保证调用来自 GoogleMobileAds 的回调 // 主线程。 // 在本例中,我们使用 MobileAdsEventExecutor 来安排这些调用 // 下一个 Update() 循环。 MobileAdsEventExecutor.ExecuteInUpdate(() => { //statusText.text = "Initialization complete."; RequestBannerAd(); }); } private void Update() { //if (showFpsMeter) //{ // fpsMeter.gameObject.SetActive(true); // deltaTime += (Time.deltaTime - deltaTime) * 0.1f; // float fps = 1.0f / deltaTime; // fpsMeter.text = string.Format("{0:0.} fps", fps); //} //else //{ // fpsMeter.gameObject.SetActive(false); //} } #endregion #region HELPER METHODS /// <summary> /// 创建广告请求 /// </summary> /// <returns></returns> private AdRequest CreateAdRequest() { return new AdRequest.Builder() .AddKeyword("unity-admob-sample") .Build(); } #endregion #region 横幅广告 /// <summary> /// 请求横幅广告 /// </summary> public void RequestBannerAd() { this.ClearAdUnityAction(); PrintStatus("请求横幅广告"); // 这些广告单元配置为始终投放测试广告。 string adUnitId = this.BannerAdID; //#if UNITY_EDITOR // string adUnitId = "unused"; //#elif UNITY_ANDROID // string adUnitId = "ca-app-pub-3940256099942544/6300978111"; //#elif UNITY_IPHONE // string adUnitId = "ca-app-pub-3940256099942544/2934735716"; //#else // string adUnitId = "unexpected_platform"; //#endif // 在重用之前清理横幅 if (bannerView != null) { bannerView.Destroy(); } // Create a 320x50 banner at top of the screen bannerView = new BannerView(adUnitId, AdSize.SmartBanner, AdPosition.Bottom); // 广告加载完成时,系统会执行 OnAdLoaded 事件。 bannerView.OnAdLoaded += (sender, args) => { PrintStatus("横幅广告已加载。"); OnAdLoadedEvent.Invoke(); }; //广告加载失败时,系统会调用 OnAdFailedToLoad 事件。Message 参数描述发生的故障类型。 bannerView.OnAdFailedToLoad += (sender, args) => { PrintStatus("横幅广告无法加载并出现错误:" + args.LoadAdError.GetMessage()); OnAdFailedToLoadEvent.Invoke(); }; //用户点按广告时,系统会调用此方法。如果您使用分析产品包跟踪点击,则此方法很适合记录点击。 bannerView.OnAdOpening += (sender, args) => { PrintStatus("横幅广告打开"); OnAdOpeningEvent.Invoke(); }; //用户查看了广告的目标网址并返回应用时,系统会调用此方法。应用可以使用此方法恢复暂停的活动,或执行任何其他必要的操作,以做好互动准备。 bannerView.OnAdClosed += (sender, args) => { PrintStatus("横幅广告关闭"); OnAdClosedEvent.Invoke(); }; //付费活动 bannerView.OnPaidEvent += (sender, args) => { string msg = string.Format("{0} (currency: {1}, value: {2}", "横幅广告收到了付费事件。", args.AdValue.CurrencyCode, args.AdValue.Value); PrintStatus(msg); }; // 加载横幅广告 bannerView.LoadAd(CreateAdRequest()); } /// <summary> /// 销毁横幅广告 /// </summary> public void DestroyBannerAd() { if (bannerView != null) { bannerView.Destroy(); } } #endregion #region 插页式广告 /// <summary> /// 请求和加载插页式广告 /// </summary> public void RequestAndLoadInterstitialAd() { this.ClearAdUnityAction(); PrintStatus("请求插页式广告"); string adUnitId = this.InterstitialAdID; //#if UNITY_EDITOR // string adUnitId = "unused"; //#elif UNITY_ANDROID // string adUnitId = "ca-app-pub-3940256099942544/1033173712"; //#elif UNITY_IPHONE // string adUnitId = "ca-app-pub-3940256099942544/4411468910"; //#else // string adUnitId = "unexpected_platform"; //#endif // 使用前清理插页式广告 if (interstitialAd != null) { interstitialAd.Destroy(); } interstitialAd = new InterstitialAd(adUnitId); // 添加事件处理程序 //广告加载完成时,系统会执行 OnAdLoaded 事件。 interstitialAd.OnAdLoaded += (sender, args) => { PrintStatus("已加载插页式广告。"); OnAdLoadedEvent.Invoke(); }; //广告加载失败时,系统会调用 OnAdFailedToLoad 事件。Message 参数用于描述发生了何种类型的失败。 interstitialAd.OnAdFailedToLoad += (sender, args) => { PrintStatus("插页式广告未能加载并出现错误: " + args.LoadAdError.GetMessage()); OnAdFailedToLoadEvent.Invoke(); }; //在广告开始展示并铺满设备屏幕时,系统会调用此方法。 interstitialAd.OnAdOpening += (sender, args) => { PrintStatus("插页式广告 打开."); OnAdOpeningEvent.Invoke(); }; //此方法会在用户点按“关闭”图标或使用“返回”按钮关闭插页式广告时被调用。如果您的应用暂停了音频输出或游戏循环,则非常适合使用此方法恢复这些活动。 interstitialAd.OnAdClosed += (sender, args) => { PrintStatus("插页式广告关闭."); OnAdClosedEvent.Invoke(); }; //插页式广告记录了一次展示。 interstitialAd.OnAdDidRecordImpression += (sender, args) => { PrintStatus("插页式广告记录了一次展示。"); }; //插页式广告未能展示 interstitialAd.OnAdFailedToShow += (sender, args) => { PrintStatus("插页式广告未能展示"); }; //付费活动 interstitialAd.OnPaidEvent += (sender, args) => { string msg = string.Format("{0} (currency: {1}, value: {2}", "插页式广告收到了付费事件。", args.AdValue.CurrencyCode, args.AdValue.Value); PrintStatus(msg); }; // 加载插页式广告 interstitialAd.LoadAd(CreateAdRequest()); } /// <summary> /// 展示插页式广告 /// </summary> public void ShowInterstitialAd() { if (interstitialAd != null && interstitialAd.IsLoaded()) { interstitialAd.Show(); } else { PrintStatus("插页式广告尚未准备就绪。"); } } /// <summary> /// 销毁插页式广告 /// </summary> public void DestroyInterstitialAd() { if (interstitialAd != null) { interstitialAd.Destroy(); } } #endregion #region 激励广告 /// <summary> /// 请求和加载激励广告 /// </summary> public void RequestAndLoadRewardedAd() { this.ClearAdUnityAction(); PrintStatus("请求激励广告"); string adUnitId = this.RewardedAdID; //#if UNITY_EDITOR // string adUnitId = "unused"; //#elif UNITY_ANDROID // string adUnitId = "ca-app-pub-3940256099942544/5224354917"; //#elif UNITY_IPHONE // string adUnitId = "ca-app-pub-3940256099942544/1712485313"; //#else // string adUnitId = "unexpected_platform"; //#endif // 创建新的激励广告实例 rewardedAd = new RewardedAd(adUnitId); // 添加事件处理程序 //在广告加载完成时被调用。 rewardedAd.OnAdLoaded += (sender, args) => { PrintStatus("已加载激励广告。"); OnAdLoadedEvent.Invoke(); this.ShowRewardedAd(); }; //在广告加载失败时被调用。提供的 AdErrorEventArgs 的 Message 属性用于描述发生了何种类型的失败。 rewardedAd.OnAdFailedToLoad += (sender, args) => { PrintStatus("激励广告加载失败。"); OnAdFailedToLoadEvent.Invoke(); }; //在广告开始展示并铺满设备屏幕时被调用。如需暂停应用音频输出或游戏循环,则非常适合使用此方法。 rewardedAd.OnAdOpening += (sender, args) => { PrintStatus("激励广告 打开."); OnAdOpeningEvent.Invoke(); }; //在广告显示失败时被调用。提供的 AdErrorEventArgs 的 Message 属性用于描述发生了何种类型的失败。 rewardedAd.OnAdFailedToShow += (sender, args) => { PrintStatus("激励广告未能展示并出现以下错误:" + args.AdError.GetMessage()); OnAdFailedToShowEvent.Invoke(); }; //在用户点按“关闭”图标或使用“返回”按钮关闭激励视频广告时被调用。如果您的应用暂停了音频输出或游戏循环,则非常适合使用此方法恢复这些活动 rewardedAd.OnAdClosed += (sender, args) => { PrintStatus("激励广告 关闭."); OnAdClosedEvent.Invoke(); }; //用户获得的激励广告奖励: rewardedAd.OnUserEarnedReward += (sender, args) => { PrintStatus("用户获得的奖励广告奖励:" + args.Amount); OnUserEarnedRewardEvent.Invoke(); }; //激励广告记录了一次展示。 rewardedAd.OnAdDidRecordImpression += (sender, args) => { PrintStatus("激励广告记录了一次展示"); }; rewardedAd.OnPaidEvent += (sender, args) => { string msg = string.Format("{0} (currency: {1}, value: {2}", "激励广告收到了付费事件。", args.AdValue.CurrencyCode, args.AdValue.Value); PrintStatus(msg); }; // Create empty ad request rewardedAd.LoadAd(CreateAdRequest()); } /// <summary> /// 展示激励广告 /// </summary> public void ShowRewardedAd() { PrintStatus("展示激励广告" + (rewardedAd != null)); if (rewardedAd != null) { rewardedAd.Show(); } else { PrintStatus("奖励广告尚未准备就绪。"); } } /// <summary> /// 请求和加载插页式广告 /// </summary> public void RequestAndLoadRewardedInterstitialAd() { this.ClearAdUnityAction(); PrintStatus("请求插页式广告"); // 这些广告单元配置为始终投放测试广告。 string adUnitId = this.RewardedInterstitialAdID; //#if UNITY_EDITOR // string adUnitId = "unused"; //#elif UNITY_ANDROID // string adUnitId = "ca-app-pub-3940256099942544/5354046379"; //#elif UNITY_IPHONE // string adUnitId = "ca-app-pub-3940256099942544/6978759866"; //#else // string adUnitId = "unexpected_platform"; //#endif // 创建插页式广告。 RewardedInterstitialAd.LoadAd(adUnitId, CreateAdRequest(), (rewardedInterstitialAd, error) => { if (error != null) { PrintStatus("奖励插页式广告加载失败并出现错误: " + error); return; } this.rewardedInterstitialAd = rewardedInterstitialAd; PrintStatus("已加载奖励插页式广告。"); // Register for ad events. this.rewardedInterstitialAd.OnAdDidPresentFullScreenContent += (sender, args) => { PrintStatus("展示了奖励插页式广告。"); }; this.rewardedInterstitialAd.OnAdDidDismissFullScreenContent += (sender, args) => { PrintStatus("奖励插页式广告已关闭。"); this.rewardedInterstitialAd = null; }; this.rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += (sender, args) => { PrintStatus("奖励插页式广告未能展示并出现错误: " + args.AdError.GetMessage()); this.rewardedInterstitialAd = null; }; this.rewardedInterstitialAd.OnPaidEvent += (sender, args) => { string msg = string.Format("{0} (currency: {1}, value: {2}", "奖励插页式广告收到了付费事件。", args.AdValue.CurrencyCode, args.AdValue.Value); PrintStatus(msg); }; this.rewardedInterstitialAd.OnAdDidRecordImpression += (sender, args) => { PrintStatus("奖励插页式广告记录了一次展示。"); }; }); } /// <summary> /// 展示插页式广告 /// </summary> public void ShowRewardedInterstitialAd() { if (rewardedInterstitialAd != null) { rewardedInterstitialAd.Show((reward) => { PrintStatus("奖励插页式广告 奖励:" + reward.Amount); }); } else { PrintStatus("激励式插页式广告尚未准备就绪。"); } } #endregion #region 开屏广告 /// <summary> /// 是否开屏广告 /// </summary> public bool IsAppOpenAdAvailable { get { return (!isShowingAppOpenAd && appOpenAd != null && DateTime.Now < appOpenExpireTime); } } public void OnAppStateChanged(AppState state) { // 当应用程序处于前台时显示应用程序打开广告。 //UnityEngine.PrintStatus("App State is " + state); // OnAppStateChanged 不能保证在 Unity UI 线程上执行。 MobileAdsEventExecutor.ExecuteInUpdate(() => { if (state == AppState.Foreground) { ShowAppOpenAd(); } }); } /// <summary> /// 请求和加载开屏广告 /// </summary> public void RequestAndLoadAppOpenAd() { PrintStatus("请求 开屏广告."); string adUnitId = this.AppOpenAdID; //#if UNITY_EDITOR // string adUnitId = "unused"; //#elif UNITY_ANDROID // string adUnitId = "ca-app-pub-3940256099942544/3419835294"; //#elif UNITY_IPHONE // string adUnitId = "ca-app-pub-3940256099942544/5662855259"; //#else // string adUnitId = "unexpected_platform"; //#endif // 创建新的应用打开广告实例 AppOpenAd.LoadAd(adUnitId, ScreenOrientation.Portrait, CreateAdRequest(), OnAppOpenAdLoad); } /// <summary> /// 加载开屏广告 /// </summary> /// <param name="ad"></param> /// <param name="error"></param> private void OnAppOpenAdLoad(AppOpenAd ad, AdFailedToLoadEventArgs error) { if (error != null) { PrintStatus("应用打开广告未能加载并出现错误: " + error); return; } PrintStatus("应用打开广告已加载。 请后台应用程序并返回。"); this.appOpenAd = ad; this.appOpenExpireTime = DateTime.Now + APPOPEN_TIMEOUT; } /// <summary> /// 展示开屏广告 /// </summary> public void ShowAppOpenAd() { if (!IsAppOpenAdAvailable) { return; } // Register for ad events. this.appOpenAd.OnAdDidDismissFullScreenContent += (sender, args) => { PrintStatus("开屏广告 dismissed."); isShowingAppOpenAd = false; if (this.appOpenAd != null) { this.appOpenAd.Destroy(); this.appOpenAd = null; } }; this.appOpenAd.OnAdFailedToPresentFullScreenContent += (sender, args) => { PrintStatus("开屏广告未能出现错误: " + args.AdError.GetMessage()); isShowingAppOpenAd = false; if (this.appOpenAd != null) { this.appOpenAd.Destroy(); this.appOpenAd = null; } }; this.appOpenAd.OnAdDidPresentFullScreenContent += (sender, args) => { PrintStatus("开屏广告 打开."); }; this.appOpenAd.OnAdDidRecordImpression += (sender, args) => { PrintStatus("开屏广告 记录了一个印象。."); }; this.appOpenAd.OnPaidEvent += (sender, args) => { string msg = string.Format("{0} (currency: {1}, value: {2}", "App Open ad received a paid event.", args.AdValue.CurrencyCode, args.AdValue.Value); PrintStatus(msg); }; isShowingAppOpenAd = true; appOpenAd.Show(); } #endregion #region AD INSPECTOR public void OpenAdInspector() { PrintStatus("打开广告检查器。"); MobileAds.OpenAdInspector((error) => { if (error != null) { PrintStatus("广告检查器无法打开并出现错误:" + error); } else { PrintStatus("广告检查器已成功打开。"); } }); } #endregion #region Utility ///<summary> /// 记录消息并更新主线程上的状态文本 ///<summary> private void PrintStatus(string message) { infoText.text += "\n" + message; MobileAdsEventExecutor.ExecuteInUpdate(() => { //statusText.text = message; }); } #endregion #region 外部调用接口 /// <summary> /// 清理广告事件 /// </summary> public void ClearAdUnityAction() { this.OnAdLoadedEvent.RemoveAllListeners(); this.OnAdFailedToLoadEvent.RemoveAllListeners(); this.OnAdOpeningEvent.RemoveAllListeners(); this.OnAdFailedToShowEvent.RemoveAllListeners(); this.OnUserEarnedRewardEvent.RemoveAllListeners(); this.OnAdClosedEvent.RemoveAllListeners(); } /// <summary> /// 请求激励视频广告 /// </summary> /// <param name="_OnAdLoadedEvent"> 在广告加载完成时被调用</param> /// <param name="_OnAdFailedToLoadEvent">在广告加载失败时被调用</param> /// <param name="_OnAdOpeningEvent">在广告开始展示并铺满设备屏幕时被调用</param> /// <param name="_OnAdFailedToShowEvent">在广告显示失败时被调用</param> /// <param name="_OnUserEarnedRewardEvent">用户获得的激励广告奖励</param> /// <param name="_OnAdClosedEvent">在用户点按“关闭”图标或使用“返回”按钮关闭激励视频广告时被调用</param> public void RequestAndLoadRewardedAd(UnityAction _OnAdLoadedEvent, UnityAction _OnAdFailedToLoadEvent, UnityAction _OnAdOpeningEvent, UnityAction _OnAdFailedToShowEvent, UnityAction _OnUserEarnedRewardEvent, UnityAction _OnAdClosedEvent) { this.OnAdLoadedEvent.AddListener(_OnAdLoadedEvent); this.OnAdFailedToLoadEvent.AddListener(_OnAdFailedToLoadEvent); this.OnAdOpeningEvent.AddListener(_OnAdOpeningEvent); this.OnAdFailedToShowEvent.AddListener(_OnAdFailedToShowEvent); this.OnUserEarnedRewardEvent.AddListener(_OnUserEarnedRewardEvent); this.OnAdClosedEvent.AddListener(_OnAdClosedEvent); this.RequestAndLoadRewardedAd(); } public void RequestAndLoadRewardedAd1() { PrintStatus("RequestAndLoadRewardedAd1"); this.RequestAndLoadRewardedAd(null, null, null, null, null, null); } /// <summary> /// 请求和加载插页式广告 /// </summary> /// <param name="_OnAdLoadedEvent"> 在广告加载完成时被调用</param> /// <param name="_OnAdFailedToLoadEvent">在广告加载失败时被调用</param> /// <param name="_OnAdOpeningEvent">在广告开始展示并铺满设备屏幕时被调用</param> /// <param name="_OnAdFailedToShowEvent">在广告显示失败时被调用</param> /// <param name="_OnUserEarnedRewardEvent">用户获得的激励广告奖励</param> /// <param name="_OnAdClosedEvent">在用户点按“关闭”图标或使用“返回”按钮关闭激励视频广告时被调用</param> public void RequestAndLoadRewardedInterstitialAd(UnityAction _OnAdLoadedEvent, UnityAction _OnAdFailedToLoadEvent, UnityAction _OnAdOpeningEvent, UnityAction _OnAdFailedToShowEvent, UnityAction _OnUserEarnedRewardEvent, UnityAction _OnAdClosedEvent) { this.OnAdLoadedEvent.AddListener(_OnAdLoadedEvent); this.OnAdFailedToLoadEvent.AddListener(_OnAdFailedToLoadEvent); this.OnAdOpeningEvent.AddListener(_OnAdOpeningEvent); this.OnAdFailedToShowEvent.AddListener(_OnAdFailedToShowEvent); this.OnUserEarnedRewardEvent.AddListener(_OnUserEarnedRewardEvent); this.OnAdClosedEvent.AddListener(_OnAdClosedEvent); this.RequestAndLoadRewardedInterstitialAd(); } public void RequestAndLoadRewardedInterstitialAd1() { PrintStatus("RequestAndLoadRewardedInterstitialAd1"); this.RequestAndLoadRewardedInterstitialAd(null, null, null, null, null, null); } /// <summary> /// 请求横幅广告 /// </summary> /// <param name="_OnAdLoadedEvent"> 在广告加载完成时被调用</param> /// <param name="_OnAdFailedToLoadEvent">在广告加载失败时被调用</param> /// <param name="_OnAdOpeningEvent">在广告开始展示并铺满设备屏幕时被调用</param> /// <param name="_OnAdFailedToShowEvent">在广告显示失败时被调用</param> /// <param name="_OnUserEarnedRewardEvent">用户获得的激励广告奖励</param> /// <param name="_OnAdClosedEvent">在用户点按“关闭”图标或使用“返回”按钮关闭激励视频广告时被调用</param> public void RequestBannerAd(UnityAction _OnAdLoadedEvent, UnityAction _OnAdFailedToLoadEvent, UnityAction _OnAdOpeningEvent, UnityAction _OnAdFailedToShowEvent, UnityAction _OnUserEarnedRewardEvent, UnityAction _OnAdClosedEvent) { this.OnAdLoadedEvent.AddListener(_OnAdLoadedEvent); this.OnAdFailedToLoadEvent.AddListener(_OnAdFailedToLoadEvent); this.OnAdOpeningEvent.AddListener(_OnAdOpeningEvent); this.OnAdFailedToShowEvent.AddListener(_OnAdFailedToShowEvent); this.OnUserEarnedRewardEvent.AddListener(_OnUserEarnedRewardEvent); this.OnAdClosedEvent.AddListener(_OnAdClosedEvent); this.RequestBannerAd(); } public void RequestBannerAd1() { PrintStatus("RequestBannerAd1"); this.RequestBannerAd(null, null, null, null, null, null); } /// <summary> /// 请求和加载插页式广告 /// </summary> /// <param name="_OnAdLoadedEvent"> 在广告加载完成时被调用</param> /// <param name="_OnAdFailedToLoadEvent">在广告加载失败时被调用</param> /// <param name="_OnAdOpeningEvent">在广告开始展示并铺满设备屏幕时被调用</param> /// <param name="_OnAdFailedToShowEvent">在广告显示失败时被调用</param> /// <param name="_OnUserEarnedRewardEvent">用户获得的激励广告奖励</param> /// <param name="_OnAdClosedEvent">在用户点按“关闭”图标或使用“返回”按钮关闭激励视频广告时被调用</param> public void RequestAndLoadInterstitialAd(UnityAction _OnAdLoadedEvent, UnityAction _OnAdFailedToLoadEvent, UnityAction _OnAdOpeningEvent, UnityAction _OnAdFailedToShowEvent, UnityAction _OnUserEarnedRewardEvent, UnityAction _OnAdClosedEvent) { this.OnAdLoadedEvent.AddListener(_OnAdLoadedEvent); this.OnAdFailedToLoadEvent.AddListener(_OnAdFailedToLoadEvent); this.OnAdOpeningEvent.AddListener(_OnAdOpeningEvent); this.OnAdFailedToShowEvent.AddListener(_OnAdFailedToShowEvent); this.OnUserEarnedRewardEvent.AddListener(_OnUserEarnedRewardEvent); this.OnAdClosedEvent.AddListener(_OnAdClosedEvent); this.RequestAndLoadInterstitialAd(); } public void RequestAndLoadInterstitialAd1() { PrintStatus("RequestAndLoadInterstitialAd1"); this.RequestAndLoadInterstitialAd(null, null, null, null, null, null); } #endregion }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。