【问题标题】:Chartboost ads not showing in Unity 3D GameChartboost 广告未在 Unity 3D 游戏中显示
【发布时间】:2016-03-30 12:08:19
【问题描述】:

我有一个简单的platformer game,我在其中使用 chartboost 和 unity ads 来显示广告,我在测试模式下运行良好,但自从我部署到生产环境并在 chartboost 和 unity 中禁用了测试模式广告 我注意到我的插页式广告和视频不会加载或显示,除非在同一游戏的蓝月亮中出现一次,然后它又开始失败。

我还注意到我的广告在 chartboost 和 Unity 上的印象非常低。你能告诉我我的代码是否正确吗?我使用了 chartboost 示例并通过它构建了我的广告控制器,哦,我正在为广告使用缓存,除非广告尚未缓存,否则我不会显示它。

代码如下:

    using UnityEngine;
    using System.Collections;
    using UnityEngine.Advertisements;
    using ChartboostSDK;
    using System;

    public class AdsController : MonoBehaviour
    {
         public static AdsController instance;

// app id for unity apps
private const string _appId = "someID";

public bool canShowChartBoostInterstitial;
public bool canShowChartBoostVideo;

private void Awake()
{
    MakeSingleton();

    if (!canShowChartBoostInterstitial)
    {
        LoadChartBoostInterstitialAds();
    }

    if (!canShowChartBoostVideo)
    {
        LoadChartBoostVideoAds();
    }

    LoadUnityAds();
}

private void MakeSingleton()
{
    if (instance != null)
    {
        Destroy(gameObject);
    }
    else
    {
        instance = this;
        DontDestroyOnLoad(gameObject);
    }
}

private void OnLevelWasLoaded()
{
    if (Application.loadedLevelName == "LevelMenu")
    {
        if (GameController.instance.canShowAds)
        {
            if (canShowChartBoostInterstitial)
            {
                ShowChartBoostInterstitial();
            }
            else
            {
                LoadChartBoostInterstitialAds();
            }
        }
    }
}

private void OnEnable()
{
    Chartboost.didCompleteRewardedVideo += VideoCompleted;
    Chartboost.didCacheInterstitial += DidCacheInterstitial;
    Chartboost.didDismissInterstitial += DidDismissInterstitial;
    Chartboost.didCloseInterstitial += DidCloseInterstitial;
    Chartboost.didCacheRewardedVideo += DidCacheVideo;
    Chartboost.didFailToLoadInterstitial += FailedToLoadInterstitial;
    Chartboost.didFailToLoadRewardedVideo += FailedToLoadVideo;
}

private void OnDisable()
{
    Chartboost.didCompleteRewardedVideo -= VideoCompleted;
    Chartboost.didCacheInterstitial -= DidCacheInterstitial;
    Chartboost.didDismissInterstitial -= DidDismissInterstitial;
    Chartboost.didCloseInterstitial -= DidCloseInterstitial;
    Chartboost.didCacheRewardedVideo -= DidCacheVideo;
    Chartboost.didFailToLoadInterstitial -= FailedToLoadInterstitial;
    Chartboost.didFailToLoadRewardedVideo -= FailedToLoadVideo;
}

public void VideoCompleted(CBLocation location, int reward)
{
    canShowChartBoostVideo = false;

    if (RewardController.instance != null)
    {
        RewardController.instance.VideoWatchedGiveUserAReward();
    }

    LoadChartBoostVideoAds();

}

public void DidCacheInterstitial(CBLocation location)
{
    canShowChartBoostInterstitial = true;
}

public void DidDismissInterstitial(CBLocation location)
{
    canShowChartBoostInterstitial = false;
    LoadChartBoostVideoAds();

    LoadChartBoostInterstitialAds();
}

public void DidCloseInterstitial(CBLocation location)
{
    canShowChartBoostInterstitial = false;
    LoadChartBoostVideoAds();

    LoadChartBoostInterstitialAds();
}

public void DidCacheVideo(CBLocation location)
{
    canShowChartBoostVideo = true;
}

private void FailedToLoadInterstitial(CBLocation location, CBImpressionError error)
{
    canShowChartBoostInterstitial = false;
    LoadChartBoostInterstitialAds();
}

private void FailedToLoadVideo(CBLocation location, CBImpressionError error)
{
    canShowChartBoostVideo = false;

    if (ShopMenuController.instance != null)
    {
        ShopMenuController.instance.FailedToLoadTheVideo();
    }

    LoadChartBoostVideoAds();
}

public void LoadChartBoostVideoAds()
{
    Chartboost.cacheRewardedVideo(CBLocation.Default);
}

public void LoadChartBoostInterstitialAds()
{
    Chartboost.cacheInterstitial(CBLocation.Default);
}

public void ShowChartBoostInterstitial()
{
    if (canShowChartBoostInterstitial)
    {
        Chartboost.showInterstitial(CBLocation.Default);            
    }
    else
    {
        LoadChartBoostInterstitialAds();
    }
}

public void ShowChartBoostVideo()
{
    if (canShowChartBoostVideo)
    {
        Chartboost.showRewardedVideo(CBLocation.Default);
    }
    else
    {
        LoadChartBoostVideoAds();
    }
}

public void LoadUnityAds()
{
    if (Advertisement.isSupported)
    {
        Advertisement.Initialize(_appId, false);
    }
}

public void ShowUnityAds()
{
    if (Advertisement.IsReady())
    {
        Advertisement.Show(null, new ShowOptions()
        {
            resultCallback = result =>
            {
                switch (result)
                {
                    case ShowResult.Finished:
                        GameController.instance.RewardPlayerWithSomething();
                        LoadUnityAds();
                        break;

                    case ShowResult.Failed:
                        GameController.instance.VideoNotLoadedOrUserSkippedTheVideo("Failed to load the video. Please try again.");
                        LoadUnityAds();
                        break;

                    case ShowResult.Skipped:
                        GameController.instance.VideoNotLoadedOrUserSkippedTheVideo("Video skipped.");
                        LoadUnityAds();
                        break;
                }
            }
        });
    }
    else
    {
        GameController.instance.VideoNotLoadedOrUserSkippedTheVideo("Failed to load the video. Please try again.");
        LoadUnityAds();
    }
}

 }

【问题讨论】:

    标签: c# android unity3d ads chartboost


    【解决方案1】:

    每次显示插页式广告后运行缓存。

    像这样:

       Chartboost.showInterstitial(CBLocation.Default); 
       Chartboost.cacheInterstitial(CBLocation.Default);
    

    这样您每次展示广告时都会补充缓存。

    记得在初始化后立即缓存。

    【讨论】:

      猜你喜欢
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2017-07-17
      • 1970-01-01
      相关资源
      最近更新 更多