void Start()
    {
        m_Button = GetComponent <Button>();
        if (m_Button)
        {
            Debug.Log("m_Button - AddListener ShowAd");
            m_Button.onClick.AddListener(ShowAd);
        }

        if (Advertisement.isSupported)
        {
            Advertisement.Initialize(gameId, true);
            Debug.Log("Advertisement is supported - game id initialized: " + Advertisement.isInitialized);
        }

        Debug.Log("Successful start");

        var anyAdUnitId = _bannerAdUnits[0];

        MoPub.InitializeSdk(anyAdUnitId);

        MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
        MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedRichMediaAdUnits);

        CreateInterstitialsSection();
    }
Exemplo n.º 2
0
    /// <summary>
    /// Handle MoPub Menu Initialization Button Pressed event.
    /// </summary>
    public void OnInitializeMoPubPressed()
    {
        MoPub.InitializeSdk(MoPubManager.Instance.SdkConfiguration);

        MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
        MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedAdUnits);
    }
Exemplo n.º 3
0
    /// <summary>
    /// MoPub SDK Stuff
    /// </summary>
    ///

    public void ConfigureMoPubAds()
    {
        // MoPub Ads
        MoPubManager.OnRewardedVideoLoadedEvent += OnMopubRewardedVideoLoadedEvent;
        MoPubManager.OnRewardedVideoClosedEvent += OnMoPubRewardedVideoClosedEvent;
        MoPubManager.OnImpressionTrackedEvent   += OnMoPubImpressionTrackedEvent;

        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedAdUnits);
    }
Exemplo n.º 4
0
        protected void LoadAllAdUnits()
        {
            string[] allBannerIds        = GetAllIds(mAdSettings.DefaultBannerId.Id, mAdSettings.CustomBannerIds);
            string[] allInterstitialIds  = GetAllIds(mAdSettings.DefaultInterstitialAdId.Id, mAdSettings.CustomInterstitialAdIds);
            string[] allRewardedVideoIds = GetAllIds(mAdSettings.DefaultRewardedAdId.Id, mAdSettings.CustomRewardedAdIds);

            MoPub.LoadBannerPluginsForAdUnits(allBannerIds);
            MoPub.LoadInterstitialPluginsForAdUnits(allInterstitialIds);
            MoPub.LoadRewardedVideoPluginsForAdUnits(allRewardedVideoIds);
        }
Exemplo n.º 5
0
    private void Start()
    {
        // NOTE: the MoPub SDK needs to be initialized on Start() to ensure all other objects have been enabled first.
        var anyAdUnitId = _bannerAdUnits[0];

        MoPub.InitializeSdk(anyAdUnitId);

        MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
        MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedRichMediaAdUnits);
#if mopub_native_beta
        MoPub.LoadNativePluginsForAdUnits(_nativeAdUnits);
#endif

#if !(UNITY_ANDROID || UNITY_IOS)
        Debug.LogError("Please switch to either Android or iOS platforms to run sample app!");
#endif

#if UNITY_EDITOR
        Debug.LogWarning("No SDK was loaded since this is not on a mobile device! Real ads will not load.");
#endif

#if mopub_native_beta
        _nativeAds = new Dictionary <string, MoPubStaticNativeAd>();
        var staticNativeAds = GameObject.Find("MoPubNativeAds").GetComponentsInChildren <MoPubStaticNativeAd>();
        Debug.Log("Found " + staticNativeAds.Length + " mopub static native ads");
        foreach (var nativeAd in staticNativeAds)
        {
            _nativeAds.Add(nativeAd.AdUnitId, nativeAd);
            HideNativeAd(nativeAd);
        }

#if mopub_mediation
        _fbNativeAds = new Dictionary <string, FacebookNativeAd>();
        var fbStaticNativeAds = GameObject.Find("MoPubNativeAds").GetComponentsInChildren <FacebookNativeAd>();
        Debug.Log("Found " + fbStaticNativeAds.Length + " facebook native ads");
        foreach (var fbNativeAd in fbStaticNativeAds)
        {
            _fbNativeAds.Add(fbNativeAd.AdUnitId, fbNativeAd);
            HideNativeAd(fbNativeAd);
        }
#endif
#else
        var nativeAdsGO = GameObject.Find("MoPubNativeAds");
        if (nativeAdsGO != null)
        {
            nativeAdsGO.SetActive(false);
        }
