Esempio n. 1
0
 // Implement IUnityAdsListener interface methods:
 public void OnUnityAdsDidFinish(string placementId, UnityEngine.Advertisements.ShowResult showResult)
 {
     if (!string.IsNullOrEmpty(currentRewardId) && string.Equals(currentRewardId, placementId))
     {
         // Define conditional logic for each ad completion status:
         if (showResult == UnityEngine.Advertisements.ShowResult.Finished)
         {
             onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.Finished));
             // Reward the user for watching the ad to completion.
         }
         else if (showResult == UnityEngine.Advertisements.ShowResult.Skipped)
         {
             onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.Canceled));
             Debug.Log("skipped ad");
             // Do not reward the user for skipping the ad.
         }
         else if (showResult == UnityEngine.Advertisements.ShowResult.Failed)
         {
             onRewardWatched?.Invoke(new RewardResult(RewardResult.Type.LoadFailed));
             AdsManager.ShowError(Advertisement.GetPlacementState(currentRewardId).ToString(), placementId);
             Debug.LogWarning("The ad did not finish due to an error.");
         }
         onRewardWatched = null;
     }
     else if (onInterstitialClosed != null) //closing a interstitial ads
     {
         onInterstitialClosed.Invoke(showResult == UnityEngine.Advertisements.ShowResult.Finished);
         onInterstitialClosed = null;
     }
 }
Esempio n. 2
0
    public void ShowBanner(string placementId, AdSize adSize, float delay = 0f, AdsManager.InterstitialDelegate onAdLoaded = null)
    {
        if (noAds != null && noAds())
        {
            onAdLoaded?.Invoke(false);
            return;
        }
        bannerLoadedDelegate = onAdLoaded;
        if (adSize == null)
        {
            Debug.Log("Admob Banner No AdSize parameter");
            adSize = AdSize.Banner;
        }
        if (this.bannerView != null && AdMobManager.bannerId == placementId && currentBannerSize == adSize)
        {
            onAdLoaded?.Invoke(true);
            if (delay > 0 && Time.timeScale > 0)
            {
                Invoke("CoShowBanner", delay);
            }
            else
            {
                CoShowBanner();
            }
        }
        else
        {
            //.Log(string.Format("destroying current banner({0} {1}), showing new one", AdsManager.bannerId, currentBannerSize));
            DestroyBanner();
            RequestBanner(placementId, adSize);
        }

        isShowBanner = true;
    }
    public void ShowBanner(string placementId, AdsManager.InterstitialDelegate onAdLoaded = null)
    {
        if (string.IsNullOrEmpty(placementId))
        {
            onAdLoaded(false);
        }
        if (adView)
        {
            adView.Dispose();
        }

        // Create a banner's ad view with a unique placement ID (generate your own on the Facebook app settings).
        // Use different ID for each ad placement in your app.
        adView = new AdView(placementId, AdSize.BANNER_HEIGHT_50);

        adView.Register(gameObject);
        currentAdViewPosition = AdPosition.BOTTOM;

        adView.AdViewDidLoad = delegate()
        {
            adView.Show(currentAdViewPosition);
            onAdLoaded?.Invoke(true);
        };
        adView.AdViewDidFailWithError = delegate(string error)
        {
            LogError(error);
            onAdLoaded?.Invoke(false);
        };
        adView.LoadAd();
    }
