Version: 2017.1

Product

class in UnityEngine.Purchasing

切换到手册

描述

表示可在应用内购买的商品。

下面是将示例商店类与商品引用配合使用的示例。

using System;
using UnityEngine;
using UnityEngine.Purchasing;

public class MyStoreClass : MonoBehaviour, IStoreListener { static string kProductID100Currency = "virtualcurrency_100"; IStoreController m_StoreController; void Awake() { ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance()); builder.AddProduct(kProductID100Currency, ProductType.Consumable); UnityPurchasing.Initialize(this, builder); }

public void PurchaseCurrency() { if (m_StoreController != null) { // Fetch the currency Product reference from Unity Purchasing Product product = m_StoreController.products.WithID(kProductID100Currency); if (product != null && product.availableToPurchase) { m_StoreController.InitiatePurchase(product); } } }

public void OnInitialized(IStoreController controller, IExtensionProvider extensions) { m_StoreController = controller; }

public void OnInitializeFailed(InitializationFailureReason error) {} public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) { if (String.Equals(e.purchasedProduct.definition.id, kProductID100Currency, StringComparison.Ordinal)) { Debug.Log("Purchased 100 coins"); } return PurchaseProcessingResult.Complete; }

public void OnPurchaseFailed(Product item, PurchaseFailureReason r) {} }

变量

availableToPurchase根据商店子系统确定此商品是否可购买。
definition不可变的基本商品属性。
hasReceipt所拥有的非消耗品和订阅内容应始终有收据。
metadata商店系统提供的本地化元数据。
receipt此商品的购买收据(如果拥有);否则为 null。
transactionID此商品交易的唯一标识符(如果有);否则为 null。

公共函数

Equals用于集合的定义的等式。
GetHashCode用于集合的定义的 GetHashCode。