#endif
    }
Exemplo n.º 6
0
        public override void SetAdConfig(TDAdConfig config)
        {
            base.SetAdConfig(config);
            MoPub.LoadRewardedVideoPluginsForAdUnits(new string[] { m_Config.unitID });

            MoPubManager.OnRewardedVideoLoadedEvent             += OnRewardedVideoLoadedEvent;
            MoPubManager.OnRewardedVideoFailedEvent             += OnRewardedVideoFailedEvent;
            MoPubManager.OnRewardedVideoExpiredEvent            += OnRewardedVideoExpiredEvent;
            MoPubManager.OnRewardedVideoShownEvent              += OnRewardedVideoShownEvent;
            MoPubManager.OnRewardedVideoClickedEvent            += OnRewardedVideoClickedEvent;
            MoPubManager.OnRewardedVideoFailedToPlayEvent       += OnRewardedVideoFailedToPlayEvent;
            MoPubManager.OnRewardedVideoReceivedRewardEvent     += OnRewardedVideoReceivedRewardEvent;
            MoPubManager.OnRewardedVideoClosedEvent             += OnRewardedVideoClosedEvent;
            MoPubManager.OnRewardedVideoLeavingApplicationEvent += OnRewardedVideoLeavingApplicationEvent;
        }
Exemplo n.º 7
0
 protected override void DoInitAD()
 {
     base.DoInitAD();
     MoPub.LoadRewardedVideoPluginsForAdUnits(new string[] { m_ADParams.adUnitId });
     DoPreLoadAD();
     MoPubManager.OnRewardedVideoLoadedEvent             += OnAdLoadedEvent;
     MoPubManager.OnRewardedVideoFailedEvent             += OnVideoFailedEvent;
     MoPubManager.OnRewardedVideoShownEvent              += OnVideoShownEvent;
     MoPubManager.OnRewardedVideoExpiredEvent            += OnAdExpiredEvent;
     MoPubManager.OnRewardedVideoReceivedRewardEvent     += OnVideoReceivedRewardEvent;
     MoPubManager.OnRewardedVideoClickedEvent            += OnAdClickedEvent;
     MoPubManager.OnRewardedVideoClosedEvent             += OnAdClosedEvent;
     MoPubManager.OnRewardedVideoLeavingApplicationEvent += OnAdVideoLeavingApplicationEvent;
     MoPubManager.OnRewardedVideoFailedToPlayEvent       += OnRewardedVideoFailedToPlayEvent;
 }
Exemplo n.º 8
0
    // Use this for initialization
    void Start()
    {
                #if UNITY_ANDROID
        // Initializing Ogury
        Presage.Initialize("270413");
                #endif

        // Initializing MoPub
        var sdkConfig = new MoPub.SdkConfiguration {
            AdUnitId = "3fa7d633bf8246f3a4ec0d92f477d3ca"
        };

        MoPub.InitializeSdk(sdkConfig);
        MoPub.LoadInterstitialPluginsForAdUnits(_InterstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_RewardedAdUnits);
    }
Exemplo n.º 9
0
    public void InitMoPubRV()
    {
        var allRewardedAdUnits = new string[] { mopubRvAdUnitID };

        MoPub.LoadRewardedVideoPluginsForAdUnits(allRewardedAdUnits);

        MoPubManager.OnRewardedVideoLoadedEvent             += OnRewardedVideoLoadedEvent;
        MoPubManager.OnRewardedVideoFailedEvent             += OnRewardedVideoFailedEvent;
        MoPubManager.OnRewardedVideoClosedEvent             += OnRewardedVideoClosedEvent;
        MoPubManager.OnRewardedVideoReceivedRewardEvent     += OnRewardedVideoReceivedRewardEvent;
        MoPubManager.OnRewardedVideoExpiredEvent            += OnRewardedVideoExpiredEvent;
        MoPubManager.OnRewardedVideoShownEvent              += OnRewardedVideoShownEvent;
        MoPubManager.OnRewardedVideoClickedEvent            += OnRewardedVideoClickedEvent;
        MoPubManager.OnRewardedVideoFailedToPlayEvent       += OnRewardedVideoFailedToPlayEvent;
        MoPubManager.OnRewardedVideoLeavingApplicationEvent += OnRewardedVideoLeavingApplicationEvent;
    }
