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();
    }
Exemple #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);
    }
Exemple #3
0
 void Start()
 {
     if (Instance == this && AutoInitializeOnStart && !MoPub.IsSdkInitialized)
     {
         MoPub.ReportApplicationOpen(itunesAppId);
         MoPub.EnableLocationSupport(LocationAware);
         MoPub.InitializeSdk(SdkConfiguration);
         MoPub.SetEngineInformation();
     }
 }
        /// <summary>
        /// Initializing MoPub
        /// </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)
            {
                initialized = 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
                //apply settings
                bannerAdUnit        = settings.idBanner.id;
                interstitialAdUnit  = settings.idInterstitial.id;
                rewardedVideoAdUnit = settings.idRewarded.id;
                this.consent        = consent;
                this.ccpaConsent    = ccpaConsent;

                //verify settings
                if (debug)
                {
                    Debug.Log(this + " Initialize");
                    ScreenWriter.Write(this + " Initialize");
                    Debug.Log(this + " Banner ID: " + bannerAdUnit);
                    ScreenWriter.Write(this + " Banner ID: " + bannerAdUnit);
                    Debug.Log(this + " Interstitial ID: " + interstitialAdUnit);
                    ScreenWriter.Write(this + " Interstitial ID: " + interstitialAdUnit);
                    Debug.Log(this + " Rewarded ID: " + rewardedVideoAdUnit);
                    ScreenWriter.Write(this + " Rewarded ID: " + rewardedVideoAdUnit);
                }

                MoPubManager.OnSdkInitializedEvent += SDKInitialized;
                string defaultID = null;
                if (string.IsNullOrEmpty(defaultID))
                {
                    defaultID = bannerAdUnit;
                }
                if (string.IsNullOrEmpty(defaultID))
                {
                    defaultID = interstitialAdUnit;
                }
                if (string.IsNullOrEmpty(defaultID))
                {
                    defaultID = rewardedVideoAdUnit;
                }

                if (!string.IsNullOrEmpty(defaultID))
                {
                    MoPub.InitializeSdk(defaultID);
                }
            }
        }
    void Start()
    {
        if (Instance != this || !AutoInitializeOnStart || MoPub.IsSdkInitialized)
        {
            return;
        }

        MoPub.InitializeSdk(SdkConfiguration);
        MoPub.ReportApplicationOpen(itunesAppId);
        MoPub.EnableLocationSupport(LocationAware);
    }
Exemple #6
0
        /// <summary>
        /// Init Mopub sdk with an id from <see cref="GetInitializeId"/>.
        /// </summary>
        protected bool NormalInit()
        {
            string initId = GetInitializeId();

            if (string.IsNullOrEmpty(initId))
            {
                Debug.LogError("MoPubClient init error. Please provide at least one default ad id.");
                return(false);
            }

            MoPub.InitializeSdk(initId);
            return(true);
        }
Exemple #7
0
 /// <summary>
 /// Init Mopub sdk with extra <see cref="MoPubBase.SdkConfiguration"/> from <see cref="GetSdkConfiguration"/>.
 /// </summary>
 protected bool AdvancedInit()
 {
     try
     {
         MoPub.InitializeSdk(GetSdkConfiguration());
         return(true);
     }
     catch (Exception e)
     {
         Debug.LogError("MoPub init error: " + e.Message);
         return(false);
     }
 }
    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
    }
Exemple #9
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);
    }
Exemple #10
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;
    }
Exemple #11
0
    public override void Init()
    {
#if MOPUB
        // 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 = MoPub.LogLevel.Debug,
        });

        // register for initialized callback event in the app
        MoPubManager.OnSdkInitializedEvent += OnSdkInitializedEventHandler;
#endif
    }
Exemple #12
0
    private void InitializeMoPubSDK()
    {
        const int titlePadding = 102;

        GUILayout.Space(titlePadding);
        GUILayout.Label("Initialize MoPub SDK");
        //GUILayout.BeginHorizontal();
        GUI.enabled = !init;
        if (GUILayout.Button("Initialize MoPub SDK"))
        {
            MoPub.InitializeSdk(MoPubManager.Instance.SdkConfiguration);
            init = true;
        }
        if (init)
        {
            CreateInterstitialsSection();
            CreateRewardedVideosSection();
        }
    }
