開発

アドオンの統合

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

要件

This is a Platform SDK feature requiring Data Use Checkup
この機能を利用するには、データの使用状況の確認(DUC)を完了する必要があります。DUCは、開発者ポリシーを遵守していることを確認するためのものです。チームの管理者は、ユーザーデータの利用がプラットフォームガイドラインに沿っていることを証明する必要があります。開発中は、提出されたDUCは自動的に承認され、アプリに暫定的なアクセスが付与されます。アプリレビューを申請するか、より高いリリースチャネル制限を有効にすると、自動承認は完全に終了します。ただし、すでに所有している機能はレビュー中も引き続き使用できます(DUCを申請するタイミングを参照)。テストユーザーは、DUCの承認を得る前にこれらの機能を呼び出すことができます。ただし、ユーザーIDまたはユーザープロフィールの付与が必要なログインユーザーの取得は例外です。
アドオンの場合は、アプリ内購入を有効にするに示されているように、[In-app purchases and/or downloadable content (アプリ内購入やダウンロードコンテンツ)]機能をリクエストしてください。サブスクリプションを販売するには、サブスクリプション機能もリクエストしてください。マッチング機能がない場合、テストユーザーでさえ、アプリ内からアドオンやサブスクリプションを購入することはできません。
アプリとアドオンを統合する前に、いくつかの要件を満たす必要があります。以降のセクションで、前提条件を満たす方法について概説します。
収益化APIを使用するには、少なくとも1つのバージョンのAPKを開発者ダッシュボードにアップロードする必要があります。アプリを設定するだけでなく、有効なAPKパッケージをアップロードして、システムがアプリのIDを確認し、収益化APIと正しく関連付ける必要があります。

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

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

エンジンサポート

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

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

ダウンロード可能なコンテンツに関連付けられているアドオンの場合、アプリにインターネット接続が必要であることを示すマークを付けます。
  1. 開発者ダッシュボード⁠から、アプリを選択します。
    Choose your app in the Developer Dashboard
  2. 左側のナビゲーションで、[Distribution (配信)] > [App Submissions (アプリ申請)]に移動します。
    Developer Dashboard menu options: Distribution and App submission
  3. [App Submissions (アプリ申請)]ページで、アプリの最新バージョンをクリックします。
    The app submissions page in the Developer Dashboard
  4. [App Metadata (アプリメタデータ)]タブをクリックします。
    The App Metadata tab in the Developer Dashboard
  5. [Specs (仕様)]タブをクリックします。
    The Specs tab in the Developer Dashboard
  6. 下にスクロールして、[Internet Connection (インターネット接続)]ドロップダウンメニューを探します。このメニューから、[Internet connection required (インターネット接続が必要)]を選択します。
    The Internet Connection dropdown menu in the Developer Dashboard

アプリ内購入を有効にする

次の手順で、アプリ内購入を有効にすることができます。この機能を有効にするには、プレイヤーのユーザーIDへのアクセスが必要です。
  1. 開発者ダッシュボード⁠から、アプリを選択します。
    Choose your app in the Developer Dashboard
  2. 左側のナビゲーションから、[Requirements (要件)] > [Data Use Checkup (データの使用状況の確認)]に移動します。
    Requirements and Data Use Checkup in the Developer Dashboard
  3. [Age group self-certification (年齢層の自己申告)]セクションで、[Start (開始)]をクリックします。
    Age group certification window in the Developer Dashboard
  4. 表示されるウィンドウで、アプリに最も適した年齢層を選択し、[Continue (次へ)]をクリックします。
    Age group certification window in the Developer Dashboard
  5. [Request to Access Platform Features (プラットフォーム機能へのアクセスリクエスト)]セクションで、[User ID (ユーザーID)]の横にある[Add (追加)]ボタンをクリックします。新しいウィンドウが開きます。
    Data Use Checkup window in the Developer Dashboard
  6. [User ID (ユーザーID)]ウィンドウで次を実行します。
    1. [Usage (用途)]ドロップダウンメニューから、[Use Add-ons: Downloadable Content and In-App Purchases Commerce (IAP) (追加コンテンツの使用: ダウンロードコンテンツとアプリ内購入コマース(IAP))]を選択します。
    2. ユーザーIDの使用方法について、詳細な説明を[Description (説明)]に入力します。
    3. (任意)用途をさらに示す補足的なスクリーンショットがあれば追加します。
    4. チェックボックスをクリックして、Metaの利用規約とポリシーに同意します。
    5. [Add to Request (リクエストに追加)]をクリックします。
    User ID details window in the Developer Dashboard
  7. [Request to access platform features (プラットフォーム機能へのアクセスリクエスト)]セクションに戻り、[In-app purchases and/or downloadable content (アプリ内購入やダウンロードコンテンツ)]の横にある[Add (追加)]ボタンをクリックします。新しいウィンドウが開きます。
  8. [In-App Purchases (アプリ内購入)]ウィンドウで次を実行します。
    1. [Usage (用途)]ドロップダウンメニューから、[Use Add-ons: Downloadable Content and In-App Purchases Commerce (IAP) (追加コンテンツの使用: ダウンロードコンテンツとアプリ内購入コマース(IAP))]を選択します。
    2. アプリ内購入の使用方法について、詳細な説明を[Description (説明)]に入力します。
    3. (任意)用途をさらに示す補足的なスクリーンショットがあれば追加します。
    4. チェックボックスをクリックして、Metaの利用規約とポリシー(開発者データ使用ポリシーを含むがこれに限定されません)に同意します。
    5. [Add to Request (リクエストに追加)]をクリックします。
    In-App Purchases details window in the Developer Dashboard
  9. [Data Use Checkup (データの使用状況の確認)]ウィンドウで、[Submit Requests (2) (リクエストを送信(2件))]をクリックします。
    Submit Requests button in the Data Use Checkup window in the Developer Dashboard
  10. リクエストを送信すると、新しいウィンドウが表示されます。[Data handling (データの取り扱い)]セクションのすべての質問に答えて、[Next (次へ)]をクリックします。
    Data handling section in the Data Use Checkup window in the Developer Dashboard
  11. [Review requests (リクエストを確認)]ページの[Your requests (あなたのリクエスト)]セクションの[Added (追加済み)]に、[User ID (ユーザーID)]と[In-app purchases and/or downloadable content (アプリ内購入やダウンロードコンテンツ)]が表示されていることを確認します。[Next (次へ)]をクリックします。
    Review requests in the Data Use Checkup window in the Developer Dashboard
  12. [Submit (送信)]ページで、[Submit for review (審査を申請)]をクリックします。
    Submit button in the Data Use Checkup window in the Developer Dashboard

