Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
Hello World v.2

Senior Member
Registered:
Posts: 238
Reply with quote  #1 
Hey guys

At the moment im looking for for a solution to simulate smartbanners inside the unity editor, so i can fit the UI of my new game to a smart banner (Smart banners are google play banners who scale for the full width of the screen size, they using something called density-independent pixels to scale the ad, wich means they not scale like the unity canvas i think)


I want to show the ad-space with a GUI.Box , but i cant get it to scale like on the device with the "px = dp * (Screen.dpi/ 160)" formular wich i found on the internet, because if i use Debug.Log(Screen.dpi) it always shows 96, no matter what screen size i emulate.

So i startet trying the to get the Adsize with AdSize.Smartbanner.Height:

using GoogleMobileAds.Api;

....

int Height = AdSize.SmartBanner.Height;
GUI.Box(new Rect(0, 0, Screen.width, Height), "Admob Banner");


...


The problem is that AdSize.SmartBanner.Height always gives me 0 and i dont know how to attach the ad to it :/

I really want to have something like this because banners are normally take more space of the screen on a small device then on a larger one and i think that with all the canvas scaling the AD Banner could overlap with the UI on small devices. (wich would hide the score in my game, making it unplayable on small devices)


Does anyone of you know an answer or have a better workaround for this ?
Would be cool if someone could help me [smile]
0
XdebugX

Avatar / Picture

Registered:
Posts: 374
Reply with quote  #2 
It's pretty easy to get the ad size of a smart banner. I've been doing it for adjusting my canvas for a while now. Use:

AdSize.SMART_BANNER.getHeightInPixels(this); //for size in pixels

or

AdSize.SMART_BANNER.getHeight(this); //for size in DPI


The reason AdSize.SmartBanner.Height is returning zero for you is probably because the view hasn't been created yet. But getHeight() works without the view having to be created first.

The "this" parameter is your activity context. Not sure if you have access to that in Unity or not, I haven't used Unity.
0
Hello World v.2

Senior Member
Registered:
Posts: 238
Reply with quote  #3 
In unity it always says that SMART_BANNER isnt there :/
0
XdebugX

Avatar / Picture

Registered:
Posts: 374
Reply with quote  #4 
It may have to do with the plugin your using. Have you tried the official admob plugin? https://github.com/googleads/googleads-mobile-unity/releases/tag/v3.0.1

And the integration guide: https://developers.google.com/admob/android/games#unity_plugin_api
0
Hello World v.2

Senior Member
Registered:
Posts: 238
Reply with quote  #5 
Yes and still i do something wrong, could you post your example code pls ? : )
0
XdebugX

Avatar / Picture

Registered:
Posts: 374
Reply with quote  #6 
I'm not using Unity, so my code is for the native Admob SDK. It's as simple as:

int adHeight = AdSize.SMART_BANNER.getHeightInPixels(this);

in my main activity onCreate().

I'm thinking maybe smart banners are not available in the Unity plugin. I was looking at the Unity guide https://developers.google.com/admob/android/games#unity_plugin_api and it says you can set the size of the banner yourself. So maybe you should try setting the custom height of the banner, then of course you would know what size it would be.

Custom ad sizes

Instead of using an AdSize constant, you can specify a custom size for your ad.

AdSize adSize =newAdSize(250,250);
BannerView bannerView =newBannerView(adUnitId, adSize,AdPosition.Bottom);
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.