Esempio n. 4
0
    IEnumerator CoRequestInterstitial(string placementId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        float                  _timeoutRequestAds = timeoutRequestAds;
        PlacementState         adState            = PlacementState.Waiting;
        float                  retryInterval      = 0.4f;
        WaitForSecondsRealtime delay = new WaitForSecondsRealtime(retryInterval);
        int tryTimes = 0;

        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            Debug.Log("unity ad not reachable " + Application.internetReachability);
            _timeoutRequestAds = 3f;
        }
        while (adState != PlacementState.Ready && tryTimes < _timeoutRequestAds / retryInterval)
        {
            adState = Advertisement.GetPlacementState(placementId);
            if (adState != PlacementState.Ready)
            {
                yield return(delay);

                tryTimes++;
            }
        }
        Debug.Log("Unity request ad state " + adState);
        onAdLoaded?.Invoke(adState == PlacementState.Ready);
        //if (showLoading)
        //    Manager.LoadingAnimation(false);
    }
    public void RequestInterstitialNoShow(string placementId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        if (string.IsNullOrEmpty(placementId))
        {
            onAdLoaded(false);
        }
        if (interstitialAd != null)
        {
            interstitialAd.Dispose();
        }
        interstitialAd = new InterstitialAd(placementId);

        interstitialAd.Register(gameObject);

        if (onAdLoaded != null)
        {
            interstitialDelegate = onAdLoaded;
        }

        interstitialAd.InterstitialAdDidLoad           = InterstitialAdDidLoad;
        interstitialAd.InterstitialAdDidFailWithError  = InterstitialAdDidFailWithError;
        interstitialAd.InterstitialAdWillLogImpression = InterstitialAdWillLogImpression;
        interstitialAd.InterstitialAdDidClick          = InterstitialAdDidClick;
        interstitialAd.InterstitialAdDidClose          = InterstitialAdDidClose;

#if UNITY_ANDROID
        /* This callback will only be triggered if the Interstitial activity has
         * been destroyed without being properly closed. This can happen if an
         * app with launchMode:singleTask (such as a Unity game) goes to
         * background and is then relaunched by tapping the icon. */
        interstitialAd.interstitialAdActivityDestroyed = InterstitialAdActivityDestroyed;
#endif

        interstitialAd.LoadAd();
    }
Esempio n. 6
0
 void OnInterstitialFinish(bool isSuccess = false)
 {
     if (interstitialFinishDelegate != null)
     {
         this.interstitialFinishDelegate(isSuccess);
         this.interstitialFinishDelegate = null;
     }
 }
Esempio n. 7
0
    /// <param name="cacheNextInter">Cache next interstitial ads</param>
    /// <param name="logOriginName">For tracking where this interstitial came from</param>
    public void ShowInterstitial(bool showLoading = true, AdsManager.InterstitialDelegate onAdClosed = null, bool cacheNextInter = false, string logOriginName = "")
    {
        //if (AdMobManager.instance.time - AdMobManager.instance.interstitialTime < TIME_BETWEEN_ADS)
        //{
        //    OnInterstitialFinish();
        //    return;
        //}

        if (onAdClosed != null)
        {
            interstitialFinishDelegate = onAdClosed;
        }

        if (noAds != null && noAds())
        {
            OnInterstitialFinish(false);
            return;
        }

        if (this.interstitial != null && this.interstitial.IsLoaded())
        {
            //cacheInterstitial = cacheNextInter;
            LogEvent("InterstitialShow_" + logOriginName);
            this.showingAds       = true;
            this.interstitialTime = this.time;
            this.interstitial.Show();
#if UNITY_EDITOR
            OnInterstitialFinish(true);
#endif
            //("show inter success");
            return;
        }

        if (lastInterstitialRequestIsFailed)
        {
            OnInterstitialFinish(false);
        }
        else
        {
            //Old logic, this part shouldn't execute
            if (showLoading)
            {
                Manager.LoadingAnimation(true);
#if UNITY_EDITOR
                Manager.LoadingAnimation(false);
#endif
            }
            RequestInterstitial();
            this.interstitial.OnAdLoaded += HandleInterstitialLoaded;
            //this.interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
            //("added listener load");
        }
    }
Esempio n. 8
0
 void OnInterstitialLoaded(bool isSuccess = false)
 {
     if (interstitialLoadedDelegate != null)
     {
         interstitialLoadedDelegate(isSuccess);
         interstitialLoadedDelegate = null;
     }
     if (coTimeoutLoad != null)
     {
         StopCoroutine(coTimeoutLoad);
         coTimeoutLoad = null;
     }
 }
