获取远程目录
获取付款提供商商店的 Remote Catalog。
阅读时间2 分钟最后更新于 2 天前
您需要创建一个连接到
StoreControllerRemoteCatalogProviderFetchRemoteCatalogRemoteCatalogProviderFetchProductsIProductServiceStoreControllerFetchProducts参考信息
获取付款提供商的 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}"); } } }}