アドオンとの統合

このセクションでは、構築したアセットをアプリ内購入として提供する方法について説明します。
クライアントアプリから以下のSDKメソッドを呼び出すことができます。各関数について詳しくは、Platform 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()

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

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

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

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

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

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

実装の例

次のUnityの例は、以下のエンドツーエンドのフローを示しています。
  1. IAPアイテムに関する情報の取得
  2. その情報をユーザーに表示する
  3. 未使用の購入品を消費する
  4. ユーザーが購入したいと示したときに、チェックアウトフローを開始する
この例は、「Ultimate Glove Ballサンプルアプリ⁠」GitHubリポジトリから取得したものです。わかりやすさと読みやすさを考慮して、元の形式から編集しています。
コードサンプルと利用可能なサンプルアプリについての詳細は、Unityコードサンプルをご覧ください。

using System;
using System.Collections.Generic;
using Meta.XR.Samples;
using Oculus.Platform;
using Oculus.Platform.Models;
using UnityEngine;

namespace UltimateGloveBall.App
{
    /// <summary>
    /// Manages in-app purchases. It's a wrapper on the Oculus.Platform.IAP functionalities.
    /// This makes it easy to fetch all products and purchases as well as make a purchase.
    /// Referenced from: https://developers.meta.com/horizon/documentation/unity/ps-iap/
    /// </summary>
    [MetaCodeSample("UltimateGloveBall")]
    public class IAPManager
    {
        #region Singleton
        private static IAPManager s_instance;

        public static IAPManager Instance
        {
            get
            {
                s_instance ??= new IAPManager();
                return s_instance;
            }
        }

        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
        public static void DestroyInstance()
        {
            s_instance = null;
        }
        #endregion // Singleton

        /// <summary>
        /// The data we get from the error message json string on purchase
        /// </summary>
        private class PurchaseErrorMessage
        {
            // Since we convert from json the naming must stay the same as the json format, which is all lowercase
            public string category;
            public int code;
            public string message;
        }

        private Dictionary<string, Product> m_products = new();
        private Dictionary<string, Purchase> m_purchases = new();

        private Dictionary<string, List<string>> m_productsByCategory = new();
        private List<string> m_availableSkus = new();
        public IList<string> AvailableSkus => m_availableSkus;

        /// <summary>
        /// Asynchronously fetch all products based on the SKU
        /// </summary>
        public void FetchProducts(string[] skus, string category = null)
        {
            _ = IAP.GetProductsBySKU(skus)?.OnComplete(message =>
            {
                GetProductsBySKUCallback(message, category);
            });
        }

        /// <summary>
        /// Asynchronously fetch all purchases that were made by the user
        /// </summary>
        public void FetchPurchases()
        {
            _ = IAP.GetViewerPurchases()?.OnComplete(GetViewerPurchasesCallback);
        }

