开发
开发
选择平台

附加组件集成

更新时间: 2025年5月17日
本主题讨论如何将附加组件集成到您的应用。

要求

必须先完成几个要求,才可将附加组件集成到您的应用程序。以下部分概述如何满足前提条件。

设置要购买的商品

开始在应用中集成附加组件之前,需要定义将要购买的商品。有关设置附加组件的指导,请参阅设置附加组件

引擎支持

Unreal 提供了与 Meta Horizon 平台中的附加组件兼容的打包功能。使用 Unreal 时,您会解包。如需了解更多信息,请参阅:

指示应用需要连接网络

对于与可下载内容关联的附加组件,请将您的应用标记为需要连接网络。
  1. 开发者面板中,通过以下方式访问应用规格页面:分发 > 应用提交 > {Your app} > 应用元数据 > 规格
  2. 网络连接下拉菜单中,选择下载可下载内容需要连接网络

启用 IAP 服务

  1. 开发者面板中,按以下路径访问应用服务页面:开发 > 所有平台服务 > 附加组件。点击添加服务
  2. 开发者面板中,按以下路径访问数据使用情况检查页面:要求 > 数据使用情况检查。针对用户编号应用内购买和/或可下载内容,点击添加

与附加组件集成

定义了您想要提供的作为购买对象的商品后,便可以开始将它们作为可购买的商品构建到您的应用中。
对于 Unreal 开发,您可以使用平台原生 API 和平台 Unreal 开发 - 安装设置指南中提供的信息。
可以从您的客户端应用调用以下 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.
ovr_IAP_GetProductsBySKU()
If using the Meta XR Platform SDK, you can call the following blueprint function:
Screenshot of calling the IAP Get Products by SKU blueprint function
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 的购买,请使用以下方法。
ovr_IAP_LaunchCheckoutFlow()
如果使用 Meta XR 平台 SDK,您可以调用以下 blueprint 函数:
Screenshot of calling the IAP Launch Checkout Flow blueprint function

检索用户购买的所有商品

要检索用户已完成的 IAP 购买清单,请使用以下方法。返回的清单包括所有耐用类型购买以及任何尚未消费的消费类型购买。
ovr_IAP_GetViewerPurchases()
如果使用 Meta XR 平台 SDK,您可以调用以下 blueprint 函数:
Screenshot of calling the IAP Get Viewer Purchases` blueprint function

检索用户已购买的耐用商品的缓存清单

要检索用户已购买的耐用附加组件清单,请使用以下方法。返回的清单包含非消耗性购买,并且是从设备缓存中填充的。应始终先使用 GetViewerPurchases,如果其他调用失败,再使用这个方法。
ovr_IAP_GetViewerPurchasesDurableCache()
如果使用 Meta XR 平台 SDK,您可以调用以下 blueprint 函数:
Screenshot of calling the IAP Get Viewer Purchases Durable Cache blueprint function

消费一件已购买的商品

要代表用户消耗已购买的商品(然后将其标记为已在应用中使用过),请使用以下方法。
ovr_IAP_ConsumePurchase()
如果使用 Meta XR 平台 SDK,您可以调用以下 blueprint 函数:
Screenshot of calling the IAP Consume Purchase blueprint function

与可下载内容集成

通过以下方法将可下载内容 (DLC) 与您的应用集成。使用这些方法来检索、下载和管理与您的应用关联的资产文件。

获取与某个应用关联的资产清单

在应用启动时,这种方法会得到与应用相关的所有资产的清单。
ovr_AssetFile_GetList
如果使用 Meta XR 平台 SDK,您可以调用以下 blueprint 函数:
Screenshot of calling the Asset File Get list blueprint function
此方法返回可用资产详细信息清单。阵列中的每个商品都有以下属性:
  • assetFileName - 文件名,
  • assetFileID - 资产标识符
  • IapStatus,是以下值之一:freeentitlednot-entitled
  • downloadStatus,这是以下值之一:
    • installed 表示用户安装了文件
    • available 表示用户可以下载文件
    • in-progress 表示文件正在下载或正在为该用户安装。

启动下载

如果有一个文件可供下载,即其状态为免费或有权下载,并且 download_status = available,您可以通过调用以下方式来启动下载:
  • ovr_AssetFile_DownloadById
如果使用 Meta XR 平台 SDK,您可以调用以下 blueprint 函数:
Screenshot of calling the Asset File Download by Id blueprint function
要进行此调用,需要传递由初始 GetList 调用返回的商品编号。
进行此调用后,您将立即收到一个包含资源路径的 DownloadResult 响应,以确认请求已成功。您还应该侦听 DownloadUpdate 通知,该通知会返回有关已传输字节的信息以及一个完成标志,当下载完成时,该标志会通知您。