注意: IAP Promo を使用するには、Unity Ads を初期化する前に Unity IAP を初期化する必要があります。
このインテグレーションガイドは 4 つの主要な手順を説明します。
IAP Promo を利用するには、次の設定が必要です。
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.
詳細については IAP の設定 を参照してください。
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 の初期化にはコードレスとスクリプティングの2つの選択肢があります。
Codeless IAP は初期化の処理を行います。Codeless IAP の初期化を利用する場合は、Unity Ads の初期化メソッドをコード内で呼び出す必要があります。
Codeless IAP を使うには Product Catalog を入力し、カタログを取得するために IAP Listener を作成します。
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.
In the IAP Catalog window, select App Store Export > Cloud JSON to export a local copy of the Product Catalog.
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);
}
}
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 ();
}
}
Navigate to the Monetization section of the Operate Dashboard to configure your IAP Promo offers:
以下のサンプコードを使って IAP Promo のコンテンツを呼び出します。
public void ShowPromo()
{
Advertisement.Show (placementID);
}
エディターの Play を押して、Placement のリクエストによってテスト広告が表示されることを確認します。実際のプロモーションのクリエイティブアセットを見るには、プロダクションモードで実機にゲームをビルドする必要があります。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.