        public List<string> GetProductSkusForCategory(string category)
        {
            return m_productsByCategory.TryGetValue(category, out var categorySkus) ? categorySkus : null;
        }

        /// <summary>
        /// Returns a product by SKU, otherwise returns null
        /// </summary>
        public Product GetProduct(string sku)
        {
            if (m_products.TryGetValue(sku, out var product))
            {
                return product;
            }

            Debug.LogError($"[IAPManager] Product {sku} doesn't exist!");
            return null;
        }
        /// <summary>
        /// Returns true if the user has purchased the SKU, false if user has not purchased the SKU or if the SKU doesn't exist
        /// </summary>
        public bool IsPurchased(string sku)
        {
            return m_purchases.TryGetValue(sku, out _);
        }

        /// <summary>
        /// Returns a purchase by SKU, otherwise returns null
        /// </summary>
        public Purchase GetPurchase(string sku)
        {
            return m_purchases.TryGetValue(sku, out var purchase) ? purchase : null;
        }

        /// <summary>
        /// Initiating the checkout flow for a SKU
        /// </summary>
        public void Purchase(string sku, Action<string, bool, string> onPurchaseFlowCompleted)
        {
#if UNITY_EDITOR
            m_purchases[sku] = null; // Keep a reference to the purchase, although purchases cannot be made in Editor
            onPurchaseFlowCompleted?.Invoke(sku, true, null);
#else
            IAP.LaunchCheckoutFlow(sku).OnComplete((Message<Purchase> msg) =>
            {
                if (msg.IsError)
                {
                    var errorMsgString = msg.GetError().Message;
                    Debug.LogError($"[IAPManager] Error while purchasing: {errorMsgString}");
                    var errorData = JsonUtility.FromJson<PurchaseErrorMessage>(errorMsgString);
                    onPurchaseFlowCompleted?.Invoke(sku, false, errorData.message);
                    return;
                }

                var p = msg.GetPurchase();
                Debug.Log("[IAPManager] Purchased " + p.Sku);
                m_purchases[sku] = p;
                onPurchaseFlowCompleted?.Invoke(sku, true, null);
            });
#endif
        }

        /// <summary>
        /// Consume a purchased item on behalf of a user
        /// </summary>
        public void ConsumePurchase(string sku, Action<string, bool> onConsumptionCompleted)
        {
#if UNITY_EDITOR
            m_purchases.Remove(sku);
            onConsumptionCompleted?.Invoke(sku, true);
#else
            _ = IAP.ConsumePurchase(sku).OnComplete(msg =>
            {
                if (msg.IsError)
                {
                    Debug.LogError($"[IAPManager] Error while consuming: {msg.GetError().Message}");
                    onConsumptionCompleted?.Invoke(sku, false);
                    return;
                }

                Debug.Log("[IAPManager] Consumed " + sku);
                m_purchases.Remove(sku);
                onConsumptionCompleted?.Invoke(sku, true);
            });
#endif
        }

        private void GetProductsBySKUCallback(Message<ProductList> msg, string category)
        {
            if (msg.IsError)
            {
                Debug.LogError($"[IAPManager] Failed to fetch products, {msg.GetError().Message}");
                return;
            }

            foreach (var p in msg.GetProductList())
            {
                Debug.LogFormat("[IAPManager] Product: sku:{0} name:{1} price:{2}", p.Sku, p.Name, p.FormattedPrice);
                m_products[p.Sku] = p;
                m_availableSkus.Add(p.Sku);
                if (!string.IsNullOrWhiteSpace(category))
                {
                    if (!m_productsByCategory.TryGetValue(category, out var categorySkus))
                    {
                        categorySkus = new List<string>();
                        m_productsByCategory[category] = categorySkus;
                    }

                    categorySkus.Add(p.Sku);
                }
            }
        }

        private void GetViewerPurchasesCallback(Message<PurchaseList> msg)
        {
            if (msg.IsError)
            {
                Debug.LogError($"[IAPManager] Failed to fetch purchased products, {msg.GetError().Message}");
                return;
            }

            foreach (var p in msg.GetPurchaseList())
            {
                Debug.Log($"[IAPManager] Purchased: sku:{p.Sku} granttime:{p.GrantTime} id:{p.ID}");
                m_purchases[p.Sku] = p;
            }
        }
    }
}
購入ボタンを新しいUnityプロジェクトに接続する手順については、Unityでの収益化のスタートガイドをご覧ください。

無料アプリで有料のフルバージョンをアンロックできるようにする

