示例#1
0
        /// <summary>
        /// Loads an Admob interstitial
        /// </summary>
        private void LoadInterstitial()
        {
            if (debug)
            {
                Debug.Log("Admob Start Loading Interstitial");
                ScreenWriter.Write("Admob Start Loading Interstitial");
            }

            if (interstitial != null)
            {
                interstitial.OnAdLoaded       -= InterstitialLoaded;
                interstitial.OnAdClosed       -= InterstitialClosed;
                interstitial.OnAdFailedToLoad -= InterstitialFailed;
                interstitial.Destroy();
            }

            //setup and load interstitial
            interstitial                   = new InterstitialAd(interstitialId);
            interstitial.OnAdLoaded       += InterstitialLoaded;
            interstitial.OnAdClosed       += InterstitialClosed;
            interstitial.OnAdFailedToLoad += InterstitialFailed;


            AdRequest request = new AdRequest.Builder().AddExtra("npa", consent).AddExtra("is_designed_for_families", designedForFamilies).TagForChildDirectedTreatment(directedForChildren).AddExtra("rdp", ccpaConsent).Build();

            interstitial.LoadAd(request);
        }
示例#2
0
 /// <summary>
 /// Hides Admob banner
 /// </summary>
 public void HideBanner()
 {
     if (debug)
     {
         Debug.Log("Admob Hide banner");
         ScreenWriter.Write("Admob Hide banner");
     }
     if (banner != null)
     {
         if (bannerLoaded == false)
         {
             //if banner is not yet loaded -> destroy so it cannot load later in the game
             if (DisplayResult != null)
             {
                 DisplayResult(false, position, bannerType);
                 DisplayResult = null;
             }
             banner.OnAdLoaded       -= BannerLoadSucces;
             banner.OnAdFailedToLoad -= BannerLoadFailed;
             banner.Destroy();
             forceReload = true;
         }
         else
         {
             //hide the banner -> will be available later without loading
             banner.Hide();
             forceReload = false;
         }
     }
 }
示例#3
0
        /// <summary>
        /// Loads an Admob rewarded video
        /// </summary>
        private void LoadRewardedVideo()
        {
            if (debug)
            {
                Debug.Log("Admob Start Loading Rewarded Video");
                ScreenWriter.Write("Admob Start Loading Rewarded Video");
            }
            if (rewardedVideo != null)
            {
                rewardedVideo.OnAdLoaded         -= RewardedVideoLoaded;
                rewardedVideo.OnUserEarnedReward -= RewardedVideoWatched;
                rewardedVideo.OnAdFailedToLoad   -= RewardedVideoFailed;
                rewardedVideo.OnAdClosed         -= OnAdClosed;
                rewardedVideo.OnAdOpening        -= OnAdOpening;
                rewardedVideo.OnAdFailedToShow   -= OnAdFailedToShow;
            }


            rewardedVideo                     = new RewardedAd(rewardedVideoId);
            rewardedVideo.OnAdLoaded         += RewardedVideoLoaded;
            rewardedVideo.OnUserEarnedReward += RewardedVideoWatched;
            rewardedVideo.OnAdFailedToLoad   += RewardedVideoFailed;
            rewardedVideo.OnAdClosed         += OnAdClosed;
            rewardedVideo.OnAdOpening        += OnAdOpening;
            rewardedVideo.OnAdFailedToShow   += OnAdFailedToShow;

            AdRequest request = new AdRequest.Builder().AddExtra("npa", consent).AddExtra("is_designed_for_families", designedForFamilies).TagForChildDirectedTreatment(directedForChildren).AddExtra("rdp", ccpaConsent).Build();

            rewardedVideo.LoadAd(request);
        }
