Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void Load(string placementId, BannerLoadOptions loadOptions)
        {
            if (!m_ListenerIsSet)
            {
                m_ListenerIsSet = true;
                m_BannersClass.CallStatic("setBannerListener", this);
            }

            m_BannerLoadOptions = loadOptions;
            if (m_BannerBundle != null && m_BannerBundle.bannerPlacementId.Equals(placementId))
            {
                m_Banner.UnityLifecycleManager.Post(() =>
                {
                    loadOptions?.loadCallback();
                });
            }
            else
            {
                if (m_BannerBundle != null)
                {
                    Hide(true);
                    m_BannerBundle = null;
                }
                if (placementId != null)
                {
                    m_BannersClass.CallStatic("loadBanner", m_CurrentActivity, placementId);
                }
                else
                {
                    m_BannersClass.CallStatic("loadBanner", m_CurrentActivity);
                }
            }
        }
Exemplo n.º 3
0
        public void Load(string placementId, BannerLoadOptions loadOptions)
        {
            IsLoaded = true;
            m_CurrentBannerPosition = m_TargetBannerPosition;

            m_Banner.UnityLifecycleManager.Post(() => {
                loadOptions?.loadCallback();
            });
        }
Exemplo n.º 4
0
 public void LoadBanner()
 {
     if (!Advertisement.Banner.isLoaded)
     {
         BannerLoadOptions loadOptions = new BannerLoadOptions
         {
             loadCallback  = OnBannerLoaded,
             errorCallback = OnBannerError
         };
         Advertisement.Banner.Load(bannerPlacementId, loadOptions);
     }
 }
    public void LoadBanner()
    {
        // Set up options to notify the SDK of load events:
        BannerLoadOptions options = new BannerLoadOptions
        {
            loadCallback  = OnBannerLoaded,
            errorCallback = OnBannerError
        };

        // Load the Ad Unit with banner content:
        Advertisement.Banner.Load(_bannerAdUnitId, options);
    }
    public void LoadBanner()
    {
        if (Advertisement.isInitialized == false)
        {
            Advertisement.Initialize(unityAdsId, showTestAd);
        }
        BannerLoadOptions options = new BannerLoadOptions {
            loadCallback = OnLoadBannerSuccess, errorCallback = OnLoadBannerFail
        };

        Advertisement.Banner.Load(bannerAdPlacement, options);
    }
Exemplo n.º 7
0
    public void LoadBanner()
    {
        debug.text += "Banner start loading";
        print("Banner start loading");
        BannerLoadOptions options = new BannerLoadOptions
        {
            loadCallback  = OnBannerLoaded,
            errorCallback = OnBannerError
        };

        Advertisement.Banner.Load(bannerID, options);
    }
Exemplo n.º 8
0
 public void ShowBanner()
 {
     if (bannerShown)
     {
         Advertisement.Banner.Hide(true);
     }
     else
     {
         BannerLoadOptions options = new BannerLoadOptions();
         options.loadCallback  = BannerLoadCallback;
         options.errorCallback = BannerErrorCallback;
         Advertisement.Banner.Load(bannerPlacementID, options);
     }
 }
Exemplo n.º 9
0
        public UnityAds(iAdsConfig config)
        {
            //set gameID
            switch (Application.platform)
            {
            case RuntimePlatform.Android:
            {
                _gameID = config.GetConfig <string>(UnityAdsConfig.GAME_ID_PLAYSTORE);
                break;
            }

            case RuntimePlatform.IPhonePlayer:
            {
                _gameID = config.GetConfig <string>(UnityAdsConfig.GAME_ID_APPSTORE);
                break;
            }

            default:
            {
                _gameID = config.GetConfig <string>(UnityAdsConfig.GAME_ID_PLAYSTORE);
                break;
            }
            }

            _bannerID       = config.GetConfig <string>(UnityAdsConfig.BANNER_ID);
            _interstitialID = config.GetConfig <string>(UnityAdsConfig.INTERSTITIAL_ID);
            _rewardID       = config.GetConfig <string>(UnityAdsConfig.REWARD_ID);
            _testMode       = config.GetConfig <bool>(UnityAdsConfig.TEST_MODE);

            _bannerLoadOptions = new BannerLoadOptions();
            _bannerLoadOptions.errorCallback += (error) => onBannerLoadFailed?.Invoke(this, error);
            _bannerLoadOptions.loadCallback  += () => onBannerLoaded?.Invoke(this);

            _bannerOptions = new BannerOptions();
            _bannerOptions.showCallback += () => onBannerOpening?.Invoke(this);
            _bannerOptions.hideCallback += () => onBannerClosed?.Invoke(this);

            Advertisement.AddListener(this);
            Advertisement.Initialize(_gameID, _testMode);

            if (Advertisement.isInitialized)
            {
                onInited?.Invoke(this);
            }
            else
            {
                WaitUntilInited();
            }
        }
Exemplo n.º 10
0
        //------------------------------------------------------------
        // Banner Ads.
        //------------------------------------------------------------


        protected override void InternalShowBannerAd(AdPlacement placement, BannerAdPosition postition, BannerAdSize size)
        {
#if UNITY_MONETIZATION
            string id = placement == AdPlacement.Default ?
                        mAdSettings.DefaultBannerAdId.Id :
                        FindIdForPlacement(mAdSettings.CustomBannerAdIds, placement);

            if (string.IsNullOrEmpty(id))
            {
                Debug.Log("Attempting to show UnityAds banner ad with an undefined ID at placement " + AdPlacement.GetPrintableName(placement));
                return;
            }

            if (!Advertisement.Banner.isLoaded)
            {
                BannerLoadOptions options = new BannerLoadOptions();

                options.errorCallback += ((string message) =>
                {
                    Debug.Log("Error: " + message);
                });

                options.loadCallback += (() =>
                {
                    Debug.Log("Ad Loaded");
                });

                Debug.Log("Loading banner ad");
                Advertisement.Banner.Load(id, options);
            }
            else
            {
                var showOptions = new BannerOptions
                {
                    showCallback = () =>
                    {
                        InternalShowBannerAdCallback(placement);
                    }
                };


                Advertisement.Banner.Show(id, showOptions);
            }
#else
            Debug.LogWarning(BANNER_UNSUPPORTED_MESSAGE);
#endif
        }
