Unity
Adkit for AD(X): Unity¶
AdKit 是一个广告模块,修复了在处理 AD(X) Unity 包时发生的错误,并支持用户便利。逐一阅读此页面,以便使用 AdKit 以及支持 SDK。
安装¶
访问 Hive 开发者并下载和应用 AdKit。
- 从 Hive 开发者处下载最新版本的 AdKit 并在 这里 解压缩。
- 在 Unity 工具栏中,选择 .unitypackage 文件,路径为 Assets > Import Package > Custom Package…,然后点击 Import。
- 导入完成后,检查Assets文件夹下是否创建了与AdKit和AD(X)相关的文件和文件夹。
Warning
在开发期间测试 AdKit 时,您必须应用测试广告密钥。
更新¶
卸载您正在使用的AdKit并安装最新版本以进行更新。
如何使用¶
iOS(Unity 2019.4 及以上版本){ #apply-ios }¶
使用 Unity 2019.4 及以上版本构建 iOS 项目时,会生成以 Dynamic Framework 方式运行的 UnityFramework target。
-
配置 EDM4U。 在 Unity 的 iOS Resolver Settings(Assets > External Dependency Manager > iOS Resolver > Settings)中检查 static_framework 构建设置(Link frameworks statically)。
Facebook SDK 仅提供 Dynamic Framework,而 Podfile 只能选择两种框架方式中的一种。因此,启用 Link frameworks statically 并使用 Facebook SDK 时,请取消注释下面对应的项目。 string[] frameworksToEmbed = { ... "FBAudienceNetwork.xcframework", // 使用 Facebook SDK 时,请取消注释正在使用的 SDK。 // "FBAEMKit.xcframework", // ... };Warning
- 仅取消注释当前使用的 Facebook SDK。
- 禁用 Link frameworks statically 时,如果在使用 Dynamic Framework 的情况下取消注释,可能会发生冲突。
-
构建项目。
Warning
生成 Xcode 项目时如果
pod install失败,并且已在上面启用 Link frameworks statically,请不要在生成的项目路径中直接运行pod install,而应在 Unity Editor 中重新构建项目。
特性¶
- 激励广告
- 同时使用AdKit API和SDK或使用独立模块时,是否发送日志信息取决于调用的RewardVideo API。日志信息将发送到Analytics服务器。支持此功能的最低版本如下:
- SDK v4.11.0
- SDK v1.17.2
- 独立模块 ModuleManager v2.6.0
- 独立模块 CommonModule v1.5.0
- 同时使用AdKit API和SDK或使用独立模块时,是否发送日志信息取决于调用的RewardVideo API。日志信息将发送到Analytics服务器。支持此功能的最低版本如下:
- 插页式广告
- 自适应横幅广告
有关如何使用 AdKit 的详细信息,请阅读以下指南。
初始化 AdKit¶
初始化、加载和显示所有类型广告(AD)之前的必要步骤
欧洲和英国目标¶
如果您的游戏面向欧洲和英国(欧洲经济区和英国),则需要显示GDPR(通用数据保护条例)同意弹窗。Adkit支持Google的UMP(用户消息平台)来显示GDPR同意弹窗。要使用Google UMP,请首先参考GDPR消息创建指南来撰写您的GDPR消息。
使用Hive SDK时,AuthV4.setup会暴露IDFA消息,因此构建IDFA消息在根本上是可选的。然而,如果您使用GDPR消息,则必须根据关于IDFA消息和ATT通知的详细说明来构建IDFA消息。
如果您已经制作了GDPR消息和IDFA消息,请使用如下所示的InitializeWithShowADXConsent初始化Hive AdKit。
Important
如果您正在使用Hive SDK,则必须在完成Hive AdKit的初始化后执行AuthV4.setup。如果在显示ATT(应用跟踪透明度)同意通知后出现GDPR同意屏幕,您的应用可能会在苹果的应用审核中被拒绝。
// When targeting Europe & the UK for commercial distribution
int debugState = 0;
HIVEAdKit.InitializeWithShowADXConsent(appId, debugState, null, adkitConsentState =>
{
/*
* adkitConsentState : User's personal information usage and collection status for AD(X)
* - 0 : No consent status exists
* - 1 : Region where consent is not required
* - 2 : User has refused the usage and collection of personal information
* - 3 : User has consented to the usage and collection of personal information
*/
});
/*
* To test the GDPR consent popup, set debugState to 1 and configure testDeviceId to display the GDPR test popup.
* The device ID for the Test Device (testDeviceId) can be found in the Android Logcat and Xcode console logs.
* The testDeviceId is used only for testing. You must specify testDeviceId as null during commercial distribution.
* Example Android log: Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("ABCDEFGHIJKLMNOPQRSTUVWXYZ") to set this as a debug device.
* Example Xcode log: To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[ABCDEFGHIJKLMNOPQRSTUVWXYZ]
*/
int debugState = 1;
string testDeviceId = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
List testDevices = new List();
testDevices.Add(testDeviceId);
HIVEAdKit.InitializeWithShowADXConsent(appId, debugState, testDevices, adkitConsentState =>
{
/*
* adkitConsentState : User's personal information usage and collection status for AD(X)
* - 0 : No consent status exists
* - 1 : Region where consent is not required
* - 2 : User has refused the usage and collection of personal information
* - 3 : User has consented to the usage and collection of personal information
*/
});
在初始化 Hive AdKit 时,如果目标区域被确定为欧洲和英国(EEA 和英国),将自动显示 GDPR 同意屏幕,如下所示。
在iOS环境中,IDFA解释消息会在欧洲和英国以外的地区自动显示。
定位其他地区¶
定位欧洲和英国以外的地区时,请使用 InitializeWithSetConsentState 进行初始化。
/*
* Set the user's personal information usage and collection status for AD(X)
* 0 : No consent status exists
* 1 : Region where consent is not required
* 2 : User has refused the usage and collection of personal information
* 3 : User has consented to the usage and collection of personal information
*/
int consentState = 1;
HIVEAdKit.InitializeWithSetConsentState(appId, consentState);
高级设置¶
// GameData Example
[Serializable]
public class SendInfo
{
public int level;
public int gold;
}
SendInfo addtionalInfo = new SendInfo();
addtionalInfo.level = 1;
addtionalInfo.gold = 100;
// Send as a JSON Obejct format
HIVEAdKit.SetAdditionalInfo(JsonUtility.ToJson(addtionalInfo));
奖励类型¶
// Initialize Rewarded AD
// Initialize Rewarded AD
EventHandlers eventHandlers = new EventHandlers.Builder()
.OnAdLoaded(OnAdLoadedCB)
.OnAdOpening(OnAdOpeningCB)
.OnAdClosed(OnAdClosedCB)
.OnAdFailedToLoad(OnAdFailedToLoadCB)
.OnAdFailedToShow(OnAdFailedToShowCB)
.OnAdReward(OnAdRewardCB)
.OnPaidEvent(OnPaidEventCB)
.Build();
// Generate an instance
RewardVideoAd = HIVEAdKit.RewardVideo.Initialize(rewardVideoUnitId, eventHandlers);
// Load Rewarded AD
// Send AD loading information to Analytics
if( HIVEAdKit.RewardVideo.IsInitialzed(RewardVideoAd) ) {
HIVEAdKit.RewardVideo.LoadAd(RewardVideoAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}
// Show RewardVideo type
// Send AD loading information to Analytics
if( HIVEAdKit.RewardVideo.IsLoaded(RewardVideoAd) ) {
HIVEAdKit.RewardVideo.Show(RewardVideoAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}
插页类型¶
EventHandlers eventHandlers = new EventHandlers.Builder()
.OnAdLoaded(OnAdLoadedCB)
.OnAdOpening(OnAdOpeningCB)
.OnAdClosed(OnAdClosedCB)
.OnAdFailedToLoad(OnAdFailedToLoadCB)
.OnAdClick(OnAdClickCB)
.OnPaidEvent(OnPaidEventCB)
.Build();
// Generate an instance
InterstitialAd = HIVEAdKit.Interstitial.Initialize(InterstitialAdUnitId, eventHandlers);
// Load
// Send AD loading information to Analytics
if( HIVEAdKit.Interstitial.IsInitialzed(InterstitialAd) ) {
HIVEAdKit.Interstitial.Load(InterstitialAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}
// Show
// Send AD loading information to Analytics
if( HIVEAdKit.Interstitial.IsLoaded(InterstitialAd) ) {
HIVEAdKit.Interstitial.Show(InterstitialAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
}
自适应横幅类型¶
EventHandlers eventHandlers = new EventHandlers.Builder()
.OnAdLoaded(OnBannerAdLoadedCB)
.OnAdOpening(OnAdOpeningCB)
.OnAdClosed(OnAdClosedCB)
.OnAdFailedToLoad(OnAdFailedToLoadCB)
.OnAdClick(OnAdClickCB)
.OnPaidEvent(OnPaidEventCB)
.Build();
HIVEAdKit.AdaptiveBanner.AdPosition bannerPosition = HIVEAdKit.AdaptiveBanner.AdPosition.Top;
HIVEAdKit.AdaptiveBanner.AdSize adaptiveSize = HIVEAdKit.AdaptiveBanner.AdSize.AD_SIZE_320x50;
// Generate an instance
AdaptiveBannerAd = HIVEAdKit.AdaptiveBanner.Initialize(AdaptiveBannerAdUnitId, adaptiveSize, bannerPosition, eventHandlers);
// Load and show
// Send AD loading information to Analytics
HIVEAdKit.AdaptiveBanner.LoadAd(AdaptiveBannerAd, "Unity-AdaptiveBanner-Show-AdditionalInfo");
// Hide
HIVEAdKit.AdaptiveBanner.Destroy(AdaptiveBannerAd);
支持 iOS 14¶
以下是支持 iOS 14 及更高版本的 SKAdNetwork AD(X) 列表。AdKitPostprocess 基于 2021 年 1 月 29 日的更新。别忘了查看最新更新。
支持 Android 11¶
一个标签 <queries> 被添加到 AD(X) 库的 AndroidManifest.xml 文件中,以支持 Android 11。如果您在 Unity 中构建项目时查看以下错误日志,请参考与 Unity-Android 11 构建的指南。
- Unity上的示例错误日志
AndroidManifest.xml: AAPT: error: unexpected element <queries> found in <manifest>.
- 使用Unity构建Android 11的指南
ADX Proguard 设置¶
库 AAR 文件包含 Proguard 的规则,因此设置会自动执行。
Unity 集成通知
¶如果在 GoogleMobileAdsSettings 上删除了应用程序 ID,请转到 Unity > Assets > Google Mobile Ads > Settings,然后选择 延迟应用程序测量 复选框,然后再次清除它。 
测试广告¶
在开发过程中,广告商在测试广告被点击时不被收费是很重要的。如果您在测试模式之外点击广告过多,这将被视为无效行为。因此,请注意不要成为被举报的目标账户。请参考Google 开发者以使用测试广告。
错误代码¶
有关广告加载失败时的代码和消息,请参阅AD(X)的Ad Error。
卸载¶
要卸载 AdKit for AD(X),请删除以下文件和文件夹列表。
-
- 与 AdKit 相关
- /Assets/HIVEAdKit
- /Assets/HIVEAdKit_Example
- 与 AD(X) 相关
- /Assets/ADXLibrary
- /Assets/GoogleMobileAds
- /Assets/Plugins/Android/GoogleMobileAdsPlugins
- 与 AdKit 相关
Note
与 AD(X) 相关的文件列表可能会根据 AdKit 中包含的 AD(X) 版本而有所不同。





