【发布时间】:2014-06-25 07:37:43
【问题描述】:
我希望在 Unity 中集成 admob 插页式广告,我这样做是为了横幅,但无法找到插页式广告的最终解决方案,任何帮助将不胜感激。
我绑定了以下链接,但它不适用于插页式广告 https://github.com/googleads/googleads-mobile-plugins
请不要推荐任何付费插件如 Prime31 等。
【问题讨论】:
标签: unity3d admob ads interstitial
我希望在 Unity 中集成 admob 插页式广告,我这样做是为了横幅,但无法找到插页式广告的最终解决方案,任何帮助将不胜感激。
我绑定了以下链接,但它不适用于插页式广告 https://github.com/googleads/googleads-mobile-plugins
请不要推荐任何付费插件如 Prime31 等。
【问题讨论】:
标签: unity3d admob ads interstitial
你可以从谷歌开发者页面here下载unity包
【讨论】:
如果免费插件不能满足您的需求,您将不得不编写自己的原生插件或在 Asset Store 上购买。但是,该插件的自述文件说它支持插页式广告。尝试按照自述文件中的说明进行操作。如果您已经尝试过但没有成功,请告诉我们具体出了什么问题。
这是创建插页式广告的最少横幅代码。
using GoogleMobileAds.Api;
...
// Initialize an InterstitialAd.
InterstitialAd interstitial = new InterstitialAd("MY_AD_UNIT_ID");
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the interstitial with the request.
interstitial.LoadAd(request);
与横幅不同,插页式广告需要明确显示。在应用中的适当停止点,检查插页式广告在显示之前是否准备就绪:
if (interstitial.IsLoaded()) {
interstitial.Show();
}
【讨论】:
我在我的安卓游戏中使用了 AdMob 的完成 Unity 包,你可以在这里找到它:http://forum.unity3d.com/threads/admob-unity-package-that-work-with-unity-3-2-above.173292
确保遍历整个线程,因为它需要一些调整才能使其与较新的统一版本完美配合。
关于应用发布者 ID 的小帮助 - 在线程中查找 page7。
【讨论】:
试试https://github.com/unity-plugins/Unity-Admob. 我用这个成功了。
而且代码更简单。
using UnityEngine;
using System.Collections;
using admob;
public class admobdemo : MonoBehaviour {
// Use this for initialization
void Start () {
Admob.Instance().bannerEventHandler += onBannerEvent;
Admob.Instance().interstitialEventHandler += onInterstitialEvent;
}
// Update is called once per frame
void Update () {
}
void OnGUI(){
if (GUI.Button (new Rect (0, 0, 100, 60), "initadmob")) {
Admob ad = Admob.Instance();
#if UNITY_IOS
ad.initAdmob("ca-app-pub-27960454450664210/xxxxxxxxx", "ca-app-pub-279343530664210/xxxxxxxxxxx");
#else
ad.initAdmob("ca-app-pub-27960454450664210/xxxxxxxxx", "ca-app-pub-279343530664210/xxxxxxxxxxx");
#endif
// ad.setTesting(true);
}
if (GUI.Button(new Rect(120, 0, 100, 60), "showfull"))
{
Admob ad = Admob.Instance();
if (ad.isInterstitialReady())
{
ad.showInterstitial();
}
else
{
ad.loadInterstitial();
}
}
if (GUI.Button(new Rect(240, 100, 100, 60), "showbanner"))
{
Admob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);
}
if (GUI.Button(new Rect(240, 200, 100, 60), "showbannerABS"))
{
Admob.Instance().showBannerAbsolute(AdSize.Banner, 0, 30);
}
if (GUI.Button(new Rect(240, 300, 100, 60), "hidebanner"))
{
Admob.Instance().removeBanner();
}
}
void onInterstitialEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobEvent---" + eventName + " " + msg);
if (eventName == AdmobEvent.onAdLoaded)
{
Admob.Instance().showInterstitial();
}
}
void onBannerEvent(string eventName, string msg)
{
Debug.Log("handler onAdmobBannerEvent---" + eventName + " " + msg);
}
}
【讨论】:
Here你去。 Google 的官方 Unity 插件,他们有横幅和插页式广告的代码示例。
【讨论】: