FullscreenInterstitial PluginInstallation - mkaji-geniee/Geniee-SDK-Unity-Plugin GitHub Wiki

Plugin導入手順

UnityへのGeniee 全画面インタースティシャル広告 SDK Unity Plugin導入手順を説明します。

  1. Google Mobile Ads Unity pluginをUnityプロジェクトへインポート
  2. GNSAdSDKUnityPlugin-X.X.XをUnityプロジェクトへインポート
  3. Plugin APIを使用し、全画面インタースティシャル広告のイベントを登録
  4. 破棄処理を追加
  5. 全画面インタースティシャル広告のロード
  6. 全画面インタースティシャル広告の表示
  7. 広告の事前呼び出しについて
  8. Androidパッケージ名について

1. Google Mobile Ads Unity pluginをUnityプロジェクトへインポート

  1. https://developers.google.com/admob/unity/startから Mobile Ads Unity pluginをダウンロードしてください。
  2. Pluginを組み込むUnityプロジェクトを開きます。
  3. メニューバーの Assets -> Import Package -> Custom Packageの順に選択します。
  4. ダウンロードしたGoogleMobileAdsPlugin.unitypackageファイルを選択します。
  5. すべてのファイルのチェックボックスがオンになっていることを確認して、Import をクリックします。

2. GNSAdSDKUnityPlugin-X.X.XをUnityプロジェクトへインポート

  1. Pluginを組み込むUnityプロジェクトを開きます。

  2. https://github.com/googlesamples/unity-jar-resolverを参照し、PlayServicesResolverを導入します。

  3. メニューバーの Assets -> Import Package -> Custom Packageの順に選択します。

  4. reward側のDistフォルダのGNSAdSDKUnityPlugin-X.X.X.unitypackageファイルを選択します。

  5. 以下ファイルのチェックボックスがオンになっていることを確認して、Import をクリックします。

    • GNSAdSDK
      • Api
        • FullscreenInterstitialAd.cs
        • FullscreenInterstitialFailedData.cs
      • Clients
        • MockClient.cs
        • FullscreenInterstitialAdClient.cs
      • Platforms
        • AdClientFactory.cs
        • Android
          • FullscreenInterstitialAdClientImpl.cs
          • Utils.cs
        • iOS
          • Externs.cs
          • FullscreenInterstitialAdClientImpl.cs
    • PlayServicesResolver
      • Editor
        • GNDependencies.xml
    • Plugins
      • Android
        • AndroidManifest.xml
        • GNSExtendsUnityPlayerActivity.jar
        • mainTemplate.gradle
      • iOS
        • GNSUInterface.m
        • GNSUObjectCache.h
        • GNSUObjectCache.m
        • GNSUFullscreenInterstitialAd.h
        • GNSUFullscreenInterstitialAd.m
        • GNSUTypes.h

3. Plugin APIを使用し、全画面インタースティシャル広告のイベントを登録

以下は、全画面インタースティシャル広告を作成してイベントを登録するために必要なコードです。 イベントを登録する際は、広告のロードをする前に登録処理を完了させてください。

using GNSAdSDK.Api;

...

static bool isRegistedFullscreenInterstitialEventHandler = false;

void RegistFullscreenInterstitialAdEventHandler()
{
    if (!isRegistedFullscreenInterstitialEventHandler)
    {
        FullscreenInterstitialAd fullscreenInterstitialAd = FullscreenInterstitialAd.Instance;
        fullscreenInterstitialAd.OnAdLoaded += (object sender, System.EventArgs args) =>
        {
            // 全画面広告のロードが完了した際の処理
        };
        fullscreenInterstitialAd.OnAdStarted += (object sender, System.EventArgs args) => {
            // 全画面広告が再生された際の処理
        };
        fullscreenInterstitialAd.OnAdClosed += (object sender, System.EventArgs args) => {
            // 全画面広告が閉じられた際の処理
        };
        fullscreenInterstitialAd.OnAdFailedToLoad += (object sender, FullscreenInterstitialFailedData args) => {
            // 全画面広告のロードが失敗した際の処理
        };
    }
    isRegistedFullscreenInterstitialEventHandler = true;
}
  • FullscreenInterstitialAdインスタンスは、全画面インタースティシャル広告を操作するためのシングルトンオブジェクトとなります。
  • FullscreenInterstitialAdインスタンスがシングルトンオブジェクトのため、イベント重複を避けるためにイベント登録は1回だけにすることを推奨します。

FullscreenInterstitialFailedData は下記プロパティを所持しています。

public class FullscreenInterstitialFailedData : EventArgs
{
    // アドネットワーク名
    // ※ iOSの場合は、常にnullとなります。
    public string AdnetworkName { get; set; }
    // コード
    public int Code { get; set; }
    // メッセージ
    public string Message { get; set; }
}

4. 破棄処理を追加

Androidの場合OnDestroy時に破棄処理を行うため、下記のようにApplication.Quitのコールバックを設定してください。 ※ iOSのみ作成する場合は、必須ではありません。

using GNSAdSDK.Api;

...

void OnApplicationQuit()
{
    FullscreenInterstitialAd.Instance.DisposeAd();
}

5. 全画面インタースティシャル広告のロード

以下は、全画面インタースティシャル広告のロードに必要なコードです。

using GNSAdSDK.Api;

...

void LoadFullscreenInterstitialAd()
{
    string zoneId = "";
    #if UNITY_ANDROID
        zoneId = "ここにzoneIdを入れてください";
    #elif UNITY_IPHONE
        zoneId = "ここにzoneIdを入れてください";
    #endif
    FullscreenInterstitialAd fullscreenInterstitialAd = FullscreenInterstitialAd.Instance;
    fullscreenInterstitialAd.LoadAd(zoneId);
}
  • FullscreenInterstitialAdインスタンスは、全画面インタースティシャル広告を操作するためのシングルトンオブジェクトとなります。
  • ロードには数秒以上かかることがあるので、早い段階で広告をロードしてください。
  • 1つの広告の再生完了後に別の広告を見せる場合、再びロードを行う必要があります。

6. 全画面インタースティシャル広告の表示

以下は、全画面インタースティシャル広告の表示に必要なコードです。広告のロードが完了されるとShowAd()の呼び出しが可能となります。

using GNSAdSDK.Api;

...

void ShowFullscreenInterstitialAd()
{
    FullscreenInterstitialAd fullscreenInterstitialAd = FullscreenInterstitialAd.Instance;
    // 広告が表示出来るか確認
    if (fullscreenInterstitialAd.IsLoaded())
    {
        // 広告の表示
        fullscreenInterstitialAd.ShowAd();
    }
}

7. 広告の事前呼び出しについて

広告表示後、事前に次の広告をロードしたい場合の注意点

広告クローズイベント(OnAdClosed)内へLoadAd(zoneId);を実装してください。

8. Androidパッケージ名について

Assets/Plugins/Android/AndroidManifest.xml内のpackage名は適宜修正ください。

 package="jp.co.geniee.GNSUnitySampleFullscreenInterstitial"