示例#4
0
 /// <summary>
 /// Show Admob banner
 /// </summary>
 /// <param name="position"> can be TOP or BOTTOM</param>
 ///  /// <param name="bannerType"> can be Banner or SmartBanner</param>
 public void ShowBanner(BannerPosition position, BannerType bannerType, UnityAction <bool, BannerPosition, BannerType> DisplayResult)
 {
     bannerLoaded       = false;
     bannerUsed         = true;
     this.DisplayResult = DisplayResult;
     if (banner != null)
     {
         if (this.position == position && this.bannerType == bannerType && forceReload == false)
         {
             if (debug)
             {
                 Debug.Log("Admob Show banner");
                 ScreenWriter.Write("Admob Show Banner");
             }
             bannerLoaded = true;
             banner.Show();
             if (this.DisplayResult != null)
             {
                 this.DisplayResult(true, position, bannerType);
                 this.DisplayResult = null;
             }
         }
         else
         {
             LoadBanner(position, bannerType);
         }
     }
     else
     {
         LoadBanner(position, bannerType);
     }
 }
示例#5
0
        /// <summary>
        /// Triggered when a rewarded video is closed
        /// </summary>
        /// <param name="ID"></param>
        private void OnAdClosed(string ID)
        {
            rewardedVideoAvailable = false;
            if (debug)
            {
                Debug.Log(this + " OnAdClosed");
                ScreenWriter.Write(this + " OnAdClosed");
            }

            //reload
            LoadRewardedVideo();

            if (OnCompleteMethod != null)
            {
                OnCompleteMethod(rewardedWatched);
                OnCompleteMethod = null;
            }
            if (OnCompleteMethodWithAdvertiser != null)
            {
                OnCompleteMethodWithAdvertiser(rewardedWatched, SupportedAdvertisers.MoPub.ToString());
                OnCompleteMethodWithAdvertiser = null;
            }

            rewardedWatched = false;
        }
        /// <summary>
        /// Triggered when rewarded video was loaded and is ready to show
        /// </summary>
        private void RewardedVideoLoaded()
        {
            if (rewardedVideoAd.IsValid())
            {
                if (debug)
                {
                    Debug.Log(this + " " + "Rewarded Video Loaded");
                    ScreenWriter.Write(this + " " + "Rewarded Video Loaded");
                }
                rewardedVideoisLoaded     = true;
                rewardedVideoDidClose     = false;
                currentRetryRewardedVideo = 0;
            }
            else
            {
                if (debug)
                {
                    Debug.Log(this + " " + "Rewarded Video Loaded but is invalid");
                    ScreenWriter.Write(this + " " + "Rewarded Video Loaded but is invalid");
                }

                //try again to load a rewarded video
                if (currentRetryRewardedVideo < maxRetryCount)
                {
                    currentRetryRewardedVideo++;
                    if (debug)
                    {
                        Debug.Log(this + " " + "RETRY " + currentRetryRewardedVideo);
                        ScreenWriter.Write(this + " " + "RETRY " + currentRetryRewardedVideo);
                    }
                    Invoke("LoadRewardedVideo", reloadTime);
                }
            }
        }
        public void ShowBanner(global::BannerPosition position, BannerType bannerType, UnityAction <bool, global::BannerPosition, BannerType> DisplayResult)
        {
            if (IsBannerAvailable())
            {
                bannerUsed = true;

                this.position      = position;
                this.bannerType    = bannerType;
                this.DisplayResult = DisplayResult;

                BannerLoadOptions options = new BannerLoadOptions
                {
                    errorCallback = BannerLoadFailed,
                    loadCallback  = BannerLoadSuccess
                };
                if (debug)
                {
                    Debug.Log(this + "Start Loading Placement:" + bannerPlacement + " is ready " + Advertisement.IsReady(bannerPlacement));
                    ScreenWriter.Write(this + "Start Loading Placement:" + bannerPlacement + " is ready " + Advertisement.IsReady(bannerPlacement));
                }
                if (position == global::BannerPosition.BOTTOM)
                {
                    Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
                }
                else
                {
                    Advertisement.Banner.SetPosition(BannerPosition.TOP_CENTER);
                }
                Advertisement.Banner.Load(bannerPlacement, options);
            }
        }
