介绍
这里对我之前写的广告接入组一个补充,之前文章之写了激励视频方式,今天拓展一下banner的接入,插件什么的就不继续写如何操作了,可以看我之前那个文章
banner
申请的地方和方式在下面图中创建新广告位即可(激励视频广告、banner广告、插屏广告),获得广告位ID
/// <summary>
/// banner视频
/// </summary>
/// <param name="adId">广告位id</param>
/// <param name="bS">样式</param>
/// <param name="IntervalTime">间隔时间必须大于等于30</param>
/// <param name="errCallBack">错误回调</param>
/// <param name="loadEdCallback">加载完成回调</param>
/// <param name="resizeCallBack">重新设置大小回调</param>
/// <param name="closeCallBack">关闭回调</param>
/// <returns></returns>
public BannerAd CreateBanner(string adId, BannerStyle bS, int IntervalTime, System.Action<int, string> errCallBack, System.Action loadEdCallback, System.Action<int, int> resizeCallBack, System.Action closeCallBack)
{
return starkAdManager.CreateBannerAd(adId, bS, IntervalTime, errCallBack, loadEdCallback, resizeCallBack, closeCallBack);
}
测试调用代码
private BannerAd ba = null;
private int px2dp(int px) => (int)(px * (160 / Screen.dpi));
/// <summary>
/// 调整位置和大小
/// </summary>
/// <param name="m_style"></param>
void changeStyle(BannerStyle m_style)
{
int w = m_style.width; //获取banner宽度大小
int h = m_style.height; //获取banner高度大小
int sw = px2dp(Screen.width); //获得屏幕宽度(dp)
int sh = px2dp(Screen.height); //获得屏幕高度(dp)
m_style.top = sh - h; //底部
m_style.left = sw / 2 - w / 2; //中央
m_style.width = w;
ba.ReSize(m_style); //使用Resize函数调整位置和大小
}
/// <summary>
/// 展示界面
/// </summary>
/// <returns></returns>
public override BasePanel Show()
{
Debug.LogError("展示界面");
BannerStyle bs = new BannerStyle();
bs.left = 0;
bs.top = 0;
bs.width = Screen.width;//高度是根据视频大小定的所以没法设置高度
ba = ByteGameAdManager.Instance.CreateBanner("3gnda6hd1hd44g8pli", bs, 30, (v, s) =>
{
Debug.LogError("v = " + v + ",s = " + s);
}, () =>
{
Debug.LogError("加载出来");
if (ba != null) ba.Show();
}, (v1, v2) =>
{
Debug.LogError("v1 = " + v1 + ",v2 = " + v2);
}, () =>
{
Debug.LogError("关闭");
});
return this;
}
总结
感谢大家的支持