facebook twitter hatena line email

「Unity/GoogleMobileAds/RewardInterstitial」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==サンプル== <pre> using GoogleMobileAds.Api; public class AdMobRewardInterstitial { AdRequest request; private RewardedInterstitialAd rewardedInterstitialA...」)
 
(サンプル)
行10: 行10:
 
     public void Init()
 
     public void Init()
 
     {
 
     {
        string testDeviceId = AdMobUtility.GetTestDeviceId();
 
 
         MobileAds.Initialize(initStatus => { });
 
         MobileAds.Initialize(initStatus => { });
 
         request = new AdRequest.Builder()
 
         request = new AdRequest.Builder()
             .AddTestDevice(testDeviceId)
+
             // .AddTestDevice(testDeviceId)
 
             .Build();
 
             .Build();
 
     }
 
     }
行19: 行18:
 
     {
 
     {
 
#if UNITY_ANDROID
 
#if UNITY_ANDROID
             string adUnitId = "ca-app-pub-0xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx";
+
             string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx";
 
#elif UNITY_IPHONE
 
#elif UNITY_IPHONE
         string adUnitId = "ca-app-pub-0xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx";
+
         string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx";
 
#else
 
#else
 
             string adUnitId = "unexpected_platform";
 
             string adUnitId = "unexpected_platform";

2022年4月16日 (土) 18:45時点における版

サンプル


using GoogleMobileAds.Api;

public class AdMobRewardInterstitial
{
    AdRequest request;
    private RewardedInterstitialAd rewardedInterstitialAd;
    public void Init()
    {
        MobileAds.Initialize(initStatus => { });
        request = new AdRequest.Builder()
             // .AddTestDevice(testDeviceId)
             .Build();
    }
    public void RequestAndLoad()
    {
#if UNITY_ANDROID
            string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx";
#elif UNITY_IPHONE
        string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxxx/xxxxxxxxx";
#else
            string adUnitId = "unexpected_platform";
#endif
        RewardedInterstitialAd.LoadAd(adUnitId, request, adLoadCallback);
    }

    private void adLoadCallback(RewardedInterstitialAd ad, string error)
    {
        if (error == null)
        {
            rewardedInterstitialAd = ad;
            /*
            rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresent;
            rewardedInterstitialAd.OnAdDidPresentFullScreenContent += HandleAdDidPresent;
            rewardedInterstitialAd.OnAdDidDismissFullScreenContent += HandleAdDidDismiss;
            rewardedInterstitialAd.OnPaidEvent += HandlePaidEvent;
            */
        }
    }
    public void ShowAd()
    {
        if (rewardedInterstitialAd != null)
        {
            rewardedInterstitialAd.Show(userEarnedRewardCallback);
        }
    }
    private void userEarnedRewardCallback(Reward reward)
    {
        // TODO: Reward the user.
    }
}

公式:https://developers.google.com/admob/unity/rewarded-interstitial?hl=ja