Unity/GoogleMobileAds/RewardedVideo8
提供: 初心者エンジニアの簡易メモ
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側は、収益発生時なので、報酬時ではない。