Baidu Unity Plugin provides a way to integrate baidu ads in Unity3D Game and u3d app. You can use it for Unity iOS and Android App with the same c# or js code. Unity Baidu Plugin features include:
- A single package with cross platform (Android/iOS) support
- Support for Baidu Banner Ads
- Support for Baidu Interstitial Ads
- Support all Baidu native events
- A sample project to demonstrate plugin integration
- Very simple API
BaiduUnityPlugin.unitypackage is the plugin file for those that want to easily import ,baidudemo.cs is a simple demo file how to use this plugin.
Baidu iOS SDK 4.3 ,android sdk 4.3
- Open your project in the Unity editor.
- Navigate to Assets -> Import Package -> Custom Package.
- Select the BaiduUnityPlugin.unitypackage file.
- Import all of the files for the plugins by selecting Import. Make sure to check for any conflicts with files.
To build and run on Android, click File -> Build Settings, select the Android platform, then Switch Platform, then Build and Run.
To build and run on iOS, click File -> Build Settings, select the iOS platform, then Switch Platform, then Build. This will export an XCode project. You'll need to do the following before you can run it: Add the following framework to xcode project
AdSupport.framework,CoreTelephony.framework,StoreKit.framework,MessageUI.framework,Security.framework
- copy baidudemo.cs to your unity project/assets dic
- attach baidudemo.cs to the main camera
- set the baidu id in baidudemo.cs
- build and run this in your device
The remainder of this guide assumes you are now attempting to write your own code to integrate Mobile Ads into your game.
Here is the minimal code needed to create a banner.
using baidu;
...
Baidu.Instance().initBaidu("app id", "banner id", "institial id", "video id");//id is got from ssp.baidu.com
Baidu.Instance().showBannerRelative(AdSize.Banner, AdPosition.BOTTOM_CENTER, 0);
The AdPosition class specifies where to place the banner. AdSize specifies witch size banner to show
Here is the minimal banner code to create an interstitial.
using baidu;
...
Baidu.Instance().initBaidu("app id", "banner id", "institial id", "video id");//initBaidu just need call once,if you called when create banner ,you not need call any more
Baidu.Instance().loadInterstitial();
Unlike banners, interstitials need to be explicitly shown. At an appropriate stopping point in your app, check that the interstitail is ready before showing it:
if (Baidu.Instance().isInterstitialReady()) {
Baidu.Instance().showInterstitial();
}
The following constants list the available ad positions:
AdPosition.TOP_LEFT
AdPosition.TOP_CENTER
AdPosition.TOP_RIGHT
AdPosition.MIDDLE_LEFT
AdPosition.MIDDLE_CENTER
AdPosition.MIDDLE_RIGHT
AdPosition.BOTTOM_LEFT
AdPosition.BOTTOM_CENTER
AdPosition.BOTTOM_RIGHT
Both Banner and Interstitial contain the same ad events that you can register for. Here we'll demonstrate setting ad events on a interstitial,and show interstitial when load success:
using baidu;
...
Baidu.Instance().interstitialEventHandler += onInterstitialEvent;
...
void onInterstitialEvent(string eventName, string msg)
{
Debug.Log("handler onBaiduEvent---" + eventName + " " + msg);
if (eventName == BaiduEvent.onAdLoaded)
{
Baidu.Instance().showInterstitial();
}
}
You only need to register for the events you care about. you can handler banner and video event as follow
Baidu.Instance().interstitialEventHandler += onInterstitialEvent;
Baidu.Instance().videoEventHandler += onVideoEvent;
By default, banners are visible. To temporarily hide a banner, call:
Baidu.Instance().removeBanner();
- Baidu
- Baidu Unity Plugin Home
- qq group 532855630