Exemplo n.º 11
0
        public IEnumerator UnityAdsBannerDidLoad(string expectedPlacementId)
        {
            var hasCalledListener = false;
            var banner            = new Banner(m_NativeBannerMock.Object, m_CoroutineExecutorMock.Object);
            var bannerLoadOptions = new BannerLoadOptions();

            bannerLoadOptions.loadCallback += () => {
                hasCalledListener = true;
            };
            banner.UnityAdsBannerDidLoad(expectedPlacementId, bannerLoadOptions);
            while (!hasCalledListener)
            {
                yield return(null);
            }
            Assert.That(hasCalledListener, Is.True, "The loadCallback should have been called");
            m_CoroutineExecutorMock.Verify(x => x.Post(It.IsAny <Action>()), Times.Once(), "Calls should happen on the main thread and should all batched together as 1 call");
        }
Exemplo n.º 12
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 ShowBannerAd()
 {
     if (Advertisement.Banner.isLoaded == false)
     {
         BannerLoadOptions options = new BannerLoadOptions {
             loadCallback = OnLoadBannerSuccess, errorCallback = OnLoadBannerFail
         };
         Advertisement.Banner.SetPosition(bannerPosition);
         Advertisement.Banner.Load(bannerAdPlacement, options);
     }
     else
     {
         BannerOptions options = new BannerOptions {
             showCallback = OnShowBanner, hideCallback = OnHideBanner
         };
         Advertisement.Banner.SetPosition(bannerPosition);
         Advertisement.Banner.Show(bannerAdPlacement, options);
     }
 }
Exemplo n.º 14
0
    IEnumerator LoadBanner()
    {
        Debug.Log("Clicked LoadBanner");
        while (!Advertisement.IsReady("banner"))
        {
            Debug.Log("Banner is not ready with state: " + Advertisement.GetPlacementState("banner"));
            yield return(new WaitForSeconds(0.5f));
        }

        if (Advertisement.IsReady("banner"))
        {
            Debug.Log("Load banner");
            BannerLoadOptions bannerLoadOptions = new BannerLoadOptions();
            bannerLoadOptions.loadCallback  = BannerLoadCallback;
            bannerLoadOptions.errorCallback = BannerErrorCallback;
            Advertisement.Banner.Load("banner", bannerLoadOptions);
        }
        else
        {
            Debug.Log("Banner is not ready with state: " + Advertisement.GetPlacementState("banner"));
        }
    }
    /**
     * 初期化
     */
    private void InitUnityAds()
    {
        // 動画広告をサポートしていないプラットフォームだったらreturn
        if (Advertisement.isSupported == false)
        {
            return;
        }

        // すでに初期化していたらreturn
        if (Advertisement.isInitialized)
        {
            return;
        }

#if UNITY_ANDROID
        _gameId = googlePlayGameId;
#elif UNITY_IOS
        _gameId = appStoreGameId;
#endif

        // 初期化
        Advertisement.Initialize(_gameId, testMode);

        // バナーを表示するポジションを設定する
        Advertisement.Banner.SetPosition(bannerPosition);

        // コールバックを設定する
        _bannerLoadOptions = new BannerLoadOptions()
        {
            loadCallback  = LoadCallback,
            errorCallback = ErrorCallback
        };
        _bannerOptions = new BannerOptions()
        {
            showCallback = ShowCallback,
            hideCallback = HideCallback
        };
    }
Exemplo n.º 16
0
    public void ShowBannerAd(BannerPosition bannerPosition)
    {
        if (!Advertisement.isInitialized)
        {
            InitializeAds();
        }

        if (!Advertisement.Banner.isLoaded)
        {
            BannerLoadOptions loadOptions = new BannerLoadOptions
            {
                loadCallback  = OnBannerLoaded,
                errorCallback = OnBannerError
            };

            Advertisement.Banner.SetPosition(bannerPosition);
            Advertisement.Banner.Load(BannerAd, loadOptions);
        }
        else
        {
            OnBannerLoaded();
        }
    }
Exemplo n.º 17
0
 /// <summary>
 /// Loads the banner ad with the default <a href="../manual/MonetizationPlacements.html">Placement</a>, but fires the <c>loadCallback</c> callback on successful load, and the <c>errorCallback</c> callback on failure to load.
 /// </summary>
 /// <param name="options">A collection of options that notify the SDK of events when loading the banner.</param>
 public static void Load(BannerLoadOptions options)
 {
     Load(null, options);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Loads the banner ad with a specified <a href="../manual/MonetizationPlacements.html">Placement</a>, but fires the <c>loadCallback</c> callback on successful load, and the <c>errorCallback</c> callback on failure to load.
 /// </summary>
 /// <param name="placementId">The unique identifier for a specific Placement, found on the <a href="https://operate.dashboard.unity3d.com/">developer dashboard</a>.</param>
 /// <param name="options">A collection of options that notify the SDK of events when loading the banner.</param>
 public static void Load(string placementId, BannerLoadOptions options)
 {
     s_Platform.Banner.Load(placementId, options);
 }
Exemplo n.º 19
0
 public void Load(string placementId, BannerLoadOptions loadOptions)
 {
 }