Unity3d access in Android Admob advertising plug-ins Tutorial

A. Unity3d access in Android Admob advertising tutorial


Admob Mobile Ads SDK to download plug-ins  https://github.com/unity-plugins/Unity-Admob

Unity is AdmobUnityPlugin.unitypackage Admob plug master file directly into the project asset import Unity of lead into unity project
added Admob Unity plug into unity following steps
1. Open Unity Engineering
2. from a menu, Assets -> Import Package -> Package Penalty for Custom.
3. select the Unity plugin file AdmobUnityPlugin.unitypackage
4. select the import everything, the entire contents within admob unity plugins lead into unity project
5. confirm admobdemo.cs has been imported into the project, and if not, please plug from above admobdemo.cs copied to the project, and modify admobdemo.cs of Admob advertising ID
6. the admobdemo.cs often drag main camera or other objects in the scene
compile and run the project
select menu File -> Build Settings select Android platform, select the player settings set the platform properties, then click on the build
Wait a moment of time the application will be installed on computers linked to the android device, opening the device will be able to get results
Unity integration admob ad code notes Description

Admob.Instance().initAdmob("banner id", "institial id");//id is got from ssp.admob.comAdmob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);



The above game which is integrated in iOS Unity android and Unity admob banner
AdSize.Banner expressed ad size display, AdPosition.BOTTOM_CENTER showing the placement of banner, AdPosition ad slot which contains various constants, AdSize comprising respective ad size constant
relative position banner
the following are all supported admob banner constant relative position

AdPosition.TOP_LEFTAdPosition.TOP_CENTERAdPosition.TOP_RIGHTAdPosition.MIDDLE_LEFTAdPosition.MIDDLE_CENTERAdPosition.MIDDLE_RIGHTAdPosition.BOTTOM_LEFTAdPosition.BOTTOM_CENTERAdPosition.BOTTOM_RIGHT



The following is a table plaque integrated advertising Admob ads Unity applications inside?
Add admob advertising inside the code below Unity3d

Admob.Instance().initAdmob( "banner id", "institial id");//id is got from ssp.admob.comAdmob.Instance().loadInterstitial();



And banner ads, full screen ads need to be loaded, etc. After loading display ads at the right point in time

if (Admob.Instance().isInterstitialReady()) {Admob.Instance().showInterstitial();}



Admob移动广告广告事件处理
Admob横幅广告和全屏广告都有差不多的广告事件,你可以在unity3d里面监听并处理所有Admob移动广告事件
下面是一个处理全屏广告事件的例子,我们在收到广告的时候就展示广告

Admob.Instance().interstitialEventHandler += onInterstitialEvent;void onInterstitialEvent(string eventName, string msg){Debug.Log("handler onAdmobEvent---" + eventName + "   " + msg);if (eventName == AdmobEvent.onAdLoaded){Admob.Instance().showInterstitial();}}




二.Unity3d在IOS系统接入Admob广告教程


先下载Admob移动广告SDK插件 https://github.com/unity-plugins/Unity-Admob
AdmobUnityPlugin.unitypackage 是Admob Unity 插件主文件,直接通过Unity的asset import进项目导入导unity项目中

把Admob Unity插件添加进unity步骤如下
1. 打开Unity工程
2. 从菜单打开,Assets -> Import Package -> Custom Package.
3. 选中Unity插件文件AdmobUnityPlugin.unitypackage
4. 选择导入所有内容,把admob unity插件内全部内容导入导unity工程
5. 确认admobdemo.cs 已经导入到项目中,如果没有,请先从上面插件中复制admobdemo.cs 到工程,并修改admobdemo.cs中的Admob广告ID
6. 把admobdemo.cs 拖到main camera 或者其他常在场景中的物件上
8. 

编译运行工程项目
选择菜单File -> Build Settings 选择ios平台,选择player settings设置平台属性,然后点击build
Unity项目将会被导出为ios工程。
然后把GoogleMobileAds.framework复制到xcode工程并添加到framework清单中
为了顺利编译ios项目,你需要对xcode工程进行下面的修改设置,把下面的frame 添加至项目
    AdSupport.framework,EventKit.framework,EventKitUI.framework,CoreTelephony.framework,StoreKit.framework,MessageUI.framework

Unity 集成admob 广告代码注解说明
    
using admob;
Admob.Instance().initAdmob( "banner id", "institial id");//id is got from ssp.admob.com
Admob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);
上面是在Unity android和Unity iOS游戏里面集成admob横幅广告
AdSize.Banner表示展示的广告尺寸,AdPosition.BOTTOM_CENTER表示横幅的放置位置,AdPosition里面包含各个广告位置常量,AdSize包含各个广告尺寸常量


横幅广告相对位置
下面是所有支持的admob横幅广告相对位置常量
   



怎么在Unity应用里面集成Admob全屏广告?
下面的Unity3d里面添加admob广告的代码
    using admob;
    ...
    Admob.Instance().initAdmob("banner id", "institial id");//id is got from ssp.admob.com
    Admob.Instance().loadInterstitial(); 

和横幅广告不同,全屏广告需要先加载,等加载完成后在合适的时间点展示广告

    if (Admob.Instance().isInterstitialReady()) {
      Admob.Instance().showInterstitial();
    }


Admob横幅广告和全屏广告都有差不多的广告事件
你可以在unity3d里面监听并处理所有Admob移动广告事件
下面是一个处理全屏广告事件的例子,我们在收到广告的时候就展示广告


你只需要关注你想处理的广告事件,忽略掉不想关注的


默认横幅广告展示后就一直是可见的,如果想隐藏广告那可以通过下面的方式进行
Admob.Instance().removeBanner();

using admob;Admob.Instance().interstitialEventHandler += onInterstitialEvent;void onInterstitialEvent(string eventName, string msg){Debug.Log("handler onAdmobEvent---" + eventName + "   " + msg);if (eventName == AdmobEvent.onAdLoaded){Admob.Instance().showInterstitial();}}


AdPosition.TOP_LEFTAdPosition.TOP_CENTERAdPosition.TOP_RIGHTAdPosition.MIDDLE_LEFTAdPosition.MIDDLE_CENTERAdPosition.MIDDLE_RIGHTAdPosition.BOTTOM_LEFTAdPosition.BOTTOM_CENTERAdPosition.BOTTOM_RIGHT


using admob;Admob.Instance().initAdmob( "banner id", "institial id");//id is got from ssp.admob.comAdmob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);


using admob;Admob.Instance().initAdmob( "banner id", "institial id");//id is got from ssp.admob.comAdmob.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);


using admob;Admob.Instance().initAdmob( "banner id", "institial id");//id is got from ssp.admob.com


Guess you like

Origin blog.51cto.com/14757709/2480777