Version: 2019.2
IAP Promo
IAP Promo Product Catalogs

IAP Promo のインテグレーション

概要

注意: IAP Promo を使用するには、Unity Ads を初期化する前に Unity IAP を初期化する必要があります。

このインテグレーションガイドは 4 つの主要な手順を説明します。

Unity エディター内のプロジェクトの準備

Unity Services の設定

IAP Promo を利用するには、次の設定が必要です。

  1. プロジェクトの Unity Services の設定
  2. プロジェクトの Unity IAP SDK (1.2+) と Unity Ads SDK (2.3+) を有効化

Unity IAP の設定

IAP Promo requires a supported version of the Unity IAP SDK (1.17+). To acquire the latest IAP SDK, either enable In-App Purchasing in the Services window (Window > Services), or import it from the Asset store. If you’re enabling it from the Services window, be sure to Import the Asset package when prompted.

エディターの Services Window から Unity IAP を有効にします
エディターの Services Window から Unity IAP を有効にします

詳細については IAP の設定 を参照してください。

Unity Ads の設定

IAP Promo requires a supported version of the Unity Ads SDK. Unity recommends acquiring the latest Ads SDK (3.0+) by importing it from the Asset store.

詳細については Unity Ads の設定 を参照してください。

実装

これらの必要な Services が設定されると、ゲームに実装できます。

IAP の実装

IAP の初期化にはコードレスとスクリプティングの2つの選択肢があります。

Codeless IAP を利用する

Codeless IAP は初期化の処理を行います。Codeless IAP の初期化を利用する場合は、Unity Ads の初期化メソッドをコード内で呼び出す必要があります。

Codeless IAP を使うには Product Catalog を入力し、カタログを取得するために IAP Listener を作成します。

  1. In the Editor, select Window > UnityIAP > IAP Catalog to open the IAP Catalog window. This window lists all of your previously configured Products. You must have at least one Product configured in your Product Catalog. For a complete walkthrough on setting up Products, see Codeless IAP.

  2. In the IAP Catalog window, select App Store Export > Cloud JSON to export a local copy of the Product Catalog.
    Exporting an IAP Product Catalog to JSON

  3. IAP Listener を作成します。Window > Unity IAP > Create IAP Listener を選択し、ゲームの最初のシーンにこれを追加します。このリスナーは Product Catalog をゲーム起動時に取得します。これによって Promotions がリクエストされる際のエラーは回避できますが、コードレスボタンがシーンに現れていないため、Product はまだ準備が完了していません。

スクリプトを利用する

Codeless IAP を使用しない場合は、スクリプトを使って 手動で UnityIAP を初期化する 必要があります。以下のコードサンプルを参照してください。

using UnityEngine;
using UnityEngine.Purchasing;

public class IAPManager : MonoBehaviour, IStoreListener {
  private IStoreController controller;
  
  //The following products must be added to the Product Catalog in the Editor:
  private const string coins100 = "100.gold.coins";
  private const string coins500 = "500.gold.coins";

  public int coin_count = 0;

  void Awake () { 
    StandardPurchasingModule module = StandardPurchasingModule.Instance (); 
    ProductCatalog catalog = ProductCatalog.LoadDefaultCatalog (); 
    ConfigurationBuilder builder = ConfigurationBuilder.Instance (module);
    IAPConfigurationHelper.PopulateConfigurationBuilder (ref builder, catalog); 
    UnityPurchasing.Initialize (this, builder); 
  }

  public void OnInitialized (IStoreController controller, IExtensionProvider extensions) { 
    this.controller = controller; Debug.Log ("Initialization Successful"); 
  }
  
  public void OnInitializeFailed(InitializationFailureReason error) { 
    Debug.Log ("UnityIAP.OnInitializeFailed (" + error + ")")
  }
  
  public void OnPurchaseFailed (Product item, PurchaseFailureReason reason) { 
    Debug.Log("UnityIAP.OnPurchaseFailed (" + item + ", " + reason + ")"); 
  }

  public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs e) {
    string purchasedItem = e.purchasedProduct.definition.id;
    
    switch (purchasedItem) { 
      case coins100: Debug.Log ("Congratulations, you are richer!"); 
      coin_count += 100; 
      Debug.Log ("IAPLog: Coin count: " + coin_count); 
      break; 
      
      case coins500: Debug.Log ("Congratulations, you are richer!"); 
      coin_count += 500; 
      Debug.Log ("IAPLog: Coin count: " + coin_count);
      break;
    }
    return PurchaseProcessingResult.Complete;
  }

  public void Buy(string productId) { 
    Debug.Log ("UnityIAP.BuyClicked (" + productId + ")");
    controller.InitiatePurchase (productId);
  }
}

Unity Ads の実装

Codeless または、手動の IAP 初期化方法、どちらを使うかにかかわらず、Unity Ads の初期化 を行う必要があります。以下のコードサンプルは、初期化メソッドの呼び出し方を示しています。

using UnityEngine;
using UnityEngine.Monetization;

public class AdManager : MonoBehaviour {

  public bool testMode = true;
  private const string adPlacement = "video";
  private const string promoPlacement = "promo";

  #if UNITY_IOS
    private string gameId = "0000000"; // Your iOS game ID here
  #elif UNITY_ANDROID
    private string gameId = "9999999"; // Your Android game ID here
  #else
    private string gameId = "0123456"; // Prevents Editor Errors
  #endif

  private void Awake () {
    if (Monetization.isSupported && !Monetization.isInitialized) {
      Monetization.Initialize (gameId, testMode); 
    }
  }

  public void ShowVideoAd () { 
    ShowAdPlacementContent ad = Monetization.GetPlacementContent (adPlacement) as ShowAdPlacementContent; 
    ad.Show (); 
  }

  public void ShowPromo () { 
    PromoAdPlacementContent promo = Monetization.GetPlacementContent (promoPlacement) as PromoAdPlacementContent; 
    promo.Show (); 
  }
}

ダッシュボードで Promotions を設定

Navigate to the Monetization section of the Operate Dashboard to configure your IAP Promo offers:

  • Use Placements to control when and how your Promotions display in-game. Follow the Placements guide to create and configure your Promo Placements for IAP content.
  • Product Catalog をインポートして各プロダクトのクリエイティブアセットを管理するには Product のインターフェースを使います。
  • プロモーションの実行時、その中に含まれる PlacementsProducts、ターゲットとするユーザーなど、 Promotions のパラメーターを定義します。

インテグレーションのテスト

Use the Editor Play mode to check that a test ad appears when the Placement makes its request.

In order to test Promos, you must have Promo assets configured and build to a device. If you initialize in test mode, you will see a test Promo creative. To see real promotional creative assets, you must build the game to a device in production mode.




  • 2019–04–11 Page amended
IAP Promo
IAP Promo Product Catalogs