private void RequestNativeExpressAdView() { // These ad units are configured to always serve test ads. #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-3940256099942544/1072772517"; #elif UNITY_IPHONE string adUnitId = "ca-app-pub-3940256099942544/2562852117"; #else string adUnitId = "unexpected_platform"; #endif // Create a 320x150 native express ad at the top of the screen. this.nativeExpressAdView = new NativeExpressAdView( adUnitId, new AdSize(320, 150), AdPosition.Top); // Register for ad events. this.nativeExpressAdView.OnAdLoaded += this.HandleNativeExpressAdLoaded; this.nativeExpressAdView.OnAdFailedToLoad += this.HandleNativeExpresseAdFailedToLoad; this.nativeExpressAdView.OnAdLoaded += this.HandleNativeExpressAdOpened; this.nativeExpressAdView.OnAdClosed += this.HandleNativeExpressAdClosed; this.nativeExpressAdView.OnAdLeavingApplication += this.HandleNativeExpressAdLeftApplication; // Load a native express ad. this.nativeExpressAdView.LoadAd(this.CreateAdRequest()); }
public void RequestNativeAds(AdPosition nativeAdPosition) { if (isNativeAdLoaded) { return; } // Create a 320x50 native express ad at the top of the screen. nativeExpressAdView = new NativeExpressAdView(_nativeAdsId, new AdSize(320, 150), nativeAdPosition); // Load a banner ad. nativeExpressAdView.LoadAd(new AdRequest.Builder() .AddTestDevice(AdRequest.TestDeviceSimulator) // Simulator. .AddTestDevice("2077ef9a63d2b398840261c8221a0c9b") // My test device. .Build()); //Debug.Log("Load native ads"); if (!handleNativeAdsSet) { // Called when an ad request has successfully loaded. nativeExpressAdView.OnAdLoaded += HandleOnNativeAdLoaded; // Called when an ad request failed to load. nativeExpressAdView.OnAdFailedToLoad += HandleOnNativeAdFailedToLoad; // Called when an ad is clicked. //nativeExpressAdView.OnAdOpened += HandleOnAdOpened; // Called when the user returned from the app after an ad click. //nativeExpressAdView.OnAdClosed += HandleOnNativeAdClosed; // Called when the ad click caused the user to leave the application. //nativeExpressAdView.OnAdLeavingApplication += HandleOnAdLeavingApplication; handleNativeAdsSet = true; } }
public void RequestNativeExpressAdView(Rect rect) { if (nativeState == AdsState.Loaded || nativeState == AdsState.Loading) { return; } // These ad units are configured to always serve test ads. #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = nativeAndroid; #elif UNITY_IPHONE string adUnitId = nativeIOS; #else string adUnitId = "unexpected_platform"; #endif #if UNITY_ANDROID || UNITY_IOS || !EDITOR // Create a 320x150 native express ad at the top of the screen. this.nativeExpressAdView = new NativeExpressAdView( adUnitId, new AdSize(320, 150), AdPosition.Top); // Register for ad events. this.nativeExpressAdView.OnAdLoaded += this.HandleNativeExpressAdLoaded; this.nativeExpressAdView.OnAdFailedToLoad += this.HandleNativeExpresseAdFailedToLoad; this.nativeExpressAdView.OnAdOpening += this.HandleNativeExpressAdOpened; this.nativeExpressAdView.OnAdClosed += this.HandleNativeExpressAdClosed; this.nativeExpressAdView.OnAdLeavingApplication += this.HandleNativeExpressAdLeftApplication; // Load a native express ad. this.nativeExpressAdView.LoadAd(adRequest); nativeState = AdsState.Loading; #endif }
public void NativeInit() { if (nativeAd != null) { nativeAd.Destroy(); nativeAd = null; } string adUnitId = ""; if (Application.platform == RuntimePlatform.IPhonePlayer) { adUnitId = "ca-app-pub-7619324821036210/1135180686"; } else { adUnitId = "ca-app-pub-7619324821036210/4647050289"; } AdSize adsize = new AdSize(300, 100); AdPosition adPosition = AdPosition.Top; nativeAd = new NativeExpressAdView(adUnitId, adsize, adPosition); RegisterNativeCallback(); }
private void HandleOnNativeExpressOpening(object sender, EventArgs args) { nativeAdView = (NativeExpressAdView)sender; MyDebug.Log("GMAS::HandleOnNativeExpressOpening =>" + this.nativeAdView.adUnitId); if (this.OnNativeExperssAdOpening != null) { this.OnNativeExperssAdOpening.Invoke(this.nativeAdView.adUnitId); } }
public void DidReceiveAd(NativeExpressAdView nativeExpressAdView) { if (nativeExpressAdView.VideoController.HasVideoContent()) { } else { } }
private void HandleOnNativeExpressLeavingApplication(object sender, EventArgs args) { this.nativeAdView = (NativeExpressAdView)sender; MyDebug.Log("GMAS::HandleOnNativeExpressLeavingApplication =>" + this.nativeAdView.adUnitId); if (this.OnNativeExperssAdLeavingApplication != null) { this.OnNativeExperssAdLeavingApplication.Invoke(this.nativeAdView.adUnitId); } }
private void HandleOnNativeExpressClosed(object sender, EventArgs args) { this.nativeAdView = (NativeExpressAdView)sender; MyDebug.Log("GMAS::HandleOnNativeExpressClosed =>" + this.nativeAdView.adUnitId); if (this.OnNativeExperssAdClosed != null) { this.OnNativeExperssAdClosed.Invoke(this.nativeAdView.adUnitId); } this.RemoveNativeAd(nativeAdView); }
private void HandleOnNativeExpressFailedToLoad(object sender, AdFailedToLoadEventArgs args) { this.nativeAdView = (NativeExpressAdView)sender; this.nativeAdViews.Remove(this.nativeAdView.adUnitId); MyDebug.Log("GMAS::HandleOnNativeExpressFailedToLoad => " + this.nativeAdView.adUnitId + " - Message: " + args.Message); if (this.OnNativeExperssAdFailedToLoad != null) { this.OnNativeExperssAdFailedToLoad.Invoke(this.nativeAdView.adUnitId, ErrorCode.NotRequested + " - " + args.Message); } }
private void AutoCacheNativeAd(NativeExpressAdView adView) { if (adView.isFixedPostion) { this.RequestNativeExpress(adView.adUnitId, adView.adSize, adView.adPosition); } else { this.RequestNativeExpress(adView.adUnitId, adView.adSize, adView.x, adView.y); } }
private void RequestBanner() { #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-3804976617812716/4394413705"; #elif UNITY_IPHONE string adUnitId = "unused"; #else string adUnitId = "unexpected_platform"; #endif AdRequest adRequest = new AdRequest.Builder() .AddTestDevice("2645D5FFD3A4D7B1") .Build(); if (screenWidth <= 500) { bannerView = new NativeExpressAdView(adUnitId, new AdSize(280, 250), 10, 120); //SIZE MUST BE SAME AS ADMOB SIZE } else if (screenWidth <= 600) { bannerView = new NativeExpressAdView(adUnitId, new AdSize(280, 250), 40, 140); //SIZE MUST BE SAME AS ADMOB SIZE } else if (screenWidth <= 900) { bannerView = new NativeExpressAdView(adUnitId, new AdSize(280, 250), 40, 120 + (screenWidth / 16)); //SIZE MUST BE SAME AS ADMOB SIZE 40 + (screenWidth / 16) } else if (screenWidth <= 1100) { bannerView = new NativeExpressAdView(adUnitId, new AdSize(300, 300), 10 + (screenWidth / 20), 50 + (screenWidth / 14)); //1920 x 1080 } else if (screenWidth <= 1400) { bannerView = new NativeExpressAdView(adUnitId, new AdSize(340, 340), 42 + (screenWidth / 13), 120 + (screenWidth / 6)); //Nexus 7 } else if (screenWidth <= 1800) { bannerView = new NativeExpressAdView(adUnitId, new AdSize(340, 340), 15 + (screenWidth / 13), 50 + (screenWidth / 12)); //1440 x 2560 } else { bannerView = new NativeExpressAdView(adUnitId, new AdSize(340, 340), 42 + (screenWidth / 13), 120 + (screenWidth / 6)); //SIZE MUST BE SAME AS ADMOB SIZE } // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the banner with the request. bannerView.LoadAd(request); }
private void SetAdView() { var adContainer = view.FindViewById <Android.Widget.RelativeLayout>(Resource.Id.adContainer); var adView = new NativeExpressAdView(Context); adView.AdSize = new AdSize(AdSize.FullWidth, 150); adView.AdUnitId = "ca-app-pub-XXXXXXXXXXXXXXX"; adContainer.AddView(adView); adView.LoadAd(new AdRequest .Builder() .Build()); }
public void preloadNativeAd() { TotalData.LoadTotalFromFile(); if (TotalData.total.noAds) { // nativeExpressAdView.Hide (); } else { nativeExpressAdView = new NativeExpressAdView(adUnitId, AdSize.MediumRectangle, AdPosition.BottomRight); AdRequest request = new AdRequest.Builder().Build(); nativeExpressAdView.LoadAd(request); nativeExpressAdView.Hide(); } }
public void RequestNativeExpressAdView() { #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-3026969986215886/2601757351"; #elif UNITY_IOS || UNITY_IPHONE string adUnitId = "ca-app-pub-3026969986215886/5656546510"; #else string adUnitId = "unexpected_platform"; #endif float screenHeightInch = Screen.height / Screen.dpi; float screenWidthInch = Screen.width / Screen.dpi; int x = 30; int y = 300; if (screenHeightInch < 3f) { y = (int)(109f * screenHeightInch); } else { float temp = screenHeightInch - 3f; y = (int)(screenHeightInch * (110f - (temp * 6f))); } if (screenWidthInch < 2.5f) { x = (int)(15f * screenWidthInch); } else if (screenWidthInch < 3f) { x = (int)(25f * screenWidthInch); } else { float temp = screenWidthInch - 3f; x = (int)(screenWidthInch * (33f + temp)); } // Create a 320x50 native express ad at the top of the screen. nativeExpressAdView = new NativeExpressAdView(adUnitId, new AdSize(300, 80), x, y); // Load a banner ad. nativeExpressAdView.LoadAd(new AdRequest.Builder().Build()); }
private void RequestNativeExpressAdView() { #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-8920179393260755/9049692625"; #elif UNITY_IPHONE string adUnitId = "ca-app-pub-8920179393260755/9049692625"; #else string adUnitId = "unexpected_platform"; #endif // Create a 320x50 native express ad at the top of the screen. nativeExpressAdView = new NativeExpressAdView(adUnitId, new AdSize(320, 150), AdPosition.Top); // Load a banner ad. nativeExpressAdView.OnAdFailedToLoad += HandleOnAdFailedToLoad; nativeExpressAdView.LoadAd(new AdRequest.Builder().Build()); }
public void RequestNativeExpressAdView(String id) { nativeAndroidid = id; this.nativeExpressAdView = new NativeExpressAdView( nativeAndroidid, new AdSize(320, 150), AdPosition.Bottom); // Register for ad events. this.nativeExpressAdView.OnAdLoaded += this.HandleNativeExpressAdLoaded; this.nativeExpressAdView.OnAdFailedToLoad += this.HandleNativeExpresseAdFailedToLoad; this.nativeExpressAdView.OnAdOpening += this.HandleNativeExpressAdOpened; this.nativeExpressAdView.OnAdClosed += this.HandleNativeExpressAdClosed; this.nativeExpressAdView.OnAdLeavingApplication += this.HandleNativeExpressAdLeftApplication; // Load a native express ad. this.nativeExpressAdView.LoadAd(this.CreateAdRequest()); }
private void SetAdView() { adView = new NativeExpressAdView(AdSizeCons.GetFullWidthPortrait(150)); adView.AdUnitID = "ca-app-pub-XXXXXXXXXXXXXXX"; adView.RootViewController = ViewController; // The video options object can be used to control the initial mute state of video assets. // By default, they start muted. var videoOptions = new VideoOptions(); videoOptions.StartMuted = true; adView.SetAdOptions(new AdLoaderOptions[] { videoOptions }); View.AddSubview(adView); var request = Request.GetDefaultRequest(); //request.TestDevices = new[] { Request.SimulatorId.ToString() }; adView.LoadRequest(request); }
public override void SetupDialog(Dialog dialog, int style) { try { base.SetupDialog(dialog, style); //Get the content View View contentView = View.Inflate(this.Context, Resource.Layout.AdmobNative_Layout, null); dialog.SetContentView(contentView); //Set the coordinator layout behavior CoordinatorLayout.LayoutParams Params = (CoordinatorLayout.LayoutParams)((View)contentView.Parent).LayoutParameters; CoordinatorLayout.Behavior behavior = Params.Behavior; //Set callback if (behavior != null && behavior.GetType() == typeof(BottomSheetBehavior)) { ((BottomSheetBehavior)behavior).SetBottomSheetCallback(mBottomSheetBehaviorCallback); } string android_id = Android.Provider.Settings.Secure.GetString(this.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId); native = contentView.FindViewById <NativeExpressAdView>(Resource.Id.adViewNative); // Create an ad request. AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); // Optionally populate the ad request builder. adRequestBuilder.AddTestDevice(android_id); // Start loading the ad. native.LoadAd(adRequestBuilder.Build()); native.Visibility = ViewStates.Visible; } catch (Exception e) { Console.WriteLine(e); } }
// private void RemoveNativeAd(NativeExpressAdView adView) { this.nativeAdViews.Remove(adView.adUnitId); this.AutoCacheNativeAd(adView); }
void Start() { switch (PlayerPrefs.GetString("Mode")) { case "Easy": modeNumber = 0; tNumber = 32; break; case "Medium": modeNumber = 1; tNumber = 24; break; case "Hard": modeNumber = 2; tNumber = 16; break; case "Insane": modeNumber = 3; tNumber = 8; transform.GetChild(0).GetChild(4).GetChild(6).GetComponent <Text> ().text = " end"; break; } audioC.transform.GetChild(modeNumber).gameObject.SetActive(true); audioC.transform.GetChild(modeNumber).GetComponent <AudioSource> ().Play(); if (PlayerPrefs.GetString("Sound") == "on") { pauseScreen.transform.GetChild(5).GetChild(1).gameObject.SetActive(true); pauseScreen.transform.GetChild(5).GetChild(2).gameObject.SetActive(false); } else { pauseScreen.transform.GetChild(5).GetChild(1).gameObject.SetActive(false); pauseScreen.transform.GetChild(5).GetChild(2).gameObject.SetActive(true); } if (PlayerPrefs.GetString("Music") == "on") { pauseScreen.transform.GetChild(4).GetChild(1).gameObject.SetActive(true); pauseScreen.transform.GetChild(4).GetChild(2).gameObject.SetActive(false); Firebase.Analytics.FirebaseAnalytics.LogEvent("start_game_with_music"); } else { pauseScreen.transform.GetChild(4).GetChild(1).gameObject.SetActive(false); pauseScreen.transform.GetChild(4).GetChild(2).gameObject.SetActive(true); audioC.transform.GetChild(modeNumber).GetComponent <AudioSource> ().Pause(); Firebase.Analytics.FirebaseAnalytics.LogEvent("start_game_without_music"); } fieldControlls = field.GetComponent <FieldControlls> (); PlayerPrefs.SetInt("Attempts" + PlayerPrefs.GetString("Mode"), PlayerPrefs.GetInt("Attempts" + PlayerPrefs.GetString("Mode")) + 1); timer.transform.GetChild(0).GetComponent <Text>().text = tNumber.ToString(); scoreText.text = "0"; recordText.text = PlayerPrefs.GetInt("BestScore" + PlayerPrefs.GetString("Mode")).ToString(); progressColor.GetComponent <Image> ().color = modeColors [modeNumber]; transform.GetChild(0).GetChild(0).GetChild(1).GetComponent <Text> ().color = modeColors [modeNumber]; transform.GetChild(0).GetChild(1).GetChild(1).GetComponent <Text> ().color = modeColors [modeNumber]; transform.GetChild(0).GetChild(1).GetChild(2).GetComponent <Text> ().color = modeColors [modeNumber]; transform.GetChild(0).GetChild(2).GetChild(1).GetComponent <Text> ().color = modeColors [modeNumber]; transform.GetChild(0).GetChild(3).GetChild(1).GetComponent <Text> ().color = modeColors [modeNumber]; transform.GetChild(1).GetComponent <Image> ().color = modeColors [modeNumber]; transform.GetChild(2).GetComponent <Image> ().color = modeColors [modeNumber]; transform.GetChild(3).GetChild(0).GetChild(0).GetComponent <Text> ().color = modeColors [modeNumber]; loseScreen.transform.GetChild(2).GetComponent <Text> ().color = modeColors [modeNumber] - new Color(0, 0, 0, 1); worldRecordText.color = modeColors [modeNumber] - new Color(0, 0, 0, 1); barLength = fieldControlls.GetFullScore(); timer.transform.GetChild(0).GetComponent <Text>().color = modeColors [modeNumber]; for (int i = 1; i < 9; i++) { timer.transform.GetChild(i).GetComponent <Image> ().color = modeColors [modeNumber]; } StartCoroutine(StartCellsAnimations()); if (UnityEngine.Random.Range(0, 2) == 0) { banner = new BannerView(adBannerId, AdSize.SmartBanner, AdPosition.Bottom); banner.LoadAd(new AdRequest.Builder().Build()); } else { banner2 = new NativeExpressAdView(adBanner2Id, AdSize.SmartBanner, AdPosition.Bottom); banner2.LoadAd(new AdRequest.Builder().Build()); } inter = new InterstitialAd(adInterId); inter.LoadAd(new AdRequest.Builder().Build()); /*inter2 = RewardBasedVideoAd.Instance; * inter2.LoadAd (new AdRequest.Builder ().Build (), adInter2Id); */ Firebase.Analytics.FirebaseAnalytics.LogEvent("start_game_" + PlayerPrefs.GetString("Mode")); Firebase.Analytics.FirebaseAnalytics.LogEvent("start_game_all_modes"); }
/// <summary> /// Loads a banner advert into memory. /// </summary> /// <param name="AdType">Admob banner ad type.</param> /// <param name="XPos">X placement position relative to top left</param> /// <param name="YPos">Y placement position relative to top left</param> /// <param name="DisplayImmediately">If set to <c>true</c> display immediately when it has finished loading.</param> public void LoadBanner(AdSize AdType, int XPos, int YPos, bool DisplayImmediately = false) { if (!EnableAdMob) { return; } // Get the name of the current method string MethodName = "LoadBanner"; DebugLog(MethodName + " called for " + AdType + " - DisplayImmediately: " + DisplayImmediately); // Update the state items (Values used to determine if the action in this method should be ran) ActionState[MethodName].UpdateItems(new List <bool>() { !BannerIsLoading, !BannerIsReady, !BannerIsVisible }); // Check if we can perform the action for the current method if (CanPerformAction(MethodName, ActionState[MethodName].items)) { // Mark the banner as loading BannerIsLoading = true; // If we want to display the banner as soon as it's loaded then mark the wanted visible variable as true BannerWantedVisible = DisplayImmediately; switch (BannerAdType) { case BannerAdTypeList.Default: // Load a banner ad marking it as hidden, this script will handle showing the banner AdMobBanner = new BannerView(BannerId, AdType, XPos, YPos); // Register the banner ad events AdMobBanner.OnAdLoaded += OnReceiveBanner; AdMobBanner.OnAdFailedToLoad += OnFailReceiveBanner; AdMobBanner.OnAdOpening += OnBannerVisible; AdMobBanner.OnAdClosed += OnBannerHidden; AdMobBanner.OnAdLeavingApplication += OnBannerClick; AdMobBanner.LoadAd(GenerateAdRequest()); break; case BannerAdTypeList.NativeExpressAds: // Load a native banner ad marking it as hidden, this script will handle showing the banner AdMobNativeBanner = new NativeExpressAdView(BannerId, AdType, XPos, YPos); // Register the native banner ad events AdMobNativeBanner.OnAdLoaded += OnReceiveBanner; AdMobNativeBanner.OnAdFailedToLoad += OnFailReceiveBanner; AdMobNativeBanner.OnAdOpening += OnBannerVisible; AdMobNativeBanner.OnAdClosed += OnBannerHidden; AdMobNativeBanner.OnAdLeavingApplication += OnBannerClick; AdMobNativeBanner.LoadAd(GenerateAdRequest()); break; } BannerInMemoryType = AdType; BannerInMemoryLayout = AdPosition.TopLeft; } else { // Google Mobile Ads does not currently support banner repositioning so we are forced to treat new positions as changing to a new banner type (destroying and reloading the advert) DestroyBanner(); LoadBanner(AdType, XPos, YPos, DisplayImmediately); } }