コンテンツの一部を含む無料のアプリを公開してから、フルバージョンのエクスペリエンスを1つのアプリ内購入として販売できます。これは、収益化モデルを選ぶ - フリープレイモデルで説明されている無料スタートモデルです。
このパターン専用のAPIはプラットフォームにありません。上のアドオンメソッドからそれをアセンブルします。
  1. フルバージョンのアンロックに相当する耐久型アドオンを開発者ダッシュボード⁠で作成し、そのSKUをメモします。耐久型アイテムはユーザーが永続的に所有でき、購入回数も1回なので、永続的なアンロックに適しています。設定手順については、アドオンの設定を参照してください。
  2. 起動時に、Core.Initialize()から成功の報告を受け取ったら、IAP.GetViewerPurchases()を呼び出し、返されたリストの中からそのSKUを探します。
  3. 結果に基づいて有料コンテンツを制限し、アンロックを所有していないユーザーに購入プロンプトを表示します。
  4. ユーザーがプロンプトを承諾したら、SKUを指定してIAP.LaunchCheckoutFlow()を呼び出し、リクエストがエラーなく完了したらコンテンツのロックを解除します。
フルバージョンアンロックがIAP.ConsumePurchase()を呼び出すことは決してありません。アドオンを消費すると再度購入可能になります。これは消費型アイテムに必要な動作です。詳しくは、購入したIAPアイテムの消費をご覧ください。
次の例では、そのフローを実装しています。
using Oculus.Platform;
using Oculus.Platform.Models;
using UnityEngine;

public class FullVersionUnlock : MonoBehaviour
{
    private const string AppId = "YOUR_APP_ID";
    private const string UnlockSku = "YOUR_UNLOCK_SKU";

    public bool HasFullVersion { get; private set; }

    private void Start()
    {
        try
        {
            Core.Initialize(AppId);
        }
        catch (UnityException e)
        {
            // Core.Initialize throws when the platform cannot start, and every IAP
            // call returns null until it does, so open the free tier and check
            // ownership again on the next launch.
            Debug.LogError($"Oculus Platform failed to initialize: {e.Message}");
            SetTrialContent();
            return;
        }

        RefreshOwnership();
    }

    // Read the live ownership list, and fall back to the device cache if it fails.
    private void RefreshOwnership()
    {
        IAP.GetViewerPurchases().OnComplete(message =>
        {
            if (message.IsError)
            {
                Debug.LogError($"GetViewerPurchases failed: {message.GetError().Message}");
                IAP.GetViewerPurchasesDurableCache().OnComplete(OnPurchaseList);
                return;
            }

            OnPurchaseList(message);
        });
    }

    private void OnPurchaseList(Message<PurchaseList> message)
    {
        if (message.IsError)
        {
            // The live call and the cache both failed. Open the free tier so the
            // app stays usable, and check ownership again on the next launch.
            Debug.LogError($"Could not read purchases: {message.GetError().Message}");
            SetTrialContent();
            return;
        }

        PurchaseList purchases = message.GetPurchaseList();

        foreach (Purchase purchase in purchases)
        {
            if (purchase.Sku == UnlockSku)
            {
                SetFullVersionUnlocked();
                return;
            }
        }

        // The list is paginated, so a user who owns many add-ons can carry the
        // unlock on a later page.
        if (purchases.HasNextPage)
        {
            IAP.GetNextPurchaseListPage(purchases).OnComplete(OnPurchaseList);
            return;
        }

        SetTrialContent();
    }

    // Wire this to the buy button on your purchase prompt.
    public void OnBuyFullVersionClicked()
    {
        IAP.LaunchCheckoutFlow(UnlockSku).OnComplete(message =>
        {
            if (message.IsError)
            {
                // When the user dismisses the checkout dialog, Error.Message holds
                // a JSON object whose "category" property is "user_canceled".
                Debug.LogError($"Checkout did not complete: {message.GetError().Message}");
                return;
            }

            SetFullVersionUnlocked();
        });
    }

    private void SetFullVersionUnlocked()
    {
        HasFullVersion = true;

        // Load your paid levels, scenes, or features here.
    }

    private void SetTrialContent()
    {
        HasFullVersion = false;

        // Load your free preview content here.
    }
}
IAP.GetViewerPurchases()は、すべての耐久型の購入品と、アプリで消費されていない消耗型の購入品を返します。そのため、SKU検索は所有リスト全体に対して実行されます。クライアントの結果は参考情報として扱ってください。価値のあるものを配信する前にアイテムの所有権を確認するの方法で独自のサーバーから所有権を確認し、購入後にアプリでダウンロードするアセットファイルとして配信することで、ロックされたコンテンツをメインパッケージから分離します。
このコードを書かずに、有料アプリの時間制限または達成度制限のあるトライアルをユーザーに提供するには、購入前に試すをご覧ください。

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

次のメソッドを使用して、ダウンロード可能コンテンツ(DLC)をアプリに統合できます。アプリに関連付けられたアセットファイルを取得、ダウンロード、管理するには、以下のメソッドを使用します。

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

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

ダウンロードの開始

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