目录
概述
Chartboost SDK 的委托和配置方法让您可以对集成具备高度控制。例如,您可以:
- 在您的游戏试图加载插页式广告时记录调试信息
- 阻止在用户第一次运行游戏时显示广告
- 明确用户是点击广告抑或只是点击“关闭” — 然后据此进行不同操作
- 阻止插页式广告或“更多应用”页面在可能干扰您的游戏的时间或位置出现
您可以在 Chartboost.cs 文件中找到可供您使用的 Chartboost Unity SDK 方法 (可在已导入 Unity 插件文件中找到 (Chartboost > Scripts > Chartboost.cs)。实施方法示例请见 ChartboostExample.cs 文件 (Chartboost > Examples > ChartboostExample.cs),该文件在您的 SDK 下载所包括的示例场景中。
SDK 配置方法
这些方法让您可以访问 Chartboost SDK 功能和设置:
// 在指定 CBLocation 检查已缓存插页式广告。public static bool hasInterstitial(CBLocation location)// 在指定 CBLocation 检查已缓存“更多应用”页面。public static bool hasMoreApps(CBLocation location) // 在指定 CBLocation 检查已缓存激励式视频。public static bool hasRewardedVideo(CBLocation location)// 检查是否有任何视图可见public static bool isAnyViewVisible()// 设置以启用或禁用自动缓存功能 (默认启用)。*public static void setAutoCacheAds(bool autoCacheAds)// 获取当前自动缓存行为 (默认启用)。*public static bool getAutoCacheAds()// 设置 POST 正文发送的自定义标识符,用于所有 Chartboost API 服务器请求。public static void setCustomId(String customId)// 获取当前 POST 正文发送的自定义标识符,用于所有 Chartboost API 服务器请求。public static String getCustomId()// 判断 Chartboost SDK 是否应该在首次会话展示插页式广告。public static void setShouldRequestInterstitialsInFirstSession(bool shouldRequest)// 判断 Chartboost SDK 在准备显示“更多应用”界面时是否显示加载视图。public static void setShouldDisplayLoadingViewForMoreApps(bool shouldDisplay)// 判断 Chartboost SDK 是否尝试从 Chartboost API 服务器抓取视频。public static void setShouldPrefetchVideoContent(bool shouldPrefetch)// 用以控制全屏广告单元和状态栏的互动。(默认 CBStatusBarBehaviorIgnore)。// 仅限 iOSpublic static void setStatusBarBehavior(CBStatusBarBehavior statusBarBehavior)
* 您可以在此了解常规 AutoCacheAds 设置和广告缓存。)
SDK 委托安装
Chartboost Unity SDK 使用 C# 样式委托和事件以实现委托功能。使用任何委托方法之前,您应先依照示范在 MonoBehaviour 中订阅相关 SDK 事件:
void OnEnable() {// 侦听所有展示相关事件 Chartboost.didFailToLoadInterstitial += didFailToLoadInterstitial; Chartboost.didDismissInterstitial += didDismissInterstitial; Chartboost.didCloseInterstitial += didCloseInterstitial; Chartboost.didClickInterstitial += didClickInterstitial; Chartboost.didCacheInterstitial += didCacheInterstitial; Chartboost.shouldDisplayInterstitial += shouldDisplayInterstitial; Chartboost.didDisplayInterstitial += didDisplayInterstitial; Chartboost.didFailToLoadMoreApps += didFailToLoadMoreApps; Chartboost.didDismissMoreApps += didDismissMoreApps; Chartboost.didCloseMoreApps += didCloseMoreApps; Chartboost.didClickMoreApps += didClickMoreApps; Chartboost.didCacheMoreApps += didCacheMoreApps; Chartboost.shouldDisplayMoreApps += shouldDisplayMoreApps; Chartboost.didDisplayMoreApps += didDisplayMoreApps; Chartboost.didFailToRecordClick += didFailToRecordClick; Chartboost.didFailToLoadRewardedVideo += didFailToLoadRewardedVideo; Chartboost.didDismissRewardedVideo += didDismissRewardedVideo; Chartboost.didCloseRewardedVideo += didCloseRewardedVideo; Chartboost.didClickRewardedVideo += didClickRewardedVideo; Chartboost.didCacheRewardedVideo += didCacheRewardedVideo; Chartboost.shouldDisplayRewardedVideo += shouldDisplayRewardedVideo; Chartboost.didCompleteRewardedVideo += didCompleteRewardedVideo; Chartboost.didDisplayRewardedVideo += didDisplayRewardedVideo; Chartboost.didCacheInPlay += didCacheInPlay; Chartboost.didFailToLoadInPlay += didFailToLoadInPlay; Chartboost.didPauseClickForConfirmation += didPauseClickForConfirmation; Chartboost.willDisplayVideo += willDisplayVideo; #if UNITY_IPHONE Chartboost.didCompleteAppStoreSheetFlow += didCompleteAppStoreSheetFlow; #endif}
您还应确保在合适的情况下取消订阅相同事件:
void OnDisable() {// 移除事件处理程序 Chartboost.didFailToLoadInterstitial -= didFailToLoadInterstitial; Chartboost.didDismissInterstitial -= didDismissInterstitial; Chartboost.didCloseInterstitial -= didCloseInterstitial; Chartboost.didClickInterstitial -= didClickInterstitial; Chartboost.didCacheInterstitial -= didCacheInterstitial; Chartboost.shouldDisplayInterstitial -= shouldDisplayInterstitial; Chartboost.didDisplayInterstitial -= didDisplayInterstitial; Chartboost.didFailToLoadMoreApps -= didFailToLoadMoreApps; Chartboost.didDismissMoreApps -= didDismissMoreApps; Chartboost.didCloseMoreApps -= didCloseMoreApps; Chartboost.didClickMoreApps -= didClickMoreApps; Chartboost.didCacheMoreApps -= didCacheMoreApps; Chartboost.shouldDisplayMoreApps -= shouldDisplayMoreApps; Chartboost.didDisplayMoreApps -= didDisplayMoreApps; Chartboost.didFailToRecordClick -= didFailToRecordClick; Chartboost.didFailToLoadRewardedVideo -= didFailToLoadRewardedVideo; Chartboost.didDismissRewardedVideo -= didDismissRewardedVideo; Chartboost.didCloseRewardedVideo -= didCloseRewardedVideo; Chartboost.didClickRewardedVideo -= didClickRewardedVideo; Chartboost.didCacheRewardedVideo -= didCacheRewardedVideo; Chartboost.shouldDisplayRewardedVideo -= shouldDisplayRewardedVideo; Chartboost.didCompleteRewardedVideo -= didCompleteRewardedVideo; Chartboost.didDisplayRewardedVideo -= didDisplayRewardedVideo; Chartboost.didCacheInPlay -= didCacheInPlay; Chartboost.didFailToLoadInPlay -= didFailToLoadInPlay; Chartboost.didPauseClickForConfirmation -= didPauseClickForConfirmation; Chartboost.willDisplayVideo -= willDisplayVideo; #if UNITY_IPHONE Chartboost.didCompleteAppStoreSheetFlow -= didCompleteAppStoreSheetFlow; #endif}
您可以随意订阅上方所有事件,或只订阅您需要的事件。然后继续实施相关委托方法以处理每项事件的响应。
静态和视频插页式广告委托方法
// 插页式广告在屏上显示前调用。bool shouldDisplayInterstitial(CBLocation location)// 插页式广告在屏上显示后调用。void didDisplayInterstitial(CBLocation location)// 在插页式广告从 Chartboost API 服务器加载// 并且本地缓存后调用。void didCacheInterstitial(CBLocation location)// 在插页式广告尝试从 Chartboost API 服务器加载// 但失败后调用。void didFailToLoadInterstitial(CBLocation location, CBImpressionError error)// 插页式广告消除后调用。void didDismissInterstitial(CBLocation location)// 插页式广告关闭后调用。void didCloseInterstitial(CBLocation location)// 插页式广告点击后调用。didClickInterstitial(CBLocation location)
“更多应用”委托方法
// “更多应用”页面在屏上显示前调用。bool shouldDisplayMoreApps(CBLocation location)// “更多应用”页面在屏上显示后调用。void didDisplayMoreApps(CBLocation location)// 在“更多应用”页面从 Chartboost API 服务器加载// 并且本地缓存后调用。void didCacheMoreApps(CBLocation location)// “更多应用”页面消除后调用。void didDismissMoreApps(CBLocation location)// “更多应用”页面关闭后调用。void didCloseMoreApps(CBLocation location)// “更多应用”页面点击后调用。void didClickMoreApps(CBLocation location)// 在“更多应用”页面尝试从 Chartboost API 服务器加载// 但失败后调用。void didFailToLoadMoreApps(CBLocation location, CBImpressionError error)
激励式视频委托方法
(有关 Chartboost 视频的更多信息,参见此页。)
// 激励式视频在屏上显示前调用。bool shouldDisplayRewardedVideo(CBLocation location)// 激励式视频在屏上显示后调用。void didDisplayRewardedVideo(CBLocation location)// 在激励式视频从 Chartboost API 服务器加载// 并且本地缓存后调用。void didCacheRewardedVideo(CBLocation location)// 在激励式视频尝试从 Chartboost API 服务器加载// 但失败后调用。void didFailToLoadRewardedVideo(CBLocation location, CBImpressionError error)// 激励式视频消除后调用。void didDismissRewardedVideo(CBLocation location)// 激励式视频关闭后调用。void didCloseRewardedVideo(CBLocation location)// 激励式视频点击后调用。void didClickRewardedVideo(CBLocation location)// 在激励式视频观看完毕,用户可获得奖励时调用void didCompleteRewardedVideo(CBLocation location, int reward)// 实施后会进行通知,如果视频将于 // 指定 CBLocation 的屏幕上播放。您可以接着进行关闭音乐和音效等操作。void willDisplayVideo(CBLocation location)
其他委托方法
// App Store 工作表消除后,显示内嵌应用工作表时调用。// 仅限 iOSvoid didCompleteAppStoreSheetFlow()// 在点击发生后而用户未转至 App Store 时调用void didFailToRecordClick(CBLocation location, CBImpressionError error)//SDK 成功初始化,视频预提取完成后调用。void didInitialize(bool status)
原生广告委托方法
// 在原生广告对象从 Chartboost API 服务器加载// 并且本地缓存后调用。void didCacheInPlay(CBLocation location)// 在原生广告尝试从 Chartboost API 服务器加载// 但失败后调用。void didFailToLoadInPlay(CBLocation location, CBImpressionError error)
年龄限制方法
// 判断 Chartboost SDK 是否使用年龄限制进行阻拦。public static void setShouldPauseClickForConfirmation(bool shouldPause)// 在 Chartboost SDK 暂停点击操作,等待用户确认时调用。使用// 在您的游戏中实施年龄限制。void didPauseClickForConfirmation()// 确认年龄显示是否通过。指定 Chartboost 在等待本调用多长时间 // 方可展示 iOS App Store 商店。public static void didPassAgeGate(bool pass)