facebook twitter hatena line email

Unity/GoogleMobileAds/RewardedVideo8

提供: 初心者エンジニアの簡易メモ
2024年6月19日 (水) 07:15時点におけるAdmin (トーク | 投稿記録)による版

移動: 案内検索

AdMob8での書き方

リワード呼び出し

AdMobReward admobReward = new AdMobReward();
admobReward.Init();
admobReward.RequestAndLoadRewardedAd();

リワード処理

public class AdMobReward
{
    private RewardedAd rewardedAd;

    public void RequestAndLoadRewardedAd()
    {
        RewardedAd.Load(GetAdUnitId(), request,
            (RewardedAd ad, LoadAdError loadError) =>
            {
                if (loadError != null)
                {
                    Debug.Log("Rewarded ad failed to load with error: " +
                                loadError.GetMessage());
                    return;
                }
                else if (ad == null)
                {
                    Debug.Log("Rewarded ad failed to load.");
                    return;
                }
                Debug.Log("Rewarded ad loaded.");
                rewardedAd = ad;
                if (rewardedAd.CanShowAd())
                {
                    ShowRewardedAd();
                }
                ad.OnAdFullScreenContentOpened += () =>
                {
                    Debug.Log("Rewarded ad opening.");
                };
                ad.OnAdFullScreenContentClosed += () =>
                {
                    Debug.Log("Rewarded ad closed.");
                };
                ad.OnAdImpressionRecorded += () =>
                {
                    Debug.Log("Rewarded ad recorded an impression.");
                };
                ad.OnAdClicked += () =>
                {
                    Debug.Log("Rewarded ad recorded a click.");
                };
                ad.OnAdFullScreenContentFailed += (AdError error) =>
                {
                    Debug.Log("Rewarded ad failed to show with error: " +
                               error.GetMessage());
                };
                ad.OnAdPaid += (AdValue adValue) =>
                {
                    string msg = string.Format("{0} (currency: {1}, value: {2}",
                                               "Rewarded ad received a paid event.",
                                               adValue.CurrencyCode,
                                               adValue.Value);
                    Debug.Log(msg);
                };
            });
    }

    public void ShowRewardedAd()
    {
        if (rewardedAd != null)
        {
            rewardedAd.Show((Reward reward) =>
            {
                Debug.Log("Rewarded ad granted a reward: " + reward.Amount);
            });
        }
        else
        {
            Debug.Log("Rewarded ad is not ready yet.");
        }
    }

}
  • 報酬発生は、reward.Amountのある行で処理してる。

OnAdPaid側は、収益発生時なので、報酬時ではない。

  • 報酬発生タイミングは、動画時間が0になったときであって、画面を閉じたときではないので注意。
  • testモードだと、報酬イベントは、クローズ後に発生した。