Exemplo n.º 10
0
    public void Initialize(string adUnitId)
    {
        if (Application.installMode != ApplicationInstallMode.Store)
        {
            OverridePlacementsByTest();
        }
        //OverridePlacementsByTest();
        MoPub.LoadBannerPluginsForAdUnits(new[] { ADUNIT_BANNER });
        MoPub.LoadInterstitialPluginsForAdUnits(new[] { ADUNIT_INTERSTITIAL });
        MoPub.LoadRewardedVideoPluginsForAdUnits(new[] { ADUNIT_REWARDED_REVIVE });

        _adsManager.Initialize(this);

        SetupInterstitial();
        SetupRewarded();
    }
Exemplo n.º 11
0
    public void InitSDK()
    {
        var anyAdUnitId = _bannerAdUnits[0];

        MoPub.InitializeSdk(new MoPub.SdkConfiguration {
            AdUnitId         = anyAdUnitId,
            LogLevel         = MoPubBase.LogLevel.MPLogLevelDebug,
            MediatedNetworks = new MoPub.MediatedNetwork[]
            {},
        });

        MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
        MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);

        MoPubManager.OnSdkInitializedEvent += OnSdkInitializedEvent;
    }
Exemplo n.º 12
0
    private void Start()
    {
        // The SdkInitialize() call is handled by the MoPubManager prefab now. Please see:
        // https://developers.mopub.com/publishers/unity/initialize/#option-1-use-the-mopub-manager-recommended

        MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
        MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedRichMediaAdUnits);
#if mopub_native_beta
        MoPub.LoadNativePluginsForAdUnits(_nativeAdUnits);
#endif

#if !(UNITY_ANDROID || UNITY_IOS)
        Debug.LogError("Please switch to either Android or iOS platforms to run sample app!");
#endif

#if UNITY_EDITOR
        Debug.LogWarning("No SDK was loaded since this is not on a mobile device! Real ads will not load.");
#endif

#if mopub_native_beta
        _nativeAds = new Dictionary <string, MoPubStaticNativeAd>();
        var nativeAds = GameObject.Find("MoPubNativeAds");
        if (nativeAds == null)
        {
            return;
        }
        var staticNativeAds = nativeAds.GetComponentsInChildren <MoPubStaticNativeAd>();
        Debug.Log("Found " + staticNativeAds.Length + " mopub static native ads");
        foreach (var nativeAd in staticNativeAds)
        {
            _nativeAds[nativeAd.AdUnitId] = nativeAd;
            HideNativeAd(nativeAd);
        }
#else
        var nativeAdsGO = GameObject.Find("MoPubNativeAds");
        if (nativeAdsGO != null)
        {
            nativeAdsGO.SetActive(false);
        }
#endif
    }
Exemplo n.º 13
0
    void initMediation()
    {
        var mopConfig = new MoPub.SdkConfiguration();

        mopConfig.LogLevel = MoPub.LogLevel.Debug;
        mopConfig.AdUnitId = adUnitId;
        MoPub.InitializeSdk(mopConfig);

        string[] interstitials = { interstitialAdUnitId };
        MoPub.LoadInterstitialPluginsForAdUnits(interstitials);

        string[] rewards = { rewardAdUnitId };
        MoPub.LoadRewardedVideoPluginsForAdUnits(rewards);

        string[] banners = { bannerAdUnitId, mrecAdUnitId };
        MoPub.LoadBannerPluginsForAdUnits(banners);

        MoPubManager.OnSdkInitializedEvent += OnSdkInitializedEvent;
    }
