「Unity/GoogleMobileAds/RewardedVideo8」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==AdMob8での書き方==」) |
|||
(同じ利用者による、間の4版が非表示) | |||
行1: | 行1: | ||
==AdMob8での書き方== | ==AdMob8での書き方== | ||
+ | リワード呼び出し | ||
+ | <pre> | ||
+ | AdMobReward admobReward = new AdMobReward(); | ||
+ | admobReward.Init(); | ||
+ | admobReward.RequestAndLoadRewardedAd(); | ||
+ | </pre> | ||
+ | |||
+ | リワード処理 | ||
+ | <pre> | ||
+ | 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."); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </pre> | ||
+ | *報酬発生は、reward.Amountのある行で処理してる。 | ||
+ | *OnAdPaid側は、収益発生時なので、報酬時ではない。 | ||
+ | *報酬発生タイミングは、動画時間が0になったときであって、画面を閉じたときではないので注意。 | ||
+ | *testモードだと、報酬イベントは、クローズ後に発生した。 |
2024年6月19日 (水) 07:33時点における最新版
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モードだと、報酬イベントは、クローズ後に発生した。