Version: 2017.1

Product

class in UnityEngine.Purchasing

Cambiar al Manual

Descripción

Represents a product that may be purchased as an In-App Purchase.

Here is an example of a sample Store class working with a Product referencs.

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) {} }

Variables

availableToPurchaseDetermine if this product is available to purchase according to the store subsystem.
definitionFundamental immutable product properties.
hasReceiptOwned Non Consumables and Subscriptions should always have receipts.
metadataLocalized metadata provided by the store system.
receiptThe purchase receipt for this product, if owned. Otherwise null.
transactionIDA unique identifier for this product's transaction, if available. Otherwise null.

Funciones Públicas

EqualsEquality defined for use in collections.
GetHashCodeGetHashCode defined for use in collections.
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961