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) {} }
availableToPurchase | Determine if this product is available to purchase according to the store subsystem. |
definition | Fundamental immutable product properties. |
hasReceipt | Owned Non Consumables and Subscriptions should always have receipts. |
metadata | Localized metadata provided by the store system. |
receipt | The purchase receipt for this product, if owned. Otherwise null. |
transactionID | A unique identifier for this product's transaction, if available. Otherwise null. |
Equals | Equality defined for use in collections. |
GetHashCode | GetHashCode defined for use in collections. |
Did you find this page useful? Please give it a rating: