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(); }
/// <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); }
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); }
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 }
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(); }
protected override void InitBannerCallBack() { #if MOPUB //加载完毕 MoPubManager.OnAdLoadedEvent += OnAdLoadedEvent; //加载失败 MoPubManager.OnAdFailedEvent += OnAdFailedEvent; //单击banner MoPubManager.OnAdClickedEvent += OnAdClickedEvent; //Fired when a banner ad expands to encompass a greater portion of the screen MoPubManager.OnAdExpandedEvent += OnAdExpandedEvent; // Android only. Fired when a banner ad collapses back to its initial size MoPubManager.OnAdCollapsedEvent += OnAdCollapsedEvent; MoPub.LoadBannerPluginsForAdUnits(_bannerAdUnits); #endif }
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; }
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 }
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; }
private void onADXConsentCompleted(string obj) { Debug.Log("onADXConsentCompleted"); //ADX string[] allBannerAdUnits = new string[_adData.BannerAdInfo.Length]; string[] allInterstitialAdUnits = new string[_adData.InterstitialAdInfo.Length]; for (int i = 0; i < allBannerAdUnits.Length; i++) { allBannerAdUnits[i] = _adData.BannerAdInfo[i].AdUnitId; } for (int i = 0; i < allInterstitialAdUnits.Length; i++) { allInterstitialAdUnits[i] = _adData.InterstitialAdInfo[i].AdUnitId; } MoPub.LoadBannerPluginsForAdUnits(allBannerAdUnits); MoPub.LoadInterstitialPluginsForAdUnits(allInterstitialAdUnits); }
public void InitStandard() { //*** Banner var allBannerAdUnits = new string[] { bannerAdUnitID }; MoPub.LoadBannerPluginsForAdUnits(allBannerAdUnits); //*** Interstitial var allInterstitialAdUnits = new string[] { interstitialAdUnitID }; MoPub.LoadInterstitialPluginsForAdUnits(allInterstitialAdUnits); //*** Banner MoPubManager.OnAdLoadedEvent += onAdLoadedEvent; MoPubManager.OnAdFailedEvent += onAdFailedEvent; //*** Interstitial MoPubManager.OnInterstitialLoadedEvent += onInterstitialLoadedEvent; MoPubManager.OnInterstitialFailedEvent += onInterstitialFailedEvent; MoPubManager.OnInterstitialDismissedEvent += onInterstitialDismissedEvent; }
private void CreateBanner() { MoPub.LoadBannerPluginsForAdUnits(new string[] { m_ADParams.adUnitId }); switch (m_ADParams.adPosition) { case ADPosition.Top: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.TopCenter); break; case ADPosition.Bottom: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.BottomCenter); break; case ADPosition.TopLeft: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.TopLeft); break; case ADPosition.TopRight: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.TopRight); break; case ADPosition.BottomLeft: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.BottomLeft); break; case ADPosition.BottomRight: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.BottomRight); break; case ADPosition.Center: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.Centered); break; case ADPosition.CustomDefine: MoPub.RequestBanner(m_ADParams.adUnitId, MoPub.AdPosition.TopCenter); break; } }
/// <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(); } }
// 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); }
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 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); } }
public override void SetAdConfig(TDAdConfig config) { base.SetAdConfig(config); MoPub.LoadBannerPluginsForAdUnits(new string[] { m_Config.unitID }); }
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 }