開発
開発
プラットフォームを選択

アドオンの統合

更新日時: 2025/05/17
このトピックではアプリにアドオンを統合する方法について説明します。

要件

アプリとアドオンを統合する前に、いくつかの要件を満たす必要があります。以降のセクションで、前提条件を満たす方法について概説します。

購入用のアイテムを設定する

アドオンをアプリに統合する前に、購入用に提供するアイテムを定義する必要があります。アドオンの設定方法については、アドオンの設定を参照してください。

エンジンサポート

Unityは、アセットバンドルと呼ばれるパッケージング機能を提供しており、これはMeta Horizonプラットフォームの一般的なアセットと互換性があります。詳しくは、以下をご覧ください。

アプリにインターネット接続が必要なことを示す

ダウンロード可能なコンテンツに関連付けられているアドオンの場合、アプリにインターネット接続が必要であることを示すマークを付けます。
  1. 開発者ダッシュボードから、[Distribution (配信)] > [App Submissions (アプリの提出)] > {Your app} > [App Metadata (アプリのメタデータ)] > [Specs (仕様)]に進み、アプリの仕様ページにアクセスします。
  2. [Internet Connection (インターネット接続)]のドロップダウンメニューから、[Internet connection required for downloadable contents (コンテンツをダウンロードするにはインターネット接続が必要)]を選択します。

IAPサービスを有効にする

  1. 開発者ダッシュボードから、[Development (開発)] > [All Platform Services (すべてのプラットフォームサービス)] > [Add-ons (アドオン)]の順に従い、アプリサービスページにアクセスしてください。[Add Service (サービスを追加)]をクリックします
  2. 開発者ダッシュボードから、[Requirements (要件)] > [Data Use Checkup (データの使用状況の確認)]の順に従い、データの使用状況の確認ページにアクセスします。ユーザーIDアプリ内購入[Add (追加)]をクリックします

アドオンとの統合

購入用に提供するアイテムの定義が完了したら、それらを購入可能なアイテムとしてアプリに組み込む作業を開始できます。
クライアントアプリから下記のSDKメソッドを呼び出すことができます。各関数について詳しくは、プラットフォームSDKのリファレンスコンテンツを参照してください。

Retrieve a list of available items and prices by SKU

To retrieve a list of add-on items that are available to the user to purchase by SKU, use the following method. The SKUs must have a description to be retrieved by this method.
This method also returns any virtual SKUs associated with subscription periods.
Platform.IAP.GetProductsBySKU()
If your app displays a price for any add-on, you should use the localized price returned from this endpoint. Do not hard-code price amounts inside the app.

SKUs for subscriptions

If a subscription tier only has a single subscription period, you can reference that single subscription period as an add-on using the SKU of its tier.
However, to differentiate between multiple subscription periods of the same SKU, we create a virtual SKU for each period by appending the subscription period (WEEKLY, BIWEEKLY, MONTHLY, QUARTERLY, SEMIANNUAL, ANNUAL) to the SKU in this format:
<SKU>:SUBSCRIPTION__<PERIOD>
For example, consider a subscription tier with the SKU MyApp-Subscription that has both monthly and annual subscription periods. You would reference the subscription add-on items by virtual SKU as follows:
  • MyApp-Subscription:SUBSCRIPTION__MONTHLY
  • MyApp-Subscription:SUBSCRIPTION__ANNUAL
The GetProductsBySKU method also returns virtual SKUs, so to prevent errors, we recommend you call that method to obtain the full list of available SKUs instead of hardcoding virtual SKU strings into your product.
詳しくは、サブスクリプションを参照してください。

SKUのチェックアウトフローを起動する

指定したSKUの購入をユーザーが完了するためのチェックアウトフローを起動するには、次のメソッドを使います。
Platform.IAP.LaunchCheckoutFlow()

ユーザーが購入したすべてのアイテムを取得する

ユーザーによるIAP購入のリストを取得するには、次のメソッドを使います。返されるリストには、すべて永続タイプの購入と、消費されていない消耗タイプの購入が含まれます。
Platform.IAP.GetViewerPurchases()

ユーザーが購入した永続アイテムのキャッシュリストを取得する

ユーザーが購入した永続アドオンアイテムのリストを取得するには、次のメソッドを使います。返されるリストには、非消耗の購入が含まれ、デバイスのキャッシュから読み込まれます。まずGetViewerPurchasesを使ってみて、それ以外の呼び出しが失敗する場合にはこのメソッドを使ってください。
Platform.IAP.GetViewerPurchasesDurableCache()

購入したアイテムを消費する

ユーザーに代わって購入したアイテムを消費し、そのアイテムをアプリ内で使用済みとしてマークするには、次のメソッドを使います。
Platform.IAP.ConsumePurchase()

