using System; using System.Collections.Generic; namespace UnityEngine.Purchasing { /// /// Product definition used by Apps declaring products for sale. /// public class ProductDefinition { /// /// Default constructor /// private ProductDefinition() { } /// /// Parametrized constructor /// /// The product id. /// The product's id for a specific store. /// The product type. public ProductDefinition(string id, string storeSpecificId, ProductType type) : this(id, storeSpecificId, type, true) { } /// /// Parametrized constructor /// /// The product id. /// The product's id for a specific store. /// The product type. /// Whether the product is enabled for purchase or not. public ProductDefinition(string id, string storeSpecificId, ProductType type, bool enabled) : this(id, storeSpecificId, type, enabled, (IEnumerable)null) { } /// /// Parametrized constructor /// /// The product id. /// The product's id for a specific store. /// The product type. /// Whether the product is enabled for purchase or not. /// The payout definition for the product once purchased. public ProductDefinition(string id, string storeSpecificId, ProductType type, bool enabled, PayoutDefinition payout) : this(id, storeSpecificId, type, enabled, new List { payout }) { } /// /// Parametrized constructor /// /// The product id. /// The product's id for a specific store. /// The product type. /// Whether the product is enabled for purchase or not. /// The payout definitions for the product once purchased. public ProductDefinition(string id, string storeSpecificId, ProductType type, bool enabled, IEnumerable payouts) { this.id = id; this.storeSpecificId = storeSpecificId; this.type = type; this.enabled = enabled; SetPayouts(payouts); } /// /// Parametrized constructor, creating a ProductDefinition where the id is the same as the store specific ID. /// /// The product id as well as its store-specific id. /// The product type. public ProductDefinition(string id, ProductType type) : this(id, id, type) { } /// /// Store independent ID. /// public string id { get; private set; } /// /// The ID this product has on a specific store. /// public string storeSpecificId { get; private set; } /// /// The type of the product. /// public ProductType type { get; private set; } /// /// Whether or not the product is enabled for purchase. /// public bool enabled { get; private set; } /// /// Check if this product definition is equal to another. /// /// The product definition to compare with this object. /// True if the definitions are equal public override bool Equals(object obj) { if (obj == null) { return false; } var p = obj as ProductDefinition; if (p == null) { return false; } return id == p.id; } /// /// Get the unique Hash representing the product definition. /// /// The hash code as integer public override int GetHashCode() { return id.GetHashCode(); } private readonly List m_Payouts = new List(); /// /// Gets all payouts attached to this product. /// /// The payouts. public IEnumerable payouts => m_Payouts; /// /// Gets the first attached payout. This is a shortcut for the case where only one payout is attached to the product. /// /// The payout. public PayoutDefinition payout => m_Payouts.Count > 0 ? m_Payouts[0] : null; /// /// Update this product's payouts /// /// A set of payouts to replace the current payouts on this product definition internal void SetPayouts(IEnumerable newPayouts) { if (newPayouts == null) { return; } m_Payouts.Clear(); m_Payouts.AddRange(newPayouts); } } }