Exemplo n.º 14
0
        /// <summary>
        /// Called after SDK was initialized
        /// </summary>
        /// <param name="defaultID">ID used to initialize SDK</param>
        private void SDKInitialized(string defaultID)
        {
            if (debug)
            {
                Debug.Log(this + " Initialized " + defaultID);
                ScreenWriter.Write(this + " Initialized " + defaultID);
            }

            UpdateConsent(consent, ccpaConsent);

            //prepare ad types
            if (!string.IsNullOrEmpty(bannerAdUnit))
            {
                MoPubManager.OnAdLoadedEvent += OnAdLoadedEvent;
                MoPubManager.OnAdFailedEvent += OnAdFailedEvent;

                MoPub.LoadBannerPluginsForAdUnits(new string[] { bannerAdUnit });
            }

            if (!string.IsNullOrEmpty(interstitialAdUnit))
            {
                MoPubManager.OnInterstitialLoadedEvent    += InterstitialLoaded;
                MoPubManager.OnInterstitialFailedEvent    += InterstitialFailed;
                MoPubManager.OnInterstitialDismissedEvent += InterstitialClosed;
                MoPub.LoadInterstitialPluginsForAdUnits(new string[] { interstitialAdUnit });
                LoadInterstitial();
            }

            if (!string.IsNullOrEmpty(rewardedVideoAdUnit))
            {
                MoPubManager.OnRewardedVideoLoadedEvent         += RewardedVideoLoaded;
                MoPubManager.OnRewardedVideoFailedEvent         += RewardedVideoFailed;
                MoPubManager.OnRewardedVideoFailedToPlayEvent   += RewardedVideoFailed;
                MoPubManager.OnRewardedVideoClosedEvent         += OnAdClosed;
                MoPubManager.OnRewardedVideoReceivedRewardEvent += RewardedVideoWatched;
                MoPub.LoadRewardedVideoPluginsForAdUnits(new string[] { rewardedVideoAdUnit });
                LoadRewardedVideo();
            }
        }
Exemplo n.º 15
0
    protected override void InitRewardedCallBack()
    {
#if MOPUB
        MoPubManager.OnRewardedVideoLoadedEvent += OnRewardedVideoLoadedEvent;
        //加载失败
        MoPubManager.OnRewardedVideoFailedEvent += OnRewardedVideoFailedEvent;
        //申请视频过期
        MoPubManager.OnRewardedVideoExpiredEvent += OnRewardedVideoExpiredEvent;
        //视频激活的时候回调
        MoPubManager.OnRewardedVideoShownEvent += OnRewardedVideoShownEvent;
        //视频单击回调
        MoPubManager.OnRewardedVideoClickedEvent += OnRewardedVideoClickedEvent;
        //视频播放失败
        MoPubManager.OnRewardedVideoFailedToPlayEvent += OnRewardedVideoFailedToPlayEvent;
        //视频完整播放完回调
        MoPubManager.OnRewardedVideoReceivedRewardEvent += OnRewardedVideoReceivedRewardEvent;
        //视频关闭回调
        MoPubManager.OnRewardedVideoClosedEvent += OnRewardedVideoClosedEvent;
        //视频广告跳转其他应用
        MoPubManager.OnRewardedVideoLeavingApplicationEvent += OnRewardedVideoLeavingApplicationEvent;

        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);
#endif
    }
Exemplo n.º 16
0
    private void Start()
    {
        // NOTE: the MoPub SDK needs to be initialized on Start() to ensure all other objects have been enabled first.
        var anyAdUnitId = _bannerAdUnits[0];

        MoPub.InitializeSdk(new MoPubBase.SdkConfiguration {
            AdUnitId          = anyAdUnitId,
            AdvancedBidders   = new MoPub.AdvancedBidder[] {
                // Add advanced bidder networks here.  Uncomment one of the following, or see the AdvancedBidder
                // class in MoPubBase.cs for more options.
                //MoPub.AdvancedBidder.AdMob,
                //MoPub.AdvancedBidder.Facebook,
                //MoPub.AdvancedBidder.Tapjoy,
                // If necessary, you can manually add a network using the plain constructor:
                //new MoPub.AdvancedBidder("NetworkClassName"),
                // where the class name is the mediation adapter's Java or ObjC class name, minus the "AdvancedBidder" suffix.
            },
            NetworksToInit    = new MoPub.RewardedNetwork[] {
                // Add rewarded networks here.  Uncomment one of the following, or see the RewardedVideo class
                // in MoPubBase.cs for more options.
                //MoPub.RewardedNetwork.AdColony,
                //MoPub.RewardedNetwork.Unity,
                //MoPub.RewardedNetwork.Vungle,
            },
            MediationSettings = new MoPubBase.MediationSetting[] {
                // Add global mediation settings here, following the schema below (which uses AdMob as an example)
                //new MoPub.MediationSetting.AdMob {
                // { "key", "value" },
                // { "key", "value" },
                //},
            }
        });

        MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
        MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedRichMediaAdUnits);
#if mopub_native_beta
        MoPub.LoadNativePluginsForAdUnits(_nativeAdUnits);
#endif

