I’m Facing a problem with adView.Show(100); cannot align it to the bottom of the screen. I tries put inside UI Canves element align to the bottom and make adView.Show(0); but it’s align to the top of the screen not of the parent element. tried also adView.Show(canves.rect.height - 50); it’s appear on my phone screen good but on other screen totally in wrong position.
Hi Senshi,
sorry i thought it’s a popular ad network maybe anyone face the same issue but it appears known using it.
here is the full code that facebook provide. my problem with the show method that take float datatype for example this.adView.Show (0); mean the top of the screen i tried to but this object in Ui Panal that aligned to the bottom of the screen but no success. I keep trying with no success. Sometimes i could align it to the bottom of my phone but in different screen size it’s not at the bottom at all.
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using AudienceNetwork;
public class AdViewTest : MonoBehaviour {
private AdView adView;
void Awake () {
// Create a banner's ad view with a unique placement ID (generate your own on the Facebook app settings).
// Use different ID for each ad placement in your app.
AdView adView = new AdView ("YOUR_PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);
this.adView = adView;
this.adView.Register (this.gameObject);
// Set delegates to get notified on changes or when the user interacts with the ad.
this.adView.AdViewDidLoad = (delegate() {
Debug.Log("Ad view loaded.");
this.adView.Show (100);
});
adView.AdViewDidFailWithError = (delegate(string error) {
Debug.Log("Ad view failed to load with error: " + error);
});
adView.AdViewWillLogImpression = (delegate() {
Debug.Log("Ad view logged impression.");
});
adView.AdViewDidClick = (delegate() {
Debug.Log("Ad view clicked.");
});
// Initiate a request to load an ad.
adView.LoadAd ();
}
void OnDestroy () {
// Dispose of banner ad when the scene is destroyed
if (this.adView) {
this.adView.Dispose ();
}
Debug.Log("AdViewTest was destroyed!");
}
// Next button
public void NextScene () {
Application.LoadLevel ("NativeAdScene");
}
}
Ah, ok! I’ve personally never used Audience Network, so I didn’t recognize it. The problem is I don’t know how adView.Show() works exactly; what the value means. However, I can make an educated guess, in that it’s an absolute size/ offset in pixels. Here’s something I came accross Googling, as well as another idea. Maybe try these and see how they behave?
//all assuming a 50px high ad
adView.Show(AdUtility.height() - 50);
adView.Show(Camera.main.pixelRect.height - 50);
adView.Show(canvas.rect.height - 50); //set "canvas" to your scene's canvas
If these don’t work, could you link me to an Audience Network API/ script reference please, so I can take a closer look?
As a by-the-way: this.adView = adView; is unnecessary. Since there’s no adView variable created in the local scope (Awake()), you can just use adView and it will refer to the one defined in your class.
Hi Senshi,
I really tried all those examples and I believe two of them are from my post on the stackoverflow but this is from 9 days ago i tried lot more from this time . this.adView = adView; this is included in their example and I don’t really know why.
you can find their sdk with a simple example in the following link
inside the zip file you will find a file named “AudienceNetwork.unitypackage”.
Hi, I’m terribly sorry, but I’ve been busy lately and haven’t had a chance to look at it, and I’m not sure when I will. I’ll keep an eye on this post though when I get some time and motivation. Hoping someone else will see this topic too now.
Here is a fix after two days of debugging, it’s about logical resolution being different for iOS when using Screen.Height
And AdUtility.height() is broken for android.
In addition to khoacng’s comment, you can also use the AdUtility.convert() too.
double height = AudienceNetwork.Utility.AdUtility.convert(Screen.height);
this.adView.Show(height - 50);