以下のコードは、リスナーを付与して最初のインタースティシャル広告をロードする方法を示しています。
#if UNITY_IOSstring adUnitId = "«iOS-ad-unit-ID»";#else // UNITY_ANDROIDstring adUnitId = "«Android-ad-unit-ID»";#endif int retryAttempt; public void InitializeInterstitialAds(){ // Attach callback MaxSdkCallbacks.Interstitial.OnAdLoadedEvent += OnInterstitialLoadedEvent; MaxSdkCallbacks.Interstitial.OnAdLoadFailedEvent += OnInterstitialLoadFailedEvent; MaxSdkCallbacks.Interstitial.OnAdDisplayedEvent += OnInterstitialDisplayedEvent; MaxSdkCallbacks.Interstitial.OnAdClickedEvent += OnInterstitialClickedEvent; MaxSdkCallbacks.Interstitial.OnAdHiddenEvent += OnInterstitialHiddenEvent; MaxSdkCallbacks.Interstitial.OnAdDisplayFailedEvent += OnInterstitialAdFailedToDisplayEvent; // Load the first interstitial LoadInterstitial();} private void LoadInterstitial(){ MaxSdk.LoadInterstitial(adUnitId);} private void OnInterstitialLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo){ // Interstitial ad is ready for you to show. MaxSdk.IsInterstitialReady(adUnitId) now returns 'true' // Reset retry attempt retryAttempt = 0;} private void OnInterstitialLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo){ // Interstitial ad failed to load // AppLovin recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds) retryAttempt++; double retryDelay = Math.Pow(2, Math.Min(6, retryAttempt)); Invoke("LoadInterstitial", (float) retryDelay);} private void OnInterstitialDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {} private void OnInterstitialAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo, MaxSdkBase.AdInfo adInfo){ // Interstitial ad failed to display. AppLovin recommends that you load the next ad. LoadInterstitial();} private void OnInterstitialClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {} private void OnInterstitialHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo){ // Interstitial ad is hidden. Pre-load the next ad. LoadInterstitial();}
インタースティシャル広告を表示するには、ShowInterstitial()を呼び出します。
ShowInterstitial()
if ( MaxSdk.IsInterstitialReady(adUnitId) ){ MaxSdk.ShowInterstitial(adUnitId);}