facebook twitter hatena line email

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

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
(同じ利用者による、間の1版が非表示)
行12: 行12:
 
     public void Init()
 
     public void Init()
 
     {
 
     {
        MobileAds.Initialize(initStatus => { });
 
 
         request = new AdRequest.Builder()
 
         request = new AdRequest.Builder()
            // .AddTestDevice(testDeviceId)
+
            .Build();
            .Build();
+
 
     }
 
     }
 
     public void RequestAndLoad()
 
     public void RequestAndLoad()
行29: 行27:
 
     }
 
     }
  
     private void adLoadCallback(RewardedInterstitialAd ad, string error)
+
     private void adLoadCallback(RewardedInterstitialAd ad, AdFailedToLoadEventArgs error)
 
     {
 
     {
 
         if (error == null)
 
         if (error == null)
 
         {
 
         {
 
             rewardedInterstitialAd = ad;
 
             rewardedInterstitialAd = ad;
            /*
 
 
             rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresent;
 
             rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresent;
 
             rewardedInterstitialAd.OnAdDidPresentFullScreenContent += HandleAdDidPresent;
 
             rewardedInterstitialAd.OnAdDidPresentFullScreenContent += HandleAdDidPresent;
 
             rewardedInterstitialAd.OnAdDidDismissFullScreenContent += HandleAdDidDismiss;
 
             rewardedInterstitialAd.OnAdDidDismissFullScreenContent += HandleAdDidDismiss;
 
             rewardedInterstitialAd.OnPaidEvent += HandlePaidEvent;
 
             rewardedInterstitialAd.OnPaidEvent += HandlePaidEvent;
             */
+
             ShowAd();
 
         }
 
         }
 +
    }
 +
 +
    private void HandleAdFailedToPresent(object sender, AdErrorEventArgs args)
 +
    {
 +
        MonoBehaviour.print("Rewarded interstitial ad has failed to present.");
 +
    }
 +
 +
    private void HandleAdDidPresent(object sender, EventArgs args)
 +
    {
 +
        MonoBehaviour.print("Rewarded interstitial ad has presented.");
 +
    }
 +
 +
    private void HandleAdDidDismiss(object sender, EventArgs args)
 +
    {
 +
        MonoBehaviour.print("Rewarded interstitial ad has dismissed presentation.");
 +
    }
 +
 +
    private void HandlePaidEvent(object sender, AdValueEventArgs args)
 +
    {
 +
        MonoBehaviour.print(
 +
            "Rewarded interstitial ad has received a paid event.");
 
     }
 
     }
 
     public void ShowAd()
 
     public void ShowAd()

2022年4月16日 (土) 23:04時点における最新版

RewardInterstitial

全画面の報酬あり広告(全部動画?)

サンプル

using GoogleMobileAds.Api;

public class AdMobRewardInterstitial
{
    AdRequest request;
    private RewardedInterstitialAd rewardedInterstitialAd;
    public void Init()
    {
        request = new AdRequest.Builder()
            .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, AdFailedToLoadEventArgs error)
    {
        if (error == null)
        {
            rewardedInterstitialAd = ad;
            rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += HandleAdFailedToPresent;
            rewardedInterstitialAd.OnAdDidPresentFullScreenContent += HandleAdDidPresent;
            rewardedInterstitialAd.OnAdDidDismissFullScreenContent += HandleAdDidDismiss;
            rewardedInterstitialAd.OnPaidEvent += HandlePaidEvent;
            ShowAd();
        }
    }

    private void HandleAdFailedToPresent(object sender, AdErrorEventArgs args)
    {
        MonoBehaviour.print("Rewarded interstitial ad has failed to present.");
    }

    private void HandleAdDidPresent(object sender, EventArgs args)
    {
        MonoBehaviour.print("Rewarded interstitial ad has presented.");
    }

    private void HandleAdDidDismiss(object sender, EventArgs args)
    {
        MonoBehaviour.print("Rewarded interstitial ad has dismissed presentation.");
    }

    private void HandlePaidEvent(object sender, AdValueEventArgs args)
    {
        MonoBehaviour.print(
            "Rewarded interstitial ad has received a paid event.");
    }
    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