示例#8
0
        /// <summary>
        /// Vungle specific event triggered after initialization is done
        /// </summary>
        private void InitCOmplete()
        {
            initComplete              = true;
            Vungle.onInitializeEvent -= InitCOmplete;

            switch (consent)
            {
            case UserConsent.Unset:
                Vungle.updateConsentStatus(Vungle.Consent.Undefined);
                break;

            case UserConsent.Accept:
                Vungle.updateConsentStatus(Vungle.Consent.Accepted);
                break;

            case UserConsent.Deny:
                Vungle.updateConsentStatus(Vungle.Consent.Denied);
                break;
            }

            //load ads
            if (!string.IsNullOrEmpty(interstitialPlacementID))
            {
                Vungle.loadAd(interstitialPlacementID);
            }
            if (!string.IsNullOrEmpty(rewardedPlacementId))
            {
                Vungle.loadAd(rewardedPlacementId);
            }
            if (debug)
            {
                ScreenWriter.Write(this + " " + "Init Complete");
            }
        }
        /// <summary>
        /// Updates consent at runtime
        /// </summary>
        /// <param name="consent">the new consent</param>
        public void UpdateConsent(UserConsent consent, UserConsent ccpaConsent)
        {
            if (consent != UserConsent.Unset)
            {
                MetaData gdprMetaData = new MetaData("gdpr");
                if (consent == UserConsent.Accept)
                {
                    gdprMetaData.Set("consent", "true");
                }
                else
                {
                    gdprMetaData.Set("consent", "false");
                }
                Advertisement.SetMetaData(gdprMetaData);
            }

            if (ccpaConsent != UserConsent.Unset)
            {
                MetaData privacyMetaData = new MetaData("privacy");
                if (consent == UserConsent.Accept)
                {
                    privacyMetaData.Set("consent", "true");
                }
                else
                {
                    privacyMetaData.Set("consent", "false");
                }
                Advertisement.SetMetaData(privacyMetaData);
            }

            Debug.Log(this + " Update consent to " + consent);
            ScreenWriter.Write(this + " Update consent to " + consent);
        }
        /// <summary>
        /// Triggered when an interstitial is loaded and ready to be shown
        /// </summary>
        private void InterstitialLoaded()
        {
            if (interstitialAd.IsValid())
            {
                interstitialIsLoaded = true;
                interstitialDidClose = false;
                if (debug)
                {
                    Debug.Log(this + " " + "Interstitial Loaded");
                    ScreenWriter.Write(this + " " + "Interstitial Loaded");
                }
                currentRetryInterstitial = 0;
            }
            else
            {
                if (debug)
                {
                    Debug.Log(this + " " + "Interstitial Loaded but is invalid");
                    ScreenWriter.Write(this + " " + "Interstitial Loaded but is invalid");
                }

                //try again to load an interstitial video
                if (currentRetryInterstitial < maxRetryCount)
                {
                    currentRetryInterstitial++;
                    if (debug)
                    {
                        Debug.Log(this + " " + "RETRY " + currentRetryInterstitial);
                        ScreenWriter.Write(this + " " + "RETRY " + currentRetryInterstitial);
                    }
                    Invoke("LoadInterstitial", reloadTime);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Show Heyzap banner
        /// </summary>
        /// <param name="position"> can be TOP of BOTTOM</param>
        /// <param name="bannerType"> it is not used in Heyzap, this param is used just in Admob implementation</param>
        public void ShowBanner(BannerPosition position, BannerType bannerType, UnityAction <bool, BannerPosition, BannerType> DisplayResult)
        {
            bannerUsed         = true;
            this.position      = position;
            this.bannerType    = bannerType;
            this.DisplayResult = DisplayResult;
            if (IsBannerAvailable())
            {
                HZBannerShowOptions showOptions = new HZBannerShowOptions();
                if (position == BannerPosition.TOP)
                {
                    showOptions.Position = HZBannerShowOptions.POSITION_TOP;
                }
                else if (position == BannerPosition.BOTTOM)
                {
                    showOptions.Position = HZBannerShowOptions.POSITION_BOTTOM;
                }

                if (debug)
                {
                    Debug.Log(this + " Show Banner");
                    ScreenWriter.Write(this + " Show Banner");
                }

                HZBannerAd.ShowWithOptions(showOptions);
            }
        }
示例#12
0
 /// <summary>
 /// Chartboost specific event triggered if a rewarded video failed to load
 /// </summary>
 /// <param name="arg1"></param>
 /// <param name="arg2"></param>
 private void FailRewarded(CBLocation arg1, CBImpressionError arg2)
 {
     if (debug)
     {
         Debug.Log(this + " FailRewarded Reason:" + arg2);
         ScreenWriter.Write(this + " FailRewarded Reason:" + arg2);
     }
     if (triggerCompleteMethod == true)
     {
         if (OnCompleteMethod != null)
         {
             OnCompleteMethod(false);
             OnCompleteMethod      = null;
             triggerCompleteMethod = false;
         }
         if (OnCompleteMethodWithAdvertiser != null)
         {
             OnCompleteMethodWithAdvertiser(false, SupportedAdvertisers.Chartboost.ToString());
             OnCompleteMethodWithAdvertiser = null;
             triggerCompleteMethod          = false;
         }
     }
     else
     {
         if (debug)
         {
             Debug.Log(this + " FailRewarded Reload...");
             ScreenWriter.Write(this + " FailRewarded Reload...");
         }
         Invoke("ReloadVideoCB", reloadTime);
     }
 }
示例#13
0
        /// <summary>
        /// Chartboost specific event triggered after a rewarded video was closed
        /// </summary>
        /// <param name="obj"></param>
        void ReloadRewarded(CBLocation obj)
        {
            if (debug)
            {
                Debug.Log(this + "ReloadRewarded");
                ScreenWriter.Write(this + "ReloadRewarded");
            }
            if (triggerCompleteMethod == true)
            {
                if (OnCompleteMethod != null)
                {
                    OnCompleteMethod(false);
                    OnCompleteMethod      = null;
                    triggerCompleteMethod = false;
                }
                if (OnCompleteMethodWithAdvertiser != null)
                {
                    OnCompleteMethodWithAdvertiser(false, SupportedAdvertisers.Chartboost.ToString());
                    OnCompleteMethodWithAdvertiser = null;
                    triggerCompleteMethod          = false;
                }
            }

            //load another rewarded video
            Chartboost.cacheRewardedVideo(CBLocation.Default);
        }
 /// <summary>
 /// AdColony specific event triggered when an AdColony video failed to load
 /// </summary>
 /// <param name="zoneID"></param>
 private void OnRequestInterstitialFailed(string zoneID)
 {
     if (debug)
     {
         Debug.Log(this + " Load Ad Failed");
         ScreenWriter.Write(this + " Load Ad Failed");
     }
     if (zoneID == interstitialZoneId)
     {
         if (currentRetryInterstitial < maxRetryCount)
         {
             currentRetryInterstitial++;
             if (debug)
             {
                 Debug.Log(this + " Interstitial Failed->Retry " + currentRetryInterstitial);
                 ScreenWriter.Write(this + " Interstitial Failed->Retry " + currentRetryInterstitial);
             }
             Invoke("RequestInterstitial", reloadTime);
         }
     }
     if (zoneID == rewardedZoneId)
     {
         if (currentRetryRewardedVideo < maxRetryCount)
         {
             currentRetryRewardedVideo++;
             if (debug)
             {
                 Debug.Log(this + " Rewarded Video Failed->Retry " + currentRetryRewardedVideo);
                 ScreenWriter.Write(this + " Rewarded Video Failed->Retry " + currentRetryRewardedVideo);
             }
             Invoke("RequestRewarded", reloadTime);
         }
     }
 }
        /// <summary>
        /// Request a banner
        /// </summary>
        private void RequestBanner(BannerPosition position)
        {
            bannerUsed = true;
            if (string.IsNullOrEmpty(bannerZoneId))
            {
                return;
            }
            if (debug)
            {
                Debug.Log(this + " Request Banner");
                ScreenWriter.Write(this + " Request banner");
            }
            AdOptions adOptions = new AdOptions();

            adOptions.ShowPrePopup  = false;
            adOptions.ShowPostPopup = false;
            if (position == BannerPosition.BOTTOM)
            {
                Ads.RequestAdView(bannerZoneId, AdSize.Banner, AdPosition.Bottom, null);
            }
            else
            {
                Ads.RequestAdView(bannerZoneId, AdSize.Banner, AdPosition.Top, null);
            }
        }
        /// <summary>
        /// AdColony specific event triggered after initialization is done
        /// </summary>
        /// <param name="zones_"></param>
        private void OnConfigurationCompleted(List <Zone> zones_)
        {
            if (debug)
            {
                Debug.Log(this + " OnConfigurationCompleted called");
                ScreenWriter.Write(this + " OnConfigurationCompleted called");
            }

            if (zones_ == null || zones_.Count <= 0)
            {
                if (debug)
                {
                    Debug.Log(this + " Configure Failed");
                    ScreenWriter.Write(this + " Configure Failed");
                }
            }
            else
            {
                if (debug)
                {
                    Debug.Log(this + " Configure Succeeded.");
                    ScreenWriter.Write(this + " Configure Succeeded.");
                }
                RequestInterstitial();
                RequestRewarded();
            }
        }
        private void BannerLoaded(AdColonyAdView ad)
        {
            bannerAd = ad;
            if (canShowBanner)
            {
                //bannerAd.ShowAdView();
                if (debug)
                {
                    Debug.Log(this + " Banner Loaded");
                    ScreenWriter.Write(this + " Banner Loaded");
                }

                if (DisplayResult != null)
                {
                    DisplayResult(true, position, BannerType.Banner);
                    DisplayResult = null;
                }
            }
            else
            {
                if (debug)
                {
                    Debug.Log(this + " Banner closed before loading");
                    ScreenWriter.Write(this + " Banner closed before loading");
                }
                if (DisplayResult != null)
                {
                    DisplayResult(false, position, BannerType.Banner);
                    DisplayResult = null;
                }
                bannerAd.DestroyAdView();
            }
        }
示例#18
0
 /// <summary>
 /// VUngle specific log event
 /// </summary>
 /// <param name="obj"></param>
 private void VungleLog(string obj)
 {
     if (debug)
     {
         ScreenWriter.Write(this + " " + obj);
     }
 }
        /// <summary>
        /// Initializing AppLovin
        /// </summary>
        /// <param name="consent">user consent -> if true show personalized ads</param>
        /// <param name="platformSettings">contains all required settings for this publisher</param>
        public void InitializeAds(UserConsent consent, UserConsent ccpaConsent, List <PlatformSettings> platformSettings)
        {
            debug = Advertisements.Instance.debug;
            if (initialized == false)
            {
                if (debug)
                {
                    AppLovin.SetVerboseLoggingOn("true");
                }

                //get settings
#if UNITY_ANDROID
                PlatformSettings settings = platformSettings.First(cond => cond.platform == SupportedPlatforms.Android);
#endif
#if UNITY_IOS
                PlatformSettings settings = platformSettings.First(cond => cond.platform == SupportedPlatforms.iOS);
#endif

                //preparing AppLovin SDK for initialization
                Debug.Log("APPID: " + settings.appId.id.ToString());
                AppLovin.SetSdkKey(settings.appId.id.ToString());

                if (consent == UserConsent.Accept || consent == UserConsent.Unset)
                {
                    AppLovin.SetHasUserConsent("true");
                }
                else
                {
                    AppLovin.SetHasUserConsent("false");
                }


                if (settings.directedForChildren == true)
                {
                    AppLovin.SetIsAgeRestrictedUser("true");
                }
                else
                {
                    AppLovin.SetIsAgeRestrictedUser("false");
                }

                AppLovin.InitializeSdk();
                AppLovin.SetUnityAdListener(gameObject.name);

                if (debug)
                {
                    Debug.Log(this + " " + "Start Initialization");
                    ScreenWriter.Write(this + " " + "Start Initialization");
                    Debug.Log(this + " SDK key: " + settings.appId.id);
                    ScreenWriter.Write(this + " SDK key: " + settings.appId.id);
                }

                //start loading ads
                PreloadInterstitial();
                PreloadRewardedVideo();

                initialized = true;
            }
        }
 /// <summary>
 /// Triggered when rewarded video is shown
 /// </summary>
 private void RewardedVideoAdWillLogImpression()
 {
     if (debug)
     {
         Debug.Log(this + " " + "Rewarded video ad logged impression.");
         ScreenWriter.Write(this + " " + "Rewarded video ad logged impression.");
     }
 }
 private void BannerHidded()
 {
     if (debug)
     {
         Debug.Log(this + "Banner Hidden");
         ScreenWriter.Write(this + "Banner Hidden");
     }
 }
 //Invoked when the video ad finishes playing.
 void RewardedVideoAdEndedEvent()
 {
     if (debug)
     {
         Debug.Log(this + " RewardedVideoAdEndedEvent");
         ScreenWriter.Write(this + " RewardedVideoAdEndedEvent");
     }
 }
 /// <summary>
 /// Triggered when rewarded video is clicked
 /// </summary>
 private void RewardedVideoAdDidClick()
 {
     if (debug)
     {
         Debug.Log(this + " " + "Rewarded video ad clicked.");
         ScreenWriter.Write(this + " " + "Rewarded video ad clicked.");
     }
 }
 /// <summary>
 /// Triggered when an interstitial is clicked
 /// </summary>
 private void InterstitialAdDidClick()
 {
     if (debug)
     {
         Debug.Log(this + " " + "Interstitial ad clicked.");
         ScreenWriter.Write(this + " " + "Interstitial ad clicked.");
     }
 }
 /// <summary>
 /// Triggered when an interstitial is displayed
 /// </summary>
 private void InterstitialAdWillLogImpression()
 {
     if (debug)
     {
         Debug.Log(this + " " + "Interstitial ad logged impression.");
         ScreenWriter.Write(this + " " + "Interstitial ad logged impression.");
     }
 }
 /// <summary>
 /// Triggered when a Facebook banner is displayed
 /// </summary>
 private void BannerAdWillLogImpression()
 {
     if (debug)
     {
         Debug.Log(this + " " + "Banner ad logged impression.");
         ScreenWriter.Write(this + " " + "Banner ad logged impression.");
     }
 }
 /// <summary>
 /// Triggered when a Facebook banner is clicked
 /// </summary>
 private void BannerAdDidClick()
 {
     if (debug)
     {
         Debug.Log(this + " " + "Banner ad clicked.");
         ScreenWriter.Write(this + " " + "Banner ad clicked.");
     }
 }
 //Invoked when the Rewarded Video failed to show
 //@param description - string - contains information about the failure.
 void RewardedVideoAdShowFailedEvent(IronSourceError error)
 {
     if (debug)
     {
         Debug.Log(this + " RewardedVideoAdShowFailedEvent " + error);
         ScreenWriter.Write(this + " RewardedVideoAdShowFailedEvent " + error);
     }
 }
 public void OnUnityAdsDidStart(string placementId)
 {
     if (debug)
     {
         Debug.Log(this + "OnUnityAdsDidStart " + placementId);
         ScreenWriter.Write(this + "OnUnityAdsDidStart " + placementId);
     }
 }
 public void OnUnityAdsDidError(string message)
 {
     if (debug)
     {
         Debug.Log(this + "OnUnityAdsDidError " + message);
         ScreenWriter.Write(this + "OnUnityAdsDidError " + message);
     }
 }