#if !(UNITY_ANDROID || UNITY_IOS)
        Debug.LogError("Please switch to either Android or iOS platforms to run sample app!");
#endif

#if UNITY_EDITOR
        Debug.LogWarning("No SDK was loaded since this is not on a mobile device! Real ads will not load.");
#endif

#if mopub_native_beta
        _nativeAds = new Dictionary <string, MoPubStaticNativeAd>();
        var nativeAds = GameObject.Find("MoPubNativeAds");
        if (nativeAds == null)
        {
            return;
        }
        var staticNativeAds = nativeAds.GetComponentsInChildren <MoPubStaticNativeAd>();
        Debug.Log("Found " + staticNativeAds.Length + " mopub static native ads");
        foreach (var nativeAd in staticNativeAds)
        {
            _nativeAds.Add(nativeAd.AdUnitId, nativeAd);
            HideNativeAd(nativeAd);
        }
#else
        var nativeAdsGO = GameObject.Find("MoPubNativeAds");
        if (nativeAdsGO != null)
        {
            nativeAdsGO.SetActive(false);
        }
#endif
    }
Exemplo n.º 17
0
    private void SDKInit()
    {
        // NOTE: the MoPub SDK needs to be initialized on Start() to ensure all other objects have been enabled first.
        var anyAdUnitId = bannerIdList[0];

        //MoPub.InitializeSdk(anyAdUnitId);


        MoPub.InitializeSdk(new MoPub.SdkConfiguration
        {
            AdUnitId = anyAdUnitId,

            // Set desired log level here to override default level of MPLogLevelNone
            LogLevel = MoPubBase.LogLevel.MPLogLevelDebug,

            // Uncomment the following line to allow supported SDK networks to collect user information on the basis
            // of legitimate interest.
            //AllowLegitimateInterest = true,

            // Specify the mediated networks you are using here:
            MediatedNetworks = new MoPub.MediatedNetwork[]
            {
                //new MoPub.SupportedNetwork.AdMob()
                //{
                //    // Network adapter configuration settings (initialization).
                //    NetworkConfiguration = {
                //        {"npa", "1"}
                //    },
                //    // Global mediation settings (per ad request).
                //    MediationSettings =
                //    {
                //        {"npa", "1"}
                //    },
                //     // Additional options to pass to the MoPub servers (per ad request).
                //    MoPubRequestOptions = {
                //        {"npa", "1"}
                //    }
                //},


                /*
                 *  // Example using AdMob.  Follow this template for other supported networks as well.
                 *  // Note that keys must be strings, and values must be JSON-serializable (strings only, for MoPubRequestOptions).
                 *  new MoPub.SupportedNetwork.AdMob
                 *  {
                 *      // Network adapter configuration settings (initialization).
                 *      NetworkConfiguration = {
                 *          { "key1", value },
                 *          { "key2", value },
                 *      },
                 *
                 *      // Global mediation settings (per ad request).
                 *      MediationSettings = {
                 *          { "key1", value },
                 *          { "key2", value },
                 *      },
                 *
                 *      // Additional options to pass to the MoPub servers (per ad request).
                 *      MoPubRequestOptions = {
                 *          { "key1", "value" },
                 *          { "key2", "value" },
                 *      }
                 *  },
                 *
                 *  // Example using a custom network adapter:
                 *  new MoPub.MediatedNetwork
                 *  {
                 *      // Specify the class name that implements the AdapterConfiguration interface.
                 #if UNITY_ANDROID
                 *      AdapterConfigurationClassName = "classname",  // include the full package name
                 #else // UNITY_IOS
                 *      AdapterConfigurationClassName = "classname",
                 #endif
                 *
                 *      // Specify the class name that implements the MediationSettings interface.
                 *      // Note: Custom network mediation settings are currently not supported on Android.
                 #if UNITY_IOS
                 *      MediationSettingsClassName = "classname",
                 #endif
                 *
                 *      // Fill in settings and configuration options the same way as for supported networks:
                 *
                 *      NetworkConfiguration = { ... },
                 *
                 #if UNITY_IOS  // See note above.
                 *      MediationSettings    = { ... },
                 #endif
                 *
                 *      MoPubRequestOptions  = { ... },
                 *  }
                 */
            },
        });


        // register for initialized callback event in the app
        MoPubManager.OnSdkInitializedEvent += OnSdkInitializedEvent;

        MoPub.LoadBannerPluginsForAdUnits(bannerIdList);
        MoPub.LoadInterstitialPluginsForAdUnits(insterIdList);
        MoPub.LoadRewardedVideoPluginsForAdUnits(rvIdList);

#if !(UNITY_ANDROID || UNITY_IOS)
        Debug.LogError("Please switch to either Android or iOS platforms to run sample app!");
#endif

#if UNITY_EDITOR
        Debug.LogWarning("No SDK was loaded since this is not on a mobile device! Real ads will not load.");
#endif

        var nativeAdsGO = GameObject.Find("MoPubNativeAds");
        if (nativeAdsGO != null)
        {
            nativeAdsGO.SetActive(false);
        }
    }
