获取远程目录
获取付款提供商商店的 Remote Catalog。
阅读时间2 分钟最后更新于 1 个月前
要获取付款提供商商店的 Remote Catalog,您需要实例化 ,然后调用 从 Unity IAP 后端检索商品。
RemoteCatalogProviderFetchRemoteCatalog然后,您可以直接使用 调用 ,也可以从 或 将商品列表传递给 。
RemoteCatalogProviderFetchProductsIProductServiceStoreControllerFetchProducts参考信息
获取付款提供商的 Remote Catalog 时,以下元素相关:
参数 | 描述 |
|---|---|
| 该类用于获取要与 IAP 一起使用的 Remote Catalog。远程目录是从 IAP 后端获取的。 |
| 这是与 IAP 通信的起点。您需要获得以下服务:
|
| 这是 |
| 这是用于向 |
获取 Remote Catalog 示例脚本
请参阅以下 脚本示例:
using System.Collections.Generic;using System.Threading.Tasks;using UnityEngine;using UnityEngine.Purchasing;public class PurchaseManager :MonoBehaviour{ StoreController m_StoreController; // Called by the ServiceOrchestrator after Auth is complete public async Task InitializeIAP() { m_StoreController = UnityIAPServices.StoreController(PaymentProvider.Name); m_StoreController.OnPurchasePending += OnPurchasePending; await m_StoreController.Connect(); m_StoreController.OnProductsFetch += OnProductsFetch; // 1.初始化 RemoteCatalogProvider RemoteCatalogProvider catalogProvider = new RemoteCatalogProvider(); // 2.为支付提供商显式获取目录 var fetchRemoteCatalogResult = await catalogProvider.FetchRemoteCatalog(); if (!fetchRemoteCatalogResult.Success) throw fetchRemoteCatalogResult.Exception!; // 3.将远程定义传递给 StoreController var productDefinitions = catalogProvider.GetProducts(); m_StoreController.FetchProducts(productDefinitions); } private void OnPurchasePending(PendingOrder order) { // Handle purchase validation and rewarding before confirming the order Debug.Log($"Order pending: {order.Info}"); } void OnProductsFetched(List<Product> products) { // Handle fetched products (e.g., populate UI) Debug.Log("Fetched products:"); foreach(商品中不同商品) { foreach(var catalogListing in product.catalogListings.Values) { Debug.Log($"ID: {catalogListing.definition.id} - Price: {catalogListing.metadata.localizedPriceString}"); } } }}
后续步骤
本页面是使用 IAP 设置 D2C 支付提供商的工作流程的一部分。要继续此工作流程,请选择以下选项之一: