Version: 2017.1

IStore

interface in UnityEngine.Purchasing.Extension

切换到手册

描述

通常向 Unity IAP 公开的底层商店系统(例如 Google Play 或 Apple App Store)的公共接口,用于扩展其应用内购买平台支持。

Unity IAP 是可扩展的,支持通过 IPurchasingModule 实现注册商店系统,这些实现可在初始化期间通过 ConfigurationBuilder 与 Unity IAP 分享。

商店类示例:

using System;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using UnityEngine.Purchasing;
using UnityEngine.Purchasing.Extension;

// Purchases always succeed at the sample store internal class SampleStore : IStore { public const string Name = "samplestore"; private IStoreCallback m_Biller; private List<string> m_PurchasedProducts = new List<string>();

public void Initialize(IStoreCallback biller) { m_Biller = biller; }

public void RetrieveProducts(ReadOnlyCollection<ProductDefinition> productDefinitions) { var products = new List<ProductDescription>(); foreach (var product in productDefinitions) { var metadata = new ProductMetadata("$123.45", "Fake title for " + product.id, "Fake description", "USD", 123.45m); products.Add(new ProductDescription(product.storeSpecificId, metadata)); } m_Biller.OnProductsRetrieved(products); }

public void Purchase(ProductDefinition product, string developerPayload) { // Keep track of non consumables. if (product.type != ProductType.Consumable) { m_PurchasedProducts.Add(product.storeSpecificId); } m_Biller.OnPurchaseSucceeded(product.storeSpecificId, "{ \"this\" : \"is a fake receipt\" }", Guid.NewGuid().ToString()); }

public void FinishTransaction(ProductDefinition product, string transactionId) { } }

公共函数

FinishTransaction系统记录交易后由 Unity IAP 调用。
Initialize初始化商店。
Purchase处理来自用户的购买请求。
RetrieveProducts获取商品包括购买收据在内的最新元数据,与通过 IStoreCallback 返回的结果异步。