Exemplo n.º 18
0
    void Awake()
    {
        if (sInstance == null)
        {
            sInstance = this;
            DontDestroyOnLoad(this.gameObject);
        }
        else
        {
            Destroy(this.gameObject);
        }


#if UNITY_ANDROID
        strVideoKey        = "eba74787288a4d0bb694aa1513d6c3c6";
        strInterstitialKey = "05ce1a8662d14d4daad4842964a9edaa";

        strAppId = "";
#else
        strVideoKey        = "6c4e740a286d4f7fab710dc3af586c7f";
        strInterstitialKey = "c2170d04c20a465792f1646df515e193";

        strAppId = "";
#endif

        MoPub.InitializeSdk(new MoPub.SdkConfiguration
        {
            // MediatedNetworks = new MoPub.MediatedNetwork[]
            // {
            //     new MoPub.SupportedNetwork.AppLovin
            //     {
            //         NetworkConfiguration = new Dictionary< string, object > {
            //             { "sdk_key", "CR4KmCdD0TUPNE-ARH4HtdfmokMLxvZ8KdS4q5IqZnEx0C5STAkKoO5a6Rw2LTAg6dlxk2mHp-CqAHGdR_zEO3" },
            //         }
            //     }
            // },

            AdUnitId = strVideoKey,
            // LogLevel = MoPubBase.LogLevel.MPLogLevelDebug,
        });


        //MoPub.EnableLocationSupport(Percent.CrossPromotion.hasAgreed);

        MoPub.LoadRewardedVideoPluginsForAdUnits(new string[] { strVideoKey });
        //MoPub.LoadInterstitialPluginsForAdUnits(new string[] { strInterstitialKey });

        MoPubManager.OnSdkInitializedEvent += OnSdkInitializedEvent;

        // MoPubManager.OnAdLoadedEvent += OnAdLoadedEvent;
        // MoPubManager.OnAdFailedEvent += OnAdFailedEvent;
        // MoPubManager.OnAdClickedEvent += OnAdClickedEvent;
        // MoPubManager.OnAdExpandedEvent += OnAdExpandedEvent;
        // MoPubManager.OnAdCollapsedEvent += OnAdCollapsedEvent;

        MoPubManager.OnInterstitialLoadedEvent    += OnInterstitialLoadedEvent;
        MoPubManager.OnInterstitialFailedEvent    += OnInterstitialFailedEvent;
        MoPubManager.OnInterstitialShownEvent     += OnInterstitialShownEvent;
        MoPubManager.OnInterstitialClickedEvent   += OnInterstitialClickedEvent;
        MoPubManager.OnInterstitialDismissedEvent += OnInterstitialDismissedEvent;
        MoPubManager.OnInterstitialExpiredEvent   += OnInterstitialExpiredEvent;


        MoPubManager.OnRewardedVideoLoadedEvent             += OnRewardedVideoLoadedEvent;
        MoPubManager.OnRewardedVideoFailedEvent             += OnRewardedVideoFailedEvent;
        MoPubManager.OnRewardedVideoExpiredEvent            += OnRewardedVideoExpiredEvent;
        MoPubManager.OnRewardedVideoShownEvent              += OnRewardedVideoShownEvent;
        MoPubManager.OnRewardedVideoClickedEvent            += OnRewardedVideoClickedEvent;
        MoPubManager.OnRewardedVideoFailedToPlayEvent       += OnRewardedVideoFailedToPlayEvent;
        MoPubManager.OnRewardedVideoReceivedRewardEvent     += OnRewardedVideoReceivedRewardEvent;
        MoPubManager.OnRewardedVideoClosedEvent             += OnRewardedVideoClosedEvent;
        MoPubManager.OnRewardedVideoLeavingApplicationEvent += OnRewardedVideoLeavingApplicationEvent;

        Debug.Log("Init Start");
    }
