C# 未显示Unity AdMob广告
我正在Unity 5.5上制作一个游戏,我已经将AdMob集成到我的游戏中,目前仅在iOS上,但Android也将在我完成这项工作后跟进 我已经在AdMob控制台上设置了我的游戏,并创建了一个基于奖励的视频广告。 我已经将GoogleMobileAds.framework添加到我在Xcode中构建的项目中。 我已经确定我正在链接新添加的框架。 下载Unity软件包并根据需要将其集成到我的项目中。 我已经连接到事件处理程序:我的广告加载没有问题,没有失败。 当我尝试在iOS上显示广告时,ad.IsLoaded;返回false,即使它刚刚加载了我的OnAdLoaded事件,但广告正在触发。在Unity编辑器中,我看到预期的虚拟方法以正确的顺序被调用,尽管没有显示任何内容,我认为这是Unity自己的编辑器上的预期行为 这是我加载广告的代码当然,我的发布者和广告单位ID是经过编辑的:C# 未显示Unity AdMob广告,c#,ios,unity3d,admob,rewardedvideoad,C#,Ios,Unity3d,Admob,Rewardedvideoad,我正在Unity 5.5上制作一个游戏,我已经将AdMob集成到我的游戏中,目前仅在iOS上,但Android也将在我完成这项工作后跟进 我已经在AdMob控制台上设置了我的游戏,并创建了一个基于奖励的视频广告。 我已经将GoogleMobileAds.framework添加到我在Xcode中构建的项目中。 我已经确定我正在链接新添加的框架。 下载Unity软件包并根据需要将其集成到我的项目中。 我已经连接到事件处理程序:我的广告加载没有问题,没有失败。 当我尝试在iOS上显示广告时,ad.Is
public class AdManager : MonoBehaviour {
static RewardBasedVideoAd ad;
static UIManager uiManager;
#if UNITY_ANDROID
static string adUnitId = "ca-app-pub-XXX/YYY";
#elif UNITY_IPHONE
static string adUnitId = "ca-app-pub-XXX/YYY";
#else
static string adUnitId = "unexpected_platform";
#endif
static int headstartPoints;
// Use this for initialization
void Start () {
uiManager = GameObject.Find("Scripts").GetComponent<UIManager>();
ad = RewardBasedVideoAd.Instance;
ad.OnAdRewarded += Ad_OnAdRewarded;
ad.OnAdClosed += Ad_OnAdClosed;
ad.OnAdFailedToLoad += Ad_OnAdFailedToLoad;
ad.OnAdLoaded += Ad_OnAdLoaded;
headstartPoints = 0;
RequestNewAd();
}
void Ad_OnAdFailedToLoad (object sender, AdFailedToLoadEventArgs e)
{
Debug.Log("Ad failed to load.");
}
void Ad_OnAdLoaded (object sender, System.EventArgs e)
{
Debug.Log("Ad loaded.");
}
void Ad_OnAdClosed (object sender, System.EventArgs e)
{
Debug.Log("Ad was closed, proceeding to game without rewards...");
}
void Ad_OnAdRewarded (object sender, Reward e)
{
Debug.Log("Ad rewarded.");
headstartPoints = (int)e.Amount;
}
public static int GetAndConsumeRewards(){
int points = headstartPoints;
headstartPoints = 0;
return points;
}
public static void RequestNewAd(){
Debug.Log("Requested new ad.");
AdRequest request = new AdRequest.Builder().Build();
ad.LoadAd(request, adUnitId);
}
public static void DisplayAdOrProceed(){
if(ad.IsLoaded()){
ad.Show();
Debug.Log("Ad was loaded, displaying ad...");
}else{
Debug.Log("Ad wasn't loaded, skipping ad...");
uiManager.ProceedToGame();
}
}
// Update is called once per frame
void Update () {
}
}
我可以看到ad加载事件是从一个名为RewardBasedVideoAddFailToReceiveAdwithErrorCallback的失败处理程序RewardBasedVideoAddFailToReceiveAdwithErrorCallback、GoogleMobileAds.Api.RewardBasedVideoAd:m_u8Object、AdFailedToLoadEventArgs的方法触发的。但是,它调用的是ad加载事件,而不是任何故障处理程序。我不知道到底发生了什么,或者是一个设计不好的命名约定。 < P> OK,在跳入XLCODE项目中的IL2CPP生成的C++代码后,我意识到SDK正在调用错误的方法。ad加载失败,错误为没有显示ad,但错误地启动了ad加载方法。我将对代码进行额外更改,以检测是否正确加载了代码
糟糕的错误或设计决策,谷歌。我希望这个问题很快得到解决。您在哪里调用displayadorocedure和RequestNewAd methods?@m.rogalski在level end/level start处。我已经更新了问题,以更详细地解决它们。
Ad loaded.
UnityEngine.DebugLogHandler:Internal_Log(LogType, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
AdManager:Ad_OnAdLoaded(Object, EventArgs)
System.EventHandler`1:Invoke(Object, TEventArgs)
GoogleMobileAds.Api.RewardBasedVideoAd:<RewardBasedVideoAd>m__8(Object, AdFailedToLoadEventArgs)
System.EventHandler`1:Invoke(Object, TEventArgs)
GoogleMobileAds.iOS.RewardBasedVideoAdClient:RewardBasedVideoAdDidFailToReceiveAdWithErrorCallback(IntPtr, String)