统一广告,谁控制它们显示的频率,我还是广告插件?
unity ads, who controls how often they will be shown, me or Advertisement plugin?
我已经实施了 Unity Ads 并且:
void Start()
{
Advertisement.Show();
}
在连接到我的统一广告GameObject的脚本中。
当我测试我的游戏时,当场景加载时会显示一个广告(这是一个显示游戏会话结果的场景),这就是我想要的,但我认为每次都显示广告并不好单次加载此场景,因为它会经常加载。后台是否有某种算法决定是否应显示广告?
我认为应该对在 x 时间内可以显示的广告数量有某种限制,不仅仅是统一,而且在一般广告中,这就是为什么我认为它可能已经内置了。
所以,我的问题是,我应该这样保留它,让广告插件来工作,还是应该添加某种随机发生器,例如:
int number = Random.Range(1, 2);
if (number == 1) {
Advertisement.Show();
}
大约 50% 的时间展示广告?
完全公开,几天前我也在统一论坛上问过这个问题,但尚未获得批准(因此未发布),可能会删除那个。
Disclaimer: I have no experience whatsoever with the Unity Ads
framework.
根据Unity团队的blog post,我想说一个简单的解决方案可以是检查场景上次加载时是否显示广告,并根据情况显示新的一个或什么都不做。
我们可以分两步完成:
- 创建静态 class 以跟踪显示广告的时间。
- 根据静态class的值判断你的场景是否满足显示新的条件,并更新
例如:
public static class AdvertisementTracker
{
/// Create a property or method to store and retrieve whether
/// an advertisement was shown at a given time.
/// You can use a bool, datetime, IList<DateTime> or whatever property that you need.
public static bool AdShown = false;
public static DateTime LastTimeShown;
public static IList<DateTime> TimesShown = new List<DateTime>();
/// You can even have a method that takes the elapsed time between calls and check
/// if they meet the criteria you wish to show your ads.
public static bool ElapsedTimeConditionMet(float elapsedTime)
{
// For example, the elapsed time exceeds 40 seconds, so a new add can be shown.
return elapsedTime >= 40.0f;
}
}
然后,在您的场景中,将以下脚本附加到您的广告对象:
using UnityEngine;
using UnityEngine.Advertisements;
using System.Collections;
public class SimpleAdScript : MonoBehaviour
{
void Start()
{
Advertisement.Initialize("<the ad ID>", true);
StartCoroutine(ShowAdWhenReady());
}
IEnumerator ShowAdWhenReady()
{
while (!Advertisement.isReady())
yield return null;
if(!AdvertisementTracker.AdShown)
{
Advertisement.Show();
}
AdvertisementTracker.AdShown = !AdvertisementTracker.AdShown;
}
}
脚本的 objective 用于检查广告是否已从 Unity 框架准备好。
如果是,它会检查上次是否展示了广告。如果不是这种情况,则会显示它,否则会更新静态 class 以为下一次迭代做好准备。
我已经实施了 Unity Ads 并且:
void Start()
{
Advertisement.Show();
}
在连接到我的统一广告GameObject的脚本中。
当我测试我的游戏时,当场景加载时会显示一个广告(这是一个显示游戏会话结果的场景),这就是我想要的,但我认为每次都显示广告并不好单次加载此场景,因为它会经常加载。后台是否有某种算法决定是否应显示广告?
我认为应该对在 x 时间内可以显示的广告数量有某种限制,不仅仅是统一,而且在一般广告中,这就是为什么我认为它可能已经内置了。
所以,我的问题是,我应该这样保留它,让广告插件来工作,还是应该添加某种随机发生器,例如:
int number = Random.Range(1, 2);
if (number == 1) {
Advertisement.Show();
}
大约 50% 的时间展示广告?
完全公开,几天前我也在统一论坛上问过这个问题,但尚未获得批准(因此未发布),可能会删除那个。
Disclaimer: I have no experience whatsoever with the Unity Ads framework.
根据Unity团队的blog post,我想说一个简单的解决方案可以是检查场景上次加载时是否显示广告,并根据情况显示新的一个或什么都不做。
我们可以分两步完成:
- 创建静态 class 以跟踪显示广告的时间。
- 根据静态class的值判断你的场景是否满足显示新的条件,并更新
例如:
public static class AdvertisementTracker
{
/// Create a property or method to store and retrieve whether
/// an advertisement was shown at a given time.
/// You can use a bool, datetime, IList<DateTime> or whatever property that you need.
public static bool AdShown = false;
public static DateTime LastTimeShown;
public static IList<DateTime> TimesShown = new List<DateTime>();
/// You can even have a method that takes the elapsed time between calls and check
/// if they meet the criteria you wish to show your ads.
public static bool ElapsedTimeConditionMet(float elapsedTime)
{
// For example, the elapsed time exceeds 40 seconds, so a new add can be shown.
return elapsedTime >= 40.0f;
}
}
然后,在您的场景中,将以下脚本附加到您的广告对象:
using UnityEngine;
using UnityEngine.Advertisements;
using System.Collections;
public class SimpleAdScript : MonoBehaviour
{
void Start()
{
Advertisement.Initialize("<the ad ID>", true);
StartCoroutine(ShowAdWhenReady());
}
IEnumerator ShowAdWhenReady()
{
while (!Advertisement.isReady())
yield return null;
if(!AdvertisementTracker.AdShown)
{
Advertisement.Show();
}
AdvertisementTracker.AdShown = !AdvertisementTracker.AdShown;
}
}
脚本的 objective 用于检查广告是否已从 Unity 框架准备好。 如果是,它会检查上次是否展示了广告。如果不是这种情况,则会显示它,否则会更新静态 class 以为下一次迭代做好准备。