使用Unity Ads的GoogleMobileAds - 基于奖励的视频广告事件处理程序问题

时间:2017-02-25 17:59:46

标签: unity3d admob rewardedvideoad

我有一个游戏项目,它使用带有Unity Ads的GoogleMobileAds来提供横幅广告,插页式广告和奖励视频广告(统一广告作为中介网络)。一切都设置正确(admob配置,sdk和适配器文件等),似乎工作正常。所有三种类型的广告都在加载和显示,没有错误。
但是有一个小问题。我很难及时回复基于奖励的视频广告 OnAdRewarded 活动。我尝试了几个选项,包括在事件处理程序中运行奖励命令(不工作)和使用标志并检查其值(不工作)。据我所知,googlemobileads事件没有在主线程中提升。旗帜应该可以做到这一点,但事实并非如此。是否有人遇到过这个问题并找到了解决方案?

我的代码如下:

using GoogleMobileAds.Api;
using System;
using System.Collections;
using UnityEngine;

public class RewardBasedAdManager : MonoBehaviour
{
    private RewardBasedVideoAd rewardBasedVideoAd;

    public int rewardAmount = 25;
    public bool isPlayerRewarded = false;

    private void Start()
    {
        // Get singleton reward based video ad reference.
        rewardBasedVideoAd = RewardBasedVideoAd.Instance;

        // RewardBasedVideoAd is a singleton, so handlers should only be registered once.
        ..
        rewardBasedVideoAd.OnAdRewarded += this.HandleRewardBasedVideoRewarded;
        ..
        RequestRewardBasedVideo();
    }

    public void RequestRewardBasedVideo(){...}

    ...

    private void HandleRewardBasedVideoRewarded(object sender, Reward args)
    {
        //Debug.Log("HandleRewardBasedVideoRewarded event received.");
        string type = args.Type;
        double amount = args.Amount;
        //Debug.Log("User rewarded with: " + amount.ToString() + " " + type);

        // Option 1
        // Directly execute reward command (not working)
        // It's a singleton. Could this be the problem?
        CoinTracker.Instance.CoinCount += rewardAmount;

        // Option 2
        // Use flag and check it's value in Update method (not working either)
        isPlayerRewarded = true;
    }

    private void Update()
    {
        if (isPlayerRewarded)
        {
            CoinTracker.Instance.CoinCount += rewardAmount;
            isPlayerRewarded = false;
        }
    }
}

0 个答案:

没有答案