public void LoadBannerAd(UnityBannerAdPositionCodeType position, string bannerSize = UnityBannerAdSize.BANNER_SIZE_320_50)
    {
        if (!isInitialized || !adsKitSettings.GetBool(HMSAdsKitSettings.EnableBannerAd))
        {
            return;
        }

        Debug.Log("[HMS] HMSAdsKitManager Loading Banner Ad.");
        var bannerAdStatusListener = new AdStatusListener();

        bannerAdStatusListener.mOnAdLoaded     += BannerAdStatusListener_mOnAdLoaded;
        bannerAdStatusListener.mOnAdClosed     += BannerAdStatusListener_mOnAdClosed;
        bannerAdStatusListener.mOnAdImpression += BannerAdStatusListener_mOnAdImpression;
        bannerAdStatusListener.mOnAdClicked    += BannerAdStatusListener_mOnAdClicked;
        bannerAdStatusListener.mOnAdOpened     += BannerAdStatusListener_mOnAdOpened;
        bannerAdStatusListener.mOnAdFailed     += BannerAdStatusListener_mOnAdFailed;

        bannerView                  = new BannerAd(bannerAdStatusListener);
        bannerView.AdId             = adsKitSettings.GetBool(HMSAdsKitSettings.UseTestAds) ? TestBannerAdId : adsKitSettings.Get(HMSAdsKitSettings.BannerAdID);
        bannerView.PositionType     = (int)position;
        bannerView.SizeType         = bannerSize;
        bannerView.AdStatusListener = bannerAdStatusListener;
        _isBannerAdLoaded           = false;
        bannerView.LoadBanner(new AdParam.Builder().Build());
        if (adsKitSettings.GetBool(HMSAdsKitSettings.ShowBannerOnLoad))
        {
            bannerView.ShowBanner();
        }
        else
        {
            bannerView.HideBanner();
        }
    }
Exemplo n.º 2
0
    public void CreateAndLoadBannerAd(string adId)
    {
        if (_bannerAds.ContainsKey(adId))
        {
            return;
        }

        var bannerAdListener = new AdStatusListener();

        bannerAdListener.mOnAdFailed += (sender, args) =>
        {
            Debug.Log("PortModule AdsManager bannerView load is failed.");
        };
        bannerAdListener.mOnAdLoaded += (sender, args) =>
        {
            Debug.Log("PortModule AdsManager bannerView load is completed.");
            _bannerAds[adId].ShowBanner();
        };

        var bannerAdView = new BannerAd(bannerAdListener);

        bannerAdView.AdId         = adId;
        bannerAdView.PositionType = (int)UnityBannerAdPositionCodeType.POSITION_BOTTOM;
        bannerAdView.SizeType     = UnityBannerAdSize.BANNER_SIZE_SMART;

        bannerAdView.LoadBanner(CreateAdRequest());

        _bannerAds.Add(adId, bannerAdView);
    }