# インタースティシャルインテグレーション

> SDKの初期化、初期化後のインタースティシャル広告オブジェクトの作成、広告イベントをハンドルするリスナーの実装によって、Unityにインタースティシャル広告を統合します。

Unity LevelPlay Interstitial は、全画面の広告単位です。通常は、アプリケーションのライフサイクル中の自然な遷移ポイントで機能します。

> **Note:**
>
> このドキュメントは SDK 8.4.0 以降に関連するものです。

## 前提条件 ## Prerequisites

* LevelPlay SDK がアプリケーションに正しく統合されていることを確認します。インテグレーションの概要は[こちら](/grow/levelplay/sdk/unity/package-integration.md)です。
* LevelPlay 初期化 API を使用して SDK を初期化していることを確認します。
* LevelPlay ダッシュボードで AdUnitID を見つけます。

## インタースティシャル広告オブジェクトの作成 ## Create Interstitial Ad Object

インタースティシャル広告オブジェクトの作成は、**OnInitSuccess** コールバックの受信後に実行する必要があります。

オブジェクトは、セッションを通じて複数のロードと表示をハンドルできる再利用可能なインスタンスです。作成後、同じ広告単位の広告をロードおよび表示するために使用する必要があります。

より高度な実装では、必要に応じて複数のインタースティシャル広告オブジェクトを作成できます。

オブジェクトを作成するには、以下を呼び出します。

```cs
// Create Interstitial Ad object
LevelPlayInterstitialAd interstitialAd = new LevelPlayInterstitialAd(interstitialAdUnitId);
```

> **Note:**
>
> `LevelPlayInterstitialAd` コンストラクターは、任意の `Config` パラメーターもサポートします。
>
> ```cs
> // Use optional Config parameter
> LevelPlayInterstitialAd(string adUnitId, Config config = null)
> ```
>
> 特別な設定が必要ない場合は、`Config`パラメーターを省略して`adUnitId`のみを渡すことができます。

### 価格帯での作成 ### Creating with a Price Floor