Exemplo n.º 19
0
    private void Start()
    {
        // NOTE: the MoPub SDK needs to be initialized on Start() to ensure all other objects have been enabled first.
        var anyAdUnitId = _bannerAdUnits[0];

        MoPub.InitializeSdk(new MoPub.SdkConfiguration {
            AdUnitId = anyAdUnitId,

            // Set desired log level here to override default level of MPLogLevelNone
            LogLevel = MoPubBase.LogLevel.MPLogLevelDebug,

            // Uncomment the following line to allow supported SDK networks to collect user information on the basis
            // of legitimate interest.
            //AllowLegitimateInterest = true,

            // Specify the mediated networks you are using here:
            MediatedNetworks = new MoPub.MediatedNetwork[]
            {
                /*
                 *  // Example using AdMob.  Follow this template for other supported networks as well.
                 *  // Note that keys must be strings, and values must be JSON-serializable (strings only, for MoPubRequestOptions).
                 *  new MoPub.SupportedNetwork.AdMob
                 *  {
                 *      // Network adapter configuration settings (initialization).
                 *      NetworkConfiguration = new Dictionary<string,object> {
                 *          { "key1", value },
                 *          { "key2", value },
                 *      },
                 *
                 *      // Global mediation settings (per ad request).
                 *      MediationSettings = new Dictionary<string,object> {
                 *          { "key1", value },
                 *          { "key2", value },
                 *      },
                 *
                 *      // Additional options to pass to the MoPub servers (per ad request).
                 *      MoPubRequestOptions = new Dictionary<string,object> {
                 *          { "key1", "value" },
                 *          { "key2", "value" },
                 *      }
                 *  },
                 *
                 *  // Example using a custom network adapter:
                 *  new MoPub.MediatedNetwork
                 *  {
                 *      // Specify the class name that implements the AdapterConfiguration interface.
                 #if UNITY_ANDROID
                 *      AdapterConfigurationClassName = "classname",  // include the full package name
                 #else // UNITY_IOS
                 *      AdapterConfigurationClassName = "classname",
                 #endif
                 *
                 *      // Specify the class name that implements the MediationSettings interface.
                 *      // Note: Custom network mediation settings are currently not supported on Android.
                 #if UNITY_IOS
                 *      MediationSettingsClassName = "classname",
                 #endif
                 *
                 *      // Fill in settings and configuration options the same way as for supported networks:
                 *
                 *      NetworkConfiguration = ...,
                 *
                 #if UNITY_IOS  // See note above.
                 *      MediationSettings = ...,
                 #endif
                 *
                 *      MoPubRequestOptions = ...,
                 *  }
                 */
            },
        });

        MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits);
        MoPub.LoadInterstitialPluginsForAdUnits(_interstitialAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedVideoAdUnits);
        MoPub.LoadRewardedVideoPluginsForAdUnits(_rewardedRichMediaAdUnits);
#if mopub_native_beta
        MoPub.LoadNativePluginsForAdUnits(_nativeAdUnits);
#endif

#if !(UNITY_ANDROID || UNITY_IOS)
        Debug.LogError("Please switch to either Android or iOS platforms to run sample app!");
#endif

#if UNITY_EDITOR
        Debug.LogWarning("No SDK was loaded since this is not on a mobile device! Real ads will not load.");
#endif

#if mopub_native_beta
        _nativeAds = new Dictionary <string, MoPubStaticNativeAd>();
        var nativeAds = GameObject.Find("MoPubNativeAds");
        if (nativeAds == null)
        {
            return;
        }
        var staticNativeAds = nativeAds.GetComponentsInChildren <MoPubStaticNativeAd>();
        Debug.Log("Found " + staticNativeAds.Length + " mopub static native ads");
        foreach (var nativeAd in staticNativeAds)
        {
            _nativeAds[nativeAd.AdUnitId] = nativeAd;
            HideNativeAd(nativeAd);
        }
#else
        var nativeAdsGO = GameObject.Find("MoPubNativeAds");
        if (nativeAdsGO != null)
        {
            nativeAdsGO.SetActive(false);
        }
#endif
    }