実装の例

次のUnityの例は、IAPアイテムの情報を取得し、その情報をユーザーに表示し、未処理の購入を処理し、ユーザーが購入意欲を示した場合にチェックアウトフローを開始するエンドツーエンドのフローを示しています。次の例は、VRBoardGameサンプルアプリから取得したものです。使用可能なアプリの詳細については、サンプルアプリのページを参照してください。

using UnityEngine;
using Oculus.Platform;
using Oculus.Platform.Models;
using UnityEngine.UI;


// This class coordinates In-App-Purchases (IAP) for the application.  Follow the
// instructions in the Readme for setting up IAP on the Meta Quest dashboard. Only
// one consumable IAP item is used is the demo: the Power-Ball!
public class IAPManager : MonoBehaviour
{
    // the game controller to notify when the user purchase more powerballs
    [SerializeField] private GameController m_gameController;

    // where to record to display the current price for the IAP item
    [SerializeField] private Text m_priceText;

    // purchasable IAP products we've configured on the Meta Quest dashboard
    private const string CONSUMABLE_1 = "PowerballPack1";

    void Start()
    {
        FetchProductPrices();
        FetchPurchasedProducts();
    }

    // get the current price for the configured IAP item
    public void FetchProductPrices()
    {
        string[] skus = { CONSUMABLE_1 };
        IAP.GetProductsBySKU(skus).OnComplete(GetProductsBySKUCallback);
    }

    void GetProductsBySKUCallback(Message<ProductList> msg)
    {
        if (msg.IsError)
        {
            PlatformManager.TerminateWithError(msg);
            return;
        }

        foreach (Product p in msg.GetProductList())
        {
            Debug.LogFormat("Product: sku:{0} name:{1} price:{2}", p.Sku, p.Name, p.FormattedPrice);
            if (p.Sku == CONSUMABLE_1)
            {
                m_priceText.text = p.FormattedPrice;
            }
        }
    }

    // fetches the Durable purchased IAP items.  should return none unless you are expanding the
    // to sample to include them.
    public void FetchPurchasedProducts()
    {
        IAP.GetViewerPurchases().OnComplete(GetViewerPurchasesCallback);
    }

    void GetViewerPurchasesCallback(Message<PurchaseList> msg)
    {
        if (msg.IsError)
        {
            PlatformManager.TerminateWithError(msg);
            return;
        }

        foreach (Purchase p in msg.GetPurchaseList())
        {
            Debug.LogFormat("Purchased: sku:{0} granttime:{1} id:{2}", p.Sku, p.GrantTime, p.ID);
        }
    }

    public void BuyPowerBallsPressed()
    {
#if UNITY_EDITOR
        m_gameController.AddPowerballs(1);
#else
        IAP.LaunchCheckoutFlow(CONSUMABLE_1).OnComplete(LaunchCheckoutFlowCallback);
#endif
    }

    private void LaunchCheckoutFlowCallback(Message<Purchase> msg)
    {
        if (msg.IsError)
        {
            PlatformManager.TerminateWithError(msg);
            return;
        }

        Purchase p = msg.GetPurchase();
        Debug.Log("purchased " + p.Sku);
        m_gameController.AddPowerballs(3);
    }
}

ダウンロード可能なコンテンツとの統合

アプリに関連付けられているアセットのリストを取得する

アプリの起動時に、アプリに関連付けられているすべてのアセットのリストが以下のメソッドにより取得されます。
Platform.AssetFile.GetList
このメソッドは、利用可能なアセットの詳細のリストを返します。配列の各要素には次のプロパティがあります。
  • assetFileName - ファイル名
  • assetFileID - アセット識別情報
  • IapStatus - これは、freeentitlednot-entitledのいずれかの値になります。
  • downloadStatus - これは次のいずれかの値になります。
    • installed - 利用者はファイルをインストール済み
    • available - 利用者はファイルをダウンロード可能
    • in-progress - 利用者のためにファイルをダウンロード中またはインストール中。

ダウンロードの開始

ダウンロード可能なファイルがある場合(つまり、そのステータスがfreeまたはentitledで、download_status = availableである場合)、次のメソッドを呼び出してダウンロードを開始できます。
  • Platform.AssetFile.DownloadById
この呼び出しを行うには、最初のGetList呼び出しで返されたアイテムのIDを渡します。
この呼び出しを行うと、リクエストが成功したことの確認として、アセットへのパスを含むDownloadResult応答が即座に返されます。また、DownloadUpdate通知のリッスンも必要です。そうすると、転送バイト数に関する情報と、ダウンロードが完了したときに通知する完了フラグが返されます。
このページは役に立ちましたか?
高評価アイコン
低評価アイコン
ナビゲーションロゴ
日本語
© 2026 Meta