此为核心组件,不用显示安装,安装具体的广告平台组件(比如max,topon)时为作为依赖项自动安装
初始化也不需要显示调用,具体的广告平台组件初始化时会自动调用
Didabu广告插件有个默认的广告播放策略,如果不需要太复杂的广告播放策略,可以直接使用默认的广告播放策略,初始化一个实例,各参数的说明如下:
var adPlayingConfig = new DefaultAdPlayingStrategyConfiguration() //默认广告播放策略配置
{
RewardedMaxTimes = 60,//激励视频每天最大播放次数
AdUnits = new List<AdUnitConfiguration>
{
new AdUnitConfiguration //配置激励视频广告单元
{
AdType = Mogafa.Unity.AdPlaying.Core.AdType.Rewarded,//激励视频
AdUnitId = "YOUR_AD_UNIT_ID",//在广告平台上配置的激励视频广告单元ID
MaxTimesToPlay = 100,//每天最大播放次数
Priority =1,//优先级
},
new AdUnitConfiguration //配置插屏广告单元
{
AdType = Mogafa.Unity.AdPlaying.Core.AdType.Interstitial,//插屏
AdUnitId = "YOUR_AD_UNIT_ID",//在广告平台上配置的插屏广告单元ID
MaxTimesToPlay = 30, //每天最大播放次数
Priority = 1
}
},
//重试间隔列表,每次重试后间隔的时长,单位为毫秒
RetryIntervals = new List<int> { 5000, 10000, 12000, 15000 }
};
var adPlayingStrategy = new DefaultAdPlayingStrategy(adPlayingConfig); //默认广告播放策略
可以通过DidabuAdPlayingCallbacks设置全局的广告回调,比如:
//定义回调
DidabuAdPlayingCallbacks.OnRewardedVideoClosed += OnRewardedVideoClosed;
DidabuAdPlayingCallbacks.OnBannerClicked += OnBannerClicked;
针对激励视频,提供了以下两个方法:
//判断是否有加载成功的激励视频广告,其中placement指定广告位(广告用途,比如:回球、获取道具)
public static bool HasRewardedVideo(this Didabu didabu, string placement)
//展示激励视频,其中placement指定广告位(广告用途,比如:回球、获取道具)
//如果启用了广告事件上报,placement会附加在事件名称中上报,比如:
//Didaba.Application.ShowRewardedVideo("homepage");
//那么上报"ddb_purchase"事件时,同时也会上报"ddb_purchase_homepage"
//此方法如果有激励视频播放则会直接播放,并返回true,如果没有则直接返回false
//此设计可以实现如下场景:在播放广告页面,广告播放按钮一直可以点击,不需要先判断时候有加载好的视频
public static bool ShowRewardedVideo(this Didabu didabu, string placement)
针对插屏,提供了以下两个方法:
//判断是否有加载成功的激励视频广告,其中placement指定广告位(广告用途,比如:回球、获取道具
public static bool HasInterstitialVideo(this Didabu didabu, string placement)
/展示激励视频,其中placement指定广告位(广告用途,比如:回球、获取道具)
//如果启用了广告事件上报,placement会附加在事件名称中上报,比如:
//Didaba.Application.ShowRewardedVideo("homepage");
//那么上报"ddb_purchase"事件时,同时也会上报"ddb_purchase_homepage"
public static bool ShowInterstitialVideo(this Didabu didabu, string placement)
正对Banner,提供了以下两个方法:
//展示Banner
public static void ShowBanner(this Didabu didabu, string placement = "")
//隐藏Banner
public static void HideBanner(this Didabu didabu, string placement = "")
允许上报事件方法的签名如下:
public static Didabu EnableAdPlayingEvent(this Didabu didabu, params AdPlayingEnableEvents[] enableEvents)
比如允许记录广告点击事件代码如下:
Didabu.Application.EnableAdPlayingEvent(AdPlayingEnableEvents.RewardedVideoClicked,
AdPlayingEnableEvents.InterstitialVideoClicked,
AdPlayingEnableEvents.BannerClicked)
当然启用事件上报的时候也可以不指定允许事件的,SDK默认会上报ddb_purchase事件(并且此事件不能也不会被移除)
//不指定允许的事件,默认上报ddb_purchase事件
Didabu.Application.EnableAdPlayingEvent();
目前AdPlayingEnableEvents定义如下:
public enum AdPlayingEnableEvents
{
RewardedVideoClicked,
RewardedVideoRevenuePaid,
RewardedVideoClosed,
RewardedVideoCompleted,
RewardedVideoLoaded,
RewardedVideoLoadFailed,
RewardedVideoShowFailed,
RewardedVideoShown,
InterstitialVideoClicked,
InterstitialVideoDismissed,
InterstitialVideoRevenuePaid,
InterstitialVideoCompleted,
InterstitialVideoLoaded,
InterstitialVideoLoadFailed,
InterstitialVideoShowFailed,
InterstitialVideoShown,
BannerClicked,
BannerRevenuePaid,
BannerLoaded,
BannerLoadFailed
}
使用如下代码记录用户的广告行为:
Didabu.Application.EnableAdBehavior()
目前会记录用户点击广告次数、完成广告观看的次数。
只要实现指定的广告策略接口,就可以自定义广告播放策略:
public interface IAdPlayingStrategy
{
string StrategyName { get; }
string GetRewardedVideoAdUnitId(string placement);
string GetInterstitialVideoAdUnitId(string placement);
string GetBannerAdUnitId(string placement);
void SetRewardedVideoPlayer(IRewardedVideoPlayer rewardedVideoPlayer);
void SetInterstitialVideoPlayer(IInterstitialVideoPlayer interstitialVideoPlayer);
void SetBannerPlayer(IBannerPlayer bannerVideoPlayer);
}