横幅广告
Banner Ads
1. 接口API说明
API Description
1.1 横幅广告请求类 br/>Banner Ad Request Class
Request
| 属性成员 Attribute members | 说明 illustrate |
|---|---|
| PlacementId | 广告位 Advertising space |
| UserId | 媒体用户体系ID ,可选 ,默认null Media user system ID, optional, default null |
| options | 扩展参数,默认null Extension parameters, default is null |
1.2 横幅广告对象类
Banner Ad Object Class
BannerAd
| 方法 method | 说明 illustrate |
|---|---|
| BannerAd(Request request) | 初始化横幅广告对象,request 为广告请求对象,必传 Initialize the banner ad object. Request is the ad request object |
| SetBannerAdListener(IBannerAdListener listener) | 设置横幅广告接口回调 Set banner ad interface callback |
| LoadAd() | 发起广告加 Initiate advertising |
| Ready() | 判断当前BannerAd是否存在可展示的广告 Determine whether there is an ad that can be displayed in the current BannerAd |
| HideAd() | 隐藏当前广告 Hide current ad |
| ShowAd() | 展示广告 Display ads |
| String PlacementId | 广告对象使用的广告位 Ad slots used by the ad object |
| Dispose() | 销毁并关闭广告 Destroy and close ads |
| AdInfo GetAdInfo() | 获取广告信息AdInfo对象,成功播放回调后获取有效 Get the AdInfo object for advertising information. After successful playback, get the valid |
| List<AdInfo> GetCacheAdInfoList() | 查询当前广告位的所有缓存信息的AdInfo对象、在广告加载成功后调用。 Query the AdInfo object of all cached information of the current ad slot and call it after the ad is loaded successfully. |
1.3 横幅广告回调说明
Banner Ad Callback Description
IBannerAdListener 横幅广告回调说明
IBannerAdListener banner ad callback description
| 回调方法 Callback Methods | 说明 illustrate |
|---|---|
| OnAdError (BannerAd ad, Error error) | 广告加载失败 Ad loading failed |
| OnAdLoad (BannerAd ad) | 广告加载成功 Ad loaded successfully |
| OnAdShow (BannerAd ad) | 广告开始展示 Ad starts showing |
| OnAdClick (BannerAd ad) | 广告被用户点击 The ad is clicked by the user |
| OnAdClose (BannerAd ad) | 广告展示关闭 Ad display off |
| OnAdAutoRefreshed (BannerAd ad) | 自动刷新广告成功 Automatically refresh ads successfully |
| OnAdAutoRefreshFail (BannerAd ad,Error error) | 自动刷新广告失败 Automatic refresh of ads failed |
2. 示例代码
Sample Code
2.1 创建横幅广告对象
Create a banner ad object
C#
Request request = new Request();
request.PlacementId = <广告位ID>;
request.UserId = "unity_user_1";
BannerAd bannerAd = new BannerAd(request);2.1 设置监听回调
Setting the listener callback
C#
private sealed class BannerAdListener : IBannerAdListener
{
public BannerAdListener()
{
}
public void OnAdClick(BannerAd ad)
{
Debug.Log("SigmobUnityPlugin -- OnAdClick ---- " + ad.PlacementId);
}
public void OnAdClose(BannerAd ad)
{
Debug.Log("SigmobUnityPlugin -- OnAdClose ---- " + ad.PlacementId);
ad.Dispose();
}
public void OnAdShow(BannerAd ad)
{
Debug.Log("SigmobUnityPlugin -- OnAdShow ---- " + ad.PlacementId);
Debug.Log("SigmobUnityPlugin -- getAdInfo ---- " + ad.GetAdInfo().ToString());
}
public void OnAdError(BannerAd ad, Error error)
{
Debug.Log("SigmobUnityPlugin -- OnAdError ---- " + ad.PlacementId + ", error -- " + error.ToString());
}
public void OnAdLoad(BannerAd ad)
{
Debug.Log("SigmobUnityPlugin -- OnAdLoad ---- " + ad.PlacementId);
}
public void OnAdAutoRefreshed(BannerAd ad)
{
Debug.Log("SigmobUnityPlugin -- OnAdAutoRefreshed ---- " + ad.PlacementId);
}
public void OnAdAutoRefreshFail(BannerAd ad, Error error)
{
Debug.Log("SigmobUnityPlugin -- OnAdAutoRefreshFail ---- " + ad.PlacementId);
}
}
bannerAd.SetBannerAdListener(new BannerAdListener());2.2 横幅广告加载
Banner ad loading
C#
bannerAd.LoadAd();2.3 横幅广告播放
Banner Ad Playback
C#
if(bannerAd.Ready()){
float ratio = 320 / 50.0f;
int wdith = Screen.width;
int height =(int) (wdith / ratio);
int x = Screen.width > wdith ? (Screen.width - wdith) / 2 : 0;
int y = Screen.height - height-50;
bannerAd.ShowAd(new Rect(x, y, wdith,height));
}