Exemple #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;
    }
Exemple #14
0
    // Use this for initialization
    void Start()
    {
        // Create and instantiate an SdkConfiguration
        // Publishers can override MoPubEventListener.OnSdkInitializedEvent() to get a callback.
        // Alternatively, publishers can call "yield return WaitUntil(() => MoPub.IsSdkInitialized)" to suspend the coroutine execution until the SDK has initialized.
        Debug.Log("GGMOPUBTEST Initializing Mopub");
        MoPub.SdkConfiguration sdkConfiguration = new MoPub.SdkConfiguration();
        sdkConfiguration.AdUnitId = bannerIds[0];
        Debug.Log("GGMOPUBTEST Initializing Mopub1");
        MoPub.EnableLocationSupport(true);
        MoPubManager.OnSdkInitializedEvent += mySDKInitialized;
        //MoPub.RequestInterstitialAd(interstitialId3);
        Debug.Log("GGMOPUBTEST Initializing Mopub2");
        MoPub.LoadBannerPluginsForAdUnits(bannerIds);
        MoPub.InitializeSdk(sdkConfiguration);
        Debug.Log("GGMOPUBTEST Initializing Mopub3");

        var props = new Value();

        props["mopubunitid"] = bannerIds[0];
        props["event"]       = "initialize";
        Mixpanel.Track("mopub-initialize", props);
    }
Exemple #15
0
        protected override bool DoAdapterInit(SDKConfig config, SDKAdapterConfig adapterConfig)
        {
            m_Config = adapterConfig as MoPubAdsConfig;
#if UNITY_ANDROID
            string appId = m_Config.appIDAndroid;
#elif UNITY_IPHONE
            string appId = m_Config.appIDIos;
#else
            string appId = "unexpected_platform";
#endif

            string adUnit = m_Config.anyAdUnit;

            MoPub.InitializeSdk(new MoPubBase.SdkConfiguration
            {
                AdUnitId        = adUnit,
                AdvancedBidders = new MoPub.AdvancedBidder[] {
                    MoPub.AdvancedBidder.AppLovin,
                    MoPub.AdvancedBidder.Unity,
                    MoPub.AdvancedBidder.AdMob,
                    MoPub.AdvancedBidder.Facebook
                },
                NetworksToInit = new MoPub.RewardedNetwork[] {
                    MoPub.RewardedNetwork.Unity,
                    MoPub.RewardedNetwork.Facebook,
                    MoPub.RewardedNetwork.AppLovin,
                    MoPub.RewardedNetwork.AdMob
                },
                MediationSettings = new MoPubBase.MediationSetting[] {
                }
            });

            MoPub.ReportApplicationOpen(appId);

            return(true);
        }
Exemple #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
    }
    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
    }
Exemple #18
0
    protected override bool AdapterInit(SDKAdapterConfig adapterConfig)
    {
        m_Config = adapterConfig as MopubAdsConfig;
        //mopubSDK初始化
#if UNITY_ANDROID
        string appId = m_Config.androidAppID;
#elif UNITY_IPHONE
        string appId = m_Config.iosAppID;
#else
        string appId = "unexpected_platform";
#endif
        // MoPub.ReportApplicationOpen(appId);

        //绑定日记等级
        MoPub.LogLevel logLevel = MoPub.LogLevel.None;
        if (m_Config.isDebugMode)
        {
            logLevel = MoPub.LogLevel.Debug;
        }

        //绑定初始化回调
        MoPubManager.OnSdkInitializedEvent += OnSdkInitializedEvent;
        MoPub.InitializeSdk(new MoPub.SdkConfiguration
        {
            //设置任意一个有效的广告id
            AdUnitId = m_Config.anyAdUnit,
            LogLevel = logLevel,

            //启动数据收集标记
            //AllowLegitimateInterest = true,

            //初始化广告网络示例
            //Note that keys must be strings, and values must be JSON-serializable (strings only, for MoPubRequestOptions).
            MediatedNetworks = new MoPubBase.MediatedNetwork[]
            {
                new MoPub.SupportedNetwork.Facebook {
                },
                new MoPub.SupportedNetwork.Unity {
                },

                new MoPub.SupportedNetwork.AdMob
                {
                    // Network adapter configuration settings (initialization).
                    // NetworkConfiguration = new Dictionary<string,string> {
                    //     { "app_id", "ca-app-pub-9726677720163576~9749987692" },
                    // },
                    // Global mediation settings (per ad request).
                    MediationSettings = new Dictionary <string, object> {
                        { "npa", 1 },
                    },
                    // Additional options to pass to the MoPub servers (per ad request).
                    // MoPubRequestOptions = new Dictionary<string,string> {
                    //     { "key1", "1" },
                    //     { "key2", "1" },
                    // }
                }
            }
        });


        return(true);
    }