Esempio n. 9
0
    /// <param name="onAdLoaded">Function to call after the ads is loaded</param>
    public void RequestAdmobInterstitialNoShow(string newInterstitialId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        if (noAds != null && noAds())
        {
            onAdLoaded();
            return;
        }

        if (onAdLoaded != null)
        {
            interstitialLoadedDelegate = onAdLoaded;
            if (showLoading)
            {
                Manager.LoadingAnimation(true);
            }
            coTimeoutLoad = StartCoroutine(CoTimeoutLoadInterstitial());
        }
#if UNITY_EDITOR
        OnInterstitialLoaded(false);
        Manager.LoadingAnimation(false);
#endif

        if (this.interstitial != null)
        {
            if (!this.interstitial.IsLoaded())
            {
                Debug.Log("Previous Interstitial load is not finished");
                this.interstitial.OnAdClosed -= HandleInterstitialClosed;
                this.interstitial.Destroy();
                this.interstitial = null;
            }
            else
            {
                //.Log("Cached Ads loaded success, showing");
                HandleInterstitialLoadedNoShow(null, null); //if a previous interstitial was loaded but not shown, show that interstitial
                return;
            }
        }

        if (this.interstitial == null)
        {
            this.interstitial = new InterstitialAd(newInterstitialId);
            this.interstitial.LoadAd(this.CreateAdRequest());
            this.interstitial.OnAdClosed       += HandleInterstitialClosed;
            this.interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoadNoShow;
            this.interstitial.OnAdLoaded       += HandleInterstitialLoadedNoShow;

            lastInterstitialRequestIsFailed = false;
            //("added listener failed load");
        }
    }
Esempio n. 10
0
    public static bool ShowInterstitialWithCallback(AdsManager.InterstitialDelegate onAdClosed = null, bool showLoading = true)
    {
        if (AdsManager.instance != null)
        {
            if (instance.noAds != null && instance.noAds())
            {
                onAdClosed();
            }
            else
            {
                if (onAdClosed != null)
                {
                    instance.interstitialFinishDelegate = onAdClosed;
                }
                instance.ShowInterstitial(showLoading);
            }
        }

        return(false);
    }
Esempio n. 11
0
    public static bool RequestAndShowInterstitial(string newInterstitialId, AdsManager.InterstitialDelegate onAdClosed = null)
    {
        if (AdsManager.instance != null)
        {
            if (instance.noAds != null && instance.noAds())
            {
                onAdClosed();
            }
            else
            {
                if (onAdClosed != null)
                {
                    instance.interstitialFinishDelegate = onAdClosed;
                }
                instance.RequestInterstitial(newInterstitialId);
                instance.ShowInterstitial();
            }
        }

        return(false);
    }
Esempio n. 12
0
    public void RequestInterstitialNoShow(AdPlacementType placementId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        string id = CustomMediation.GetAdmobID(placementId, AdMobConst.INTERSTITIAL);

        RequestAdmobInterstitialNoShow(id, onAdLoaded, showLoading);
    }
Esempio n. 13
0
 public static void ShowBanner(string placementId, BannerPosition bannerPosition, AdsManager.InterstitialDelegate onAdLoaded = null)
 {
     instance.StartCoroutine(instance.ShowBannerWhenReady(placementId, bannerPosition, onAdLoaded));
 }
Esempio n. 14
0
    public void ShowBanner(AdPlacementType placementId, AdsManager.InterstitialDelegate onAdLoaded = null)
    {
        string id = CustomMediation.GetAdmobID(placementId, AdMobConst.BANNER_ID);

        ShowBanner(id, AdSize.GetCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth), 0f, onAdLoaded);
    }
Esempio n. 15
0
 public void ShowInterstitial(AdPlacementType placementId, AdsManager.InterstitialDelegate onAdClosed)
 {
     ShowInterstitial(true, onAdClosed, cacheInterstitial, placementId.ToString());
 }
Esempio n. 16
0
 public static void ShowInterstitial(string placementId, AdsManager.InterstitialDelegate onAdClosed)
 {
     Advertisement.Show(placementId);
 }
 public void ShowInterstitial(AdPlacementType placementType, AdsManager.InterstitialDelegate onAdClosed)
 {
     interstitialClosedDelegate = onAdClosed;
     ShowInterstitial(CustomMediation.GetFANPlacementId(placementType));
 }
