2016-03-30 69 views
0

我有一個簡單的platformer game,其中我使用了chartboost和unity ads t顯示廣告,並且它在測試模式下工作正常,但自從我部署到生產並禁用測試我注意到,我的插頁式廣告和視頻不會加載或顯示,除非曾經在藍色月亮中出現過一次相同的遊戲,然後再次開始失敗。Chartboost廣告在Unity 3D遊戲中不顯示

我也注意到我的廣告印象在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(); 
    } 
} 

} 

回答

0

運行緩存,每次當你展示插頁式廣告。

這樣的:

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

這樣,每次展示廣告時,您將補充緩存。

記得初始化時也要緩存。