Exemple #19
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");
    }
        /// <summary>
        /// Initialize.
        /// </summary>
        public void Initialize(Action onCompleteCallback = null)
        {
#if DEBUG_MY_ADMOB
            Debug.Log("[" + typeof(MyAdMobManager).Name + "] Initialize()");
#endif

            if (mTestEnable && mTestDeviceId.Length > 0)
            {
                if (mTestUseGoogleAdsId)
                {
                    mAndroidDefaultBannerId         = "ca-app-pub-3940256099942544/6300978111";
                    mAndroidDefaultInterstitialAdId = "ca-app-pub-3940256099942544/1033173712";
                    mAndroidDefaultRewardedAdId     = "ca-app-pub-3940256099942544/5224354917";

                    mIosDefaultBannerId         = "ca-app-pub-3940256099942544/2934735716";
                    mIosDefaultInterstitialAdId = "ca-app-pub-3940256099942544/4411468910";
                    mIosDefaultRewardedAdId     = "ca-app-pub-3940256099942544/1712485313";

#if UNITY_ANDROID
                    PlayerPrefs.SetString("MyAdMobManager_BannerId", mAndroidDefaultBannerId);
                    PlayerPrefs.SetString("MyAdMobManager_InterstitialAdId", mAndroidDefaultInterstitialAdId);
                    PlayerPrefs.SetString("MyAdMobManager_RewardedAdId", mAndroidDefaultRewardedAdId);
#elif UNITY_IOS
                    PlayerPrefs.SetString("MyAdMobManager_BannerId", mIosDefaultBannerId);
                    PlayerPrefs.SetString("MyAdMobManager_InterstitialAdId", mIosDefaultInterstitialAdId);
                    PlayerPrefs.SetString("MyAdMobManager_RewardedAdId", mIosDefaultRewardedAdId);
#endif
                }

                List <string> deviceIds = new List <string>();
                deviceIds.AddRange(mTestDeviceId.Split(';'));
                RequestConfiguration requestConfiguration = new RequestConfiguration.Builder().SetTestDeviceIds(deviceIds).build();
                MobileAds.SetRequestConfiguration(requestConfiguration);
            }

            MobileAds.Initialize(initStatus =>
            {
#if DEBUG_MY_ADMOB
                Debug.Log("[" + typeof(MyAdMobManager).Name + "] Initialize(): completed");
#endif

                mIsInitialized = true;

                if (onCompleteCallback != null)
                {
                    onCompleteCallback();
                }
            });

#if USE_MY_ADMOB_APPLOVIN
            AppLovin.Initialize();
            AppLovin.SetHasUserConsent(true);
#endif

#if USE_MY_ADMOB_MOPUB
            MoPub.InitializeSdk("8c09b6f2cb324838acf2fdad6899f5a8");
#endif

#if USE_MY_ADMOB_UNITY_ADS
            UnityAds.SetGDPRConsentMetaData(true);
#endif

#if USE_MY_ADMOB_VUNGLE
            Vungle.UpdateConsentStatus(VungleConsent.ACCEPTED);
#endif
        }
Exemple #21
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);
        }
    }