Esempio n. 18
0
    public void ShowBanner(AdPlacement.Type placementType, BannerTransform bannerTransform, AdsManager.InterstitialDelegate onAdLoaded = null)
    {
        BannerPosition adPosition;

        switch (bannerTransform.adPosition)
        {
        case Omnilatent.AdsMediation.AdPosition.Top:
        case Omnilatent.AdsMediation.AdPosition.TopLeft:
        case Omnilatent.AdsMediation.AdPosition.TopRight:
            adPosition = BannerPosition.TOP_CENTER;
            break;

        case Omnilatent.AdsMediation.AdPosition.Bottom:
        case Omnilatent.AdsMediation.AdPosition.Center:
        default:
            adPosition = BannerPosition.BOTTOM_CENTER;
            break;
        }
        ShowBanner(CustomMediation.GetUnityPlacementId(placementType), adPosition, onAdLoaded);
    }
Esempio n. 19
0
 public void ShowBanner(AdPlacement.Type placementType, AdsManager.InterstitialDelegate onAdLoaded = null)
 {
     ShowBanner(placementType, Omnilatent.AdsMediation.BannerTransform.defaultValue, onAdLoaded);
 }
Esempio n. 20
0
 public void ShowInterstitial(AdPlacement.Type placementType, AdsManager.InterstitialDelegate onAdClosed)
 {
     onInterstitialClosed = onAdClosed;
     ShowInterstitial(CustomMediation.GetUnityPlacementId(placementType), onAdClosed);
 }
Esempio n. 21
0
 public void RequestInterstitialNoShow(AdPlacement.Type placementType, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
 {
     RequestInterstitialNoShow(CustomMediation.GetUnityPlacementId(placementType), onAdLoaded, showLoading);
 }
Esempio n. 22
0
    IEnumerator ShowBannerWhenReady(string placementId, BannerPosition bannerPosition, AdsManager.InterstitialDelegate onAdLoaded = null)
    {
        Advertisement.Banner.SetPosition(bannerPosition);

        BannerLoadOptions options = new BannerLoadOptions {
            loadCallback = OnLoadBannerSuccess, errorCallback = OnLoadBannerFail
        };

        Advertisement.Banner.Load(placementId, options);

        float timeoutTime = 5f, retryInterval = 0.2f;
        WaitForSecondsRealtime delay = new WaitForSecondsRealtime(retryInterval);
        int tryTimes = 0;

        while (!bannerLoadSuccess.HasValue && tryTimes < timeoutTime / retryInterval)
        {
            yield return(delay);

            tryTimes++;
        }

        if (!bannerLoadSuccess.HasValue)
        {
            LogEvent("LoadBannerTimeout", "", "");
            bannerLoadSuccess = false;
        }
        onAdLoaded?.Invoke(bannerLoadSuccess.Value);

        bool           adReady = Advertisement.IsReady(placementId);
        PlacementState adState = Advertisement.GetPlacementState(placementId);

        if (bannerLoadSuccess.Value)
        {
            Debug.Log($"Unity banner showing. State: {Advertisement.GetPlacementState(placementId)}, ready {adReady}");
            Advertisement.Banner.Show(placementId);
        }
        else
        {
            Debug.Log($"Unity banner show failed. State: {Advertisement.GetPlacementState(placementId)}, ready {adReady}");
        }

        /*if (adReady) //show banner regardless of load success or not since Unity Ads is the only ads
         *  Advertisement.Banner.Show(placementId);*/
        bannerLoadSuccess = null;
    }
 public void ShowBanner(AdPlacementType placementType, AdsManager.InterstitialDelegate onAdLoaded = null)
 {
     ShowBanner(CustomMediation.GetFANPlacementId(placementType), onAdLoaded);
 }
Esempio n. 24
0
 public void RequestInterstitialNoShow(string placementId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
 {
     StartCoroutine(CoRequestInterstitial(placementId, onAdLoaded, showLoading));
 }