広告リクエストに任意の価格下限を設定するには、`LevelPlayInterstitialAd`の作成時に `Config` オブジェクトを介してこれを渡します（詳細[はこちら](/grow/levelplay/sdk/unity/advanced-settings.md#price-floor-configuration)）。

```cs
// Create Interstitial Ad object with Price Floor in config.
var configBuilder = new LevelPlayInterstitialAd.Config.Builder();
configBuilder.SetBidFloor(1.0); // Minimum bid price in USD
var isConfig = configBuilder.Build();

LevelPlayInterstitialAd InterstitialAd = new LevelPlayInterstitialAd(InterstitialAdUnitId, isConfig);
```

## インタースティシャルイベントに登録 ## Register to Interstitial Events

コードに **LevelPlayInterstitialAdListener** を実装して、広告配信に関する情報を取得します。

* インタースティシャル広告をロードする前にリスナーを設定することをお勧めします。
* 各インタースティシャル広告には、独自のリスナー実装が必要です。
* コールバックはメインスレッドで実行されます。

```cs
// Register to interstitial events
interstitialAd.OnAdLoaded += InterstitialOnAdLoadedEvent;
interstitialAd.OnAdLoadFailed += InterstitialOnAdLoadFailedEvent;
interstitialAd.OnAdDisplayed += InterstitialOnAdDisplayedEvent;
interstitialAd.OnAdDisplayFailed += InterstitialOnAdDisplayFailedEvent;
interstitialAd.OnAdClicked += InterstitialOnAdClickedEvent;
interstitialAd.OnAdClosed += InterstitialOnAdClosedEvent;
interstitialAd.OnAdInfoChanged += InterstitialOnAdInfoChangedEvent;

// Implement the events
void InterstitialOnAdLoadedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdLoadFailedEvent(LevelPlayAdError error){}
void InterstitialOnAdDisplayedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdDisplayFailedEvent(LevelPlayAdInfo adInfo, LevelPlayAdError error){}
void InterstitialOnAdClickedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdClosedEvent(LevelPlayAdInfo adInfo){}
void InterstitialOnAdInfoChangedEvent(LevelPlayAdInfo adInfo){}
```

### LevelPlay 広告情報 ### LevelPlay Ad Info

**LevelPlayAdInfo** パラメーターには、ロードされた広告に関する情報が含まれます。

実装と使用可能なフィールドの詳細については、[こちら](/grow/levelplay/sdk/unity/levelplay-listener-adinfo-integration.md)を参照してください。

## ロード インタースティシャル広告 ## Load Interstitial Ad

インタースティシャル広告をロードするには、**LoadAd** を使用します。

```cs
// Load interstitial ad
interstitialAd.LoadAd();
```

## インタースティシャル広告の表示 ## Show Interstitial Ad

**LevelPlayInterstitialAdListener** API を使用し**て OnAdLoaded** コールバックを受信した後にインタースティシャル広告を表示します。

* プレースメントを使用している場合は、後述のプレースメントのセクションで示すように、**ShowAd** APIで配置名を渡します。
* ユーザーに広告が正常に表示されたら、ロードステップを繰り返して別の広告をロードできます。 

```cs
// Show ad without placement
interstitialAd.ShowAd();
// Show ad with placement
interstitialAd.ShowAd(placementName: "placementName");
```

### 広告の準備ができているか確認 ### Check Ad is Ready

表示の失敗を避け、広告が正しく表示されるようにするために、**ShowAd** API を呼び出す前に以下の API を使用することをお勧めします。

**IsAdReady** – 広告のロードが成功し、広告単位が上限に達していない場合は true、それ以外の場合は false を返します。

**IsPlacementCapped** – 有効な配置に上限がある場合に true を返します。配置が有効でないか、上限がない場合、この API は false を返します。

```cs
// Check that ad is ready and that the placement is not capped
if (interstitialAd.IsAdReady() && !LevelPlayInterstitialAd.IsPlacementCapped(placementName))
{
    interstitialAd.ShowAd(placementName);
}
```

### Placements##placements

LevelPlay ダッシュボードでは、インタースティシャルの[プレースメント](/grow/levelplay/platform/settings/placements.md) ペーシングとプレースメント キャップをサポートします。 

インタースティシャル広告にプレースメントが設定されている場合は、**ShowAd** メソッドを呼び出して特定の配置の広告を配信します。

```cs
// Check that ad is ready and that the placement is not capped
if (interstitialAd.IsAdReady() && !LevelPlayInterstitialAd.IsPlacementCapped(placementName))
{
    interstitialAd.ShowAd(placementName);
}
```

## インタースティシャル広告の完全な実装例 ## Full Implementation Example of Interstitial Ads

```cs
public class InterstitialAdSample {
    private LevelPlayInterstitialAd interstitialAd;
    void CreateInterstitialAd() {
	      //Create InterstitialAd instance
        interstitialAd= new LevelPlayInterstitialAd("interstitialAdUnitId");

        //Subscribe InterstitialAd events
        interstitialAd.OnAdLoaded += InterstitialOnAdLoadedEvent;
        interstitialAd.OnAdLoadFailed += InterstitialOnAdLoadFailedEvent;
        interstitialAd.OnAdDisplayed += InterstitialOnAdDisplayedEvent;
        interstitialAd.OnAdDisplayFailed += InterstitialOnAdDisplayFailedEvent;
        interstitialAd.OnAdClicked += InterstitialOnAdClickedEvent;
        interstitialAd.OnAdClosed += InterstitialOnAdClosedEvent;
        interstitialAd.OnAdInfoChanged += InterstitialOnAdInfoChangedEvent;
    }
    void LoadInterstitialAd() {
        //Load or reload InterstitialAd 	
        interstitialAd.LoadAd();
    }
    void ShowInterstitialAd() {
	       //Show InterstitialAd, check if the ad is ready before showing
        if (interstitialAd.IsAdReady()) {
   		      interstitialAd.ShowAd();
        }
    }
  
    //Implement InterstitialAd events
    void InterstitialOnAdLoadedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdLoadFailedEvent(LevelPlayAdError ironSourceError) { }
    void InterstitialOnAdClickedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdDisplayedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdDisplayFailedEvent(LevelPlayAdInfo adInfo, LevelPlayAdError error) { }
    void InterstitialOnAdClosedEvent(LevelPlayAdInfo adInfo) { }
    void InterstitialOnAdInfoChangedEvent(LevelPlayAdInfo adInfo) { }
}
```

## LevelPlay Mediation デモアプリケーション ## LevelPlay Mediation Demo App

インテグレーション Demo (インテグレーションデモ) アプリケーションは、アプリケーションにインタースティシャル広告単位 API を統合する方法を示します。

[Unityデモ アプリケーションのダウンロード](https://github.com/ironsource-mobile/Mediation-Demo-Apps)

[インテグレーションテストスイート](/grow/levelplay/sdk/unity/integration-test-suite.md)とのインテグレーションを確認します。

エディター内でインテグレーションをテストできます。Unity エディターで模擬広告をプレビューする方法については、『 [プレビュー模擬広告ガイド](/grow/levelplay/sdk/unity/preview-mock-ads-in-editor.md) 』を参照してください。

## 次のステップ ## Next steps

インテグレーション ガイドに従って、追加のインタースティシャル広告ネットワークを統合したり、追加の広告フォーマットを設定したりできます。

* [メディエーションネットワークの追加](/grow/levelplay/sdk/unity/mediation-networks.md)
* [リワード広告](/grow/levelplay/sdk/unity/rewarded-ad-integration-package.md)
* [バナー広告](/grow/levelplay/sdk/unity/banner-integration.md)
