当前位置:   article > 正文

unity Google 广告接入 SDK Android_unity 对接google广告

unity 对接google广告

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
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237
  • 238
  • 239
  • 240
  • 241
  • 242
  • 243
  • 244
  • 245
  • 246
  • 247
  • 248
  • 249
  • 250
  • 251
  • 252
  • 253
  • 254
  • 255
  • 256
  • 257
  • 258
  • 259
  • 260
  • 261
  • 262
  • 263
  • 264
  • 265
  • 266
  • 267
  • 268
  • 269
  • 270
  • 271
  • 272
  • 273
  • 274
  • 275
  • 276
  • 277
  • 278
  • 279
  • 280
  • 281
  • 282
  • 283
  • 284
  • 285
  • 286
  • 287
  • 288
  • 289
  • 290
  • 291
  • 292
  • 293
  • 294
  • 295
  • 296
  • 297
  • 298
  • 299
  • 300
  • 301
  • 302
  • 303
  • 304
  • 305
  • 306
  • 307
  • 308
  • 309
  • 310
  • 311
  • 312
  • 313
  • 314
  • 315
  • 316
  • 317
  • 318
  • 319
  • 320
  • 321
  • 322
  • 323
  • 324
  • 325
  • 326
  • 327
  • 328
  • 329
  • 330
  • 331
  • 332
  • 333
  • 334
  • 335
  • 336
  • 337
  • 338
  • 339
  • 340
  • 341
  • 342
  • 343
  • 344
  • 345
  • 346
  • 347
  • 348
  • 349
  • 350
  • 351
  • 352
  • 353
  • 354
  • 355
  • 356
  • 357
  • 358
  • 359
  • 360
  • 361
  • 362
  • 363
  • 364
  • 365
  • 366
  • 367
  • 368
  • 369
  • 370
  • 371
  • 372
  • 373
  • 374
  • 375
  • 376
  • 377
  • 378
  • 379
  • 380
  • 381
  • 382
  • 383
  • 384
  • 385
  • 386
  • 387
  • 388
  • 389
  • 390
  • 391
  • 392
  • 393
  • 394
  • 395
  • 396
  • 397
  • 398
  • 399
  • 400
  • 401
  • 402
  • 403
  • 404
  • 405
  • 406
  • 407
  • 408
  • 409
  • 410
  • 411
  • 412
  • 413
  • 414
  • 415
  • 416
  • 417
  • 418
  • 419
  • 420
  • 421
  • 422
  • 423
  • 424
  • 425
  • 426
  • 427
  • 428
  • 429
  • 430
  • 431
  • 432
  • 433
  • 434
  • 435
  • 436
  • 437
  • 438
  • 439
  • 440
  • 441
  • 442
  • 443
  • 444
  • 445
  • 446
  • 447
  • 448
  • 449
  • 450
  • 451
  • 452
  • 453
  • 454
  • 455
  • 456
  • 457
  • 458
  • 459
  • 460
  • 461
  • 462
  • 463
  • 464
  • 465
  • 466
  • 467
  • 468
  • 469
  • 470
  • 471
  • 472
  • 473
  • 474
  • 475
  • 476
  • 477
  • 478
  • 479
  • 480
  • 481
  • 482
  • 483
  • 484
  • 485
  • 486
  • 487
  • 488
  • 489
  • 490
  • 491
  • 492
  • 493
  • 494
  • 495
  • 496
  • 497
  • 498
  • 499
  • 500
  • 501
  • 502
  • 503
  • 504
  • 505
  • 506
  • 507
  • 508
  • 509
  • 510
  • 511
  • 512
  • 513
  • 514
  • 515
  • 516
  • 517
  • 518
  • 519
  • 520
  • 521
  • 522
  • 523
  • 524
  • 525
  • 526
  • 527
  • 528
  • 529
  • 530
  • 531
  • 532
  • 533
  • 534
  • 535
  • 536
  • 537
  • 538
  • 539
  • 540
  • 541
  • 542
  • 543
  • 544
  • 545
  • 546
  • 547
  • 548
  • 549
  • 550
  • 551
  • 552
  • 553
  • 554
  • 555
  • 556
  • 557
  • 558
  • 559
  • 560
  • 561
  • 562
  • 563
  • 564
  • 565
  • 566
  • 567
  • 568
  • 569
  • 570
  • 571
  • 572
  • 573
  • 574
  • 575
  • 576
  • 577
  • 578
  • 579
  • 580
  • 581
  • 582
  • 583
  • 584
  • 585
  • 586
  • 587
  • 588
  • 589
  • 590
  • 591
  • 592
  • 593
  • 594
  • 595
  • 596
  • 597
  • 598
  • 599
  • 600
  • 601
  • 602
  • 603
  • 604
  • 605
  • 606
  • 607
  • 608
  • 609
  • 610
  • 611
  • 612
  • 613
  • 614
  • 615
  • 616
  • 617
  • 618
  • 619
  • 620
  • 621
  • 622
  • 623
  • 624
  • 625
  • 626
  • 627
  • 628
  • 629
  • 630
  • 631
  • 632
  • 633
  • 634
  • 635
  • 636
  • 637
  • 638
  • 639
  • 640
  • 641
  • 642
  • 643
  • 644
  • 645
  • 646
  • 647
  • 648
  • 649
  • 650
  • 651
  • 652
  • 653
  • 654
  • 655
  • 656
  • 657
  • 658
  • 659
  • 660
  • 661
  • 662
  • 663
  • 664
  • 665
  • 666
  • 667
  • 668
  • 669
  • 670
  • 671
  • 672
  • 673
  • 674
  • 675
  • 676
  • 677
  • 678
  • 679
  • 680
  • 681
  • 682
  • 683
  • 684
  • 685
  • 686
  • 687
  • 688
  • 689
  • 690
  • 691
  • 692
  • 693
  • 694
  • 695
  • 696
  • 697
  • 698
  • 699
  • 700
  • 701
  • 702
  • 703
  • 704
  • 705
  • 706
  • 707
  • 708
  • 709
  • 710
  • 711
  • 712
  • 713
  • 714
  • 715
  • 716
  • 717
  • 718
  • 719
  • 720
  • 721
  • 722
  • 723
  • 724
  • 725
  • 726
  • 727
  • 728
  • 729
  • 730
  • 731
  • 732
  • 733
  • 734
  • 735
  • 736
  • 737
  • 738
  • 739
  • 740
  • 741
  • 742
  • 743
  • 744
  • 745
  • 746
  • 747
  • 748
  • 749
  • 750
  • 751
  • 752
  • 753
  • 754
  • 755
  • 756
  • 757
  • 758
  • 759
  • 760
  • 761
  • 762
  • 763
  • 764
  • 765
  • 766
  • 767
  • 768
  • 769
  • 770
  • 771
  • 772
  • 773
  • 774
  • 775
  • 776
  • 777
  • 778
  • 779
  • 780
  • 781
  • 782
  • 783
  • 784
  • 785
  • 786
  • 787
  • 788
  • 789
  • 790
  • 791
  • 792
  • 793
  • 794
  • 795
  • 796
  • 797
  • 798
  • 799
  • 800
  • 801
  • 802
  • 803
  • 804
  • 805
  • 806
  • 807
  • 808
  • 809
  • 810
  • 811
  • 812
  • 813
  • 814
  • 815
  • 816
  • 817
  • 818
  • 819
  • 820
  • 821
  • 822
  • 823
  • 824
  • 825
  • 826
  • 827
  • 828
  • 829
  • 830
  • 831
  • 832
  • 833
  • 834
  • 835
  • 836
  • 837
  • 838
  • 839
  • 840
  • 841
  • 842
  • 843
  • 844
  • 845
  • 846
  • 847
  • 848
  • 849
  • 850
  • 851
  • 852
  • 853
  • 854
  • 855
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/1021194
推荐阅读
相关标签
  

闽ICP备14008679号