如何统一隐藏亚马逊广告
How to hide amazon ads in unity
所以我将亚马逊移动广告整合到我的 unity/ios 项目中。每次场景发生变化时,我都会将其全部用于隐藏广告的位置。每次我打开一个场景,广告都会显示。所以一切都很好,除非你真的很快改变场景。我不希望在主游戏中出现广告,因为它会阻碍用户的视线。每次进入重试场景时,如果您在广告加载前快速从该场景切换,该广告将卡在下一个场景中,从而使另一个广告显示在它上面。每次场景更改时,无论您更改场景的速度有多快,它都应该隐藏广告。如果显示广告,有什么方法可以确保它隐藏广告?我正在使用以下代码:
void Start() {
mobileAds = AmazonMobileAdsImpl.Instance;
ApplicationKey key = new ApplicationKey();
key.StringValue = iosKey;
mobileAds.SetApplicationKey(key);
ShouldEnable enable = new ShouldEnable();
enable.BooleanValue = true;
mobileAds.EnableTesting(enable);
mobileAds.EnableLogging(enable);
Placement placement = new Placement();
placement.Dock = Dock.BOTTOM;
placement.HorizontalAlign = HorizontalAlign.CENTER;
placement.AdFit = AdFit.FIT_AD_SIZE;
response = mobileAds.CreateFloatingBannerAd(placement);
string adType = response.AdType.ToString();
long identifer = response.Identifier;
newResponse = mobileAds.LoadAndShowFloatingBannerAd(response);
bool loadingStarted = newResponse.BooleanValue;
}
void OnDestroy() {
mobileAds.CloseFloatingBannerAd(response);
response = null;
mobileAds = null;
newResponse = null;
}
您是什么时候下载Unity插件的?在插件的早期版本中有一些问题,这听起来像(整个,一个广告加载在另一个东西之上)。如果您最近没有更新,请尝试从亚马逊下载最新版本,看看问题是否仍然存在。
关闭广告API
mobileAds.CloseFloatingBannerAd(response);
仅当广告已加载时才有效。您需要注册广告加载事件。如果场景被破坏,那么您将在广告加载事件触发时关闭广告。
您可以按如下方式注册AdLoaded
活动,Documentation
using com.amazon.mas.cpt.ads;
bool sceneDestroyed = false; //tracks if scene is destroyed
//Obtain object used to interact with the plugin
IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
// Define event handler
private void EventHandler(Ad args)
{
if (sceneDestroyed)
{
mobileAds.CloseFloatingBannerAd(response);
}
else
{
//Do some other job
}
}
//Register for an event
mobileAds.AddAdLoadedListener(EventHandler);
void OnDestroy()
{
sceneDestroyed = true;
}
所以我将亚马逊移动广告整合到我的 unity/ios 项目中。每次场景发生变化时,我都会将其全部用于隐藏广告的位置。每次我打开一个场景,广告都会显示。所以一切都很好,除非你真的很快改变场景。我不希望在主游戏中出现广告,因为它会阻碍用户的视线。每次进入重试场景时,如果您在广告加载前快速从该场景切换,该广告将卡在下一个场景中,从而使另一个广告显示在它上面。每次场景更改时,无论您更改场景的速度有多快,它都应该隐藏广告。如果显示广告,有什么方法可以确保它隐藏广告?我正在使用以下代码:
void Start() {
mobileAds = AmazonMobileAdsImpl.Instance;
ApplicationKey key = new ApplicationKey();
key.StringValue = iosKey;
mobileAds.SetApplicationKey(key);
ShouldEnable enable = new ShouldEnable();
enable.BooleanValue = true;
mobileAds.EnableTesting(enable);
mobileAds.EnableLogging(enable);
Placement placement = new Placement();
placement.Dock = Dock.BOTTOM;
placement.HorizontalAlign = HorizontalAlign.CENTER;
placement.AdFit = AdFit.FIT_AD_SIZE;
response = mobileAds.CreateFloatingBannerAd(placement);
string adType = response.AdType.ToString();
long identifer = response.Identifier;
newResponse = mobileAds.LoadAndShowFloatingBannerAd(response);
bool loadingStarted = newResponse.BooleanValue;
}
void OnDestroy() {
mobileAds.CloseFloatingBannerAd(response);
response = null;
mobileAds = null;
newResponse = null;
}
您是什么时候下载Unity插件的?在插件的早期版本中有一些问题,这听起来像(整个,一个广告加载在另一个东西之上)。如果您最近没有更新,请尝试从亚马逊下载最新版本,看看问题是否仍然存在。
关闭广告API
mobileAds.CloseFloatingBannerAd(response);
仅当广告已加载时才有效。您需要注册广告加载事件。如果场景被破坏,那么您将在广告加载事件触发时关闭广告。
您可以按如下方式注册AdLoaded
活动,Documentation
using com.amazon.mas.cpt.ads;
bool sceneDestroyed = false; //tracks if scene is destroyed
//Obtain object used to interact with the plugin
IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
// Define event handler
private void EventHandler(Ad args)
{
if (sceneDestroyed)
{
mobileAds.CloseFloatingBannerAd(response);
}
else
{
//Do some other job
}
}
//Register for an event
mobileAds.AddAdLoadedListener(EventHandler);
void OnDestroy()
{
sceneDestroyed = true;
}