如何让Android Unity C#Revmob广告显示在屏幕顶部而不是底部

时间:2015-08-24 21:23:52

标签: c# android unity3d banner revmob

标题说明了一切,现在广告(默认情况下)位于屏幕的底部,我希望它们位于顶部。这是SDK 9.0.0。

我不知道这个剧本是否重要,但是在触发时会激活。

	public void cargarBanner()
	{
		#if UNITY_EDITOR
		Debug.Log("cargarBanner Revmob.");
		#elif UNITY_ANDROID
		revmob.CreateBanner (RevMob.Position.TOP, 0, 0, Screen.width, 55);
		//revmob.CreateBanner();
		#endif
		//revmob.CreateBanner (RevMob.Position.TOP, 0, 0, Screen.width, 55);
	}

RevMobAndroidBanner

using UnityEngine;
using System;
using System.Runtime.InteropServices;

#if UNITY_ANDROID
public class RevMobAndroidBanner : RevMobBanner {
	private AndroidJavaObject javaObject;

	public RevMobAndroidBanner(AndroidJavaObject activity, AndroidJavaObject listener, RevMob.Position position, int x, int y, int w, int h, AndroidJavaObject session) {
		this.javaObject = session;
		this.javaObject.Call("createBanner", activity, listener, (int)position, x, y, w, h);
	}
	
	public override void Show() {
		Debug.Log("BCRS showBanner");
		this.javaObject.Call("showBanner");
    }

    public override void Hide() {
		Debug.Log("BCRS hideBanner");
		this.javaObject.Call("hideBanner");
    }

	public override void Release() {
		Debug.Log("BCRS releaseBanner");
		this.javaObject.Call("releaseBanner");
	}
}
#endif

RevMobAndroid

using UnityEngine;
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;


#if UNITY_ANDROID
public class RevMobAndroid : RevMob {
	private AndroidJavaObject session;

	public RevMobAndroid(string appId, string gameObjectName) {
		this.gameObjectName = gameObjectName;
		AndroidJavaClass unityRevMobClass = new AndroidJavaClass("com.revmob.unity.UnityRevMob");
		this.session = unityRevMobClass.CallStatic<AndroidJavaObject>("start",
	                                                               RevMobAndroid.CurrentActivity(),
	                                                               appId,
	                                                               "unity-android",
	                                                               REVMOB_VERSION,
                                                                 new AndroidJavaObject("com.revmob.unity.RevMobAdsUnityListener", gameObjectName, "session"));
	}


	public static AndroidJavaObject CurrentActivity() {
		AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
		return unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
	}

	public override bool IsDevice() {
		return (Application.platform == RuntimePlatform.Android);
	}  
      
  private AndroidJavaObject adUnitWrapperCall(string methodName, string placementId, string adUnit) {
		if (placementId == null) {
			placementId = "";
		}
		AndroidJavaObject publisherListener = CreateRevMobListener(this.gameObjectName, adUnit);
		AndroidJavaObject obj = this.session.Call<AndroidJavaObject>(methodName, CurrentActivity(), placementId, publisherListener);
		return obj;
	}

	private AndroidJavaObject CreateRevMobListener(String gameObjectName, String adUnityType) {
		return new AndroidJavaObject("com.revmob.unity.RevMobAdsUnityListener", gameObjectName, adUnityType);
	}

	public override void PrintEnvironmentInformation() {
		session.Call("printEnvironmentInformation", CurrentActivity());
	}

	public override void SetTestingMode(RevMob.Test test) {
		session.Call("setTestingMode", (int)test);
	}

	public override void SetTimeoutInSeconds(int timeout) {
		session.Call("setTimeoutInSeconds", timeout);
	}

	public override RevMobFullscreen ShowFullscreen(string placementId) {
		return new RevMobAndroidFullscreen(this.adUnitWrapperCall("showFullscreen", placementId, "Fullscreen"));
	}

	public override RevMobFullscreen CreateFullscreen(string placementId) {
		if (!IsDevice ()) return null;
		AndroidJavaObject javaObject = this.adUnitWrapperCall("createFullscreen", placementId, "Fullscreen");
		return new RevMobAndroidFullscreen(javaObject);
	}

	public override RevMobFullscreen CreateVideo(string placementId) {
		if (!IsDevice ()) return null;
		AndroidJavaObject javaObject = this.adUnitWrapperCall("createVideo", placementId, "Fullscreen");
		return new RevMobAndroidFullscreen(javaObject);
	}

	public override RevMobFullscreen CreateRewardedVideo(string placementId) {
		if (!IsDevice ()) return null;
		AndroidJavaObject javaObject = this.adUnitWrapperCall("createRewardedVideo", placementId, "Fullscreen");
		return new RevMobAndroidFullscreen(javaObject);
	}

	public override RevMobBanner CreateBanner(RevMob.Position position, int x, int y, int w, int h) {
		return (IsDevice()) ? new RevMobAndroidBanner(CurrentActivity(), CreateRevMobListener(this.gameObjectName, "Banner"), position, x, y, w, h, session) : null;
	}

	public override void ShowBanner(RevMob.Position position, int x, int y, int w, int h) {
		if (!IsDevice ()) return;
		this.session.Call("showBanner", CurrentActivity(), CreateRevMobListener(this.gameObjectName, "Banner"), (int)position, x, y, w, h);
	}

	public override void HideBanner() {
		this.session.Call("hideBanner", CurrentActivity());
	}

	public override RevMobLink OpenLink(string placementId) {
		return new RevMobAndroidLink(this.adUnitWrapperCall("openLink", placementId, "Link"));
	}

	public override RevMobLink CreateLink(string placementId)	{
		if (!IsDevice ()) return null;
		AndroidJavaObject javaObject = this.adUnitWrapperCall("createLink", placementId, "Link");
		return new RevMobAndroidLink(javaObject);
	}



	public override RevMobPopup ShowPopup(string placementId) {
		return new RevMobAndroidPopup(this.adUnitWrapperCall("showPopup", placementId, "Popup"));
	}

	public override RevMobPopup CreatePopup(string placementId) {
		return new RevMobAndroidPopup(this.adUnitWrapperCall("createPopup", placementId, "Popup"));
	}
}
#endif

0 个答案:

没有答案