Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ProductDefinition.cs 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEngine.Purchasing
  4. {
  5. /// <summary>
  6. /// Product definition used by Apps declaring products for sale.
  7. /// </summary>
  8. public class ProductDefinition
  9. {
  10. /// <summary>
  11. /// Default constructor
  12. /// </summary>
  13. private ProductDefinition()
  14. {
  15. }
  16. /// <summary>
  17. /// Parametrized constructor
  18. /// </summary>
  19. /// <param name="id"> The product id. </param>
  20. /// <param name="storeSpecificId"> The product's id for a specific store. </param>
  21. /// <param name="type"> The product type. </param>
  22. public ProductDefinition(string id, string storeSpecificId, ProductType type) : this(id, storeSpecificId, type, true)
  23. {
  24. }
  25. /// <summary>
  26. /// Parametrized constructor
  27. /// </summary>
  28. /// <param name="id"> The product id. </param>
  29. /// <param name="storeSpecificId"> The product's id for a specific store. </param>
  30. /// <param name="type"> The product type. </param>
  31. /// <param name="enabled"> Whether the product is enabled for purchase or not. </param>
  32. public ProductDefinition(string id, string storeSpecificId, ProductType type, bool enabled) : this(id, storeSpecificId, type, enabled, (IEnumerable<PayoutDefinition>)null)
  33. {
  34. }
  35. /// <summary>
  36. /// Parametrized constructor
  37. /// </summary>
  38. /// <param name="id"> The product id. </param>
  39. /// <param name="storeSpecificId"> The product's id for a specific store. </param>
  40. /// <param name="type"> The product type. </param>
  41. /// <param name="enabled"> Whether the product is enabled for purchase or not. </param>
  42. /// <param name="payout"> The payout definition for the product once purchased. </param>
  43. public ProductDefinition(string id, string storeSpecificId, ProductType type, bool enabled, PayoutDefinition payout) : this(id, storeSpecificId, type, enabled, new List<PayoutDefinition> { payout })
  44. {
  45. }
  46. /// <summary>
  47. /// Parametrized constructor
  48. /// </summary>
  49. /// <param name="id"> The product id. </param>
  50. /// <param name="storeSpecificId"> The product's id for a specific store. </param>
  51. /// <param name="type"> The product type. </param>
  52. /// <param name="enabled"> Whether the product is enabled for purchase or not. </param>
  53. /// <param name="payouts"> The payout definitions for the product once purchased. </param>
  54. public ProductDefinition(string id, string storeSpecificId, ProductType type, bool enabled, IEnumerable<PayoutDefinition> payouts)
  55. {
  56. this.id = id;
  57. this.storeSpecificId = storeSpecificId;
  58. this.type = type;
  59. this.enabled = enabled;
  60. SetPayouts(payouts);
  61. }
  62. /// <summary>
  63. /// Parametrized constructor, creating a ProductDefinition where the id is the same as the store specific ID.
  64. /// </summary>
  65. /// <param name="id"> The product id as well as its store-specific id. </param>
  66. /// <param name="type"> The product type. </param>
  67. public ProductDefinition(string id, ProductType type) : this(id, id, type)
  68. {
  69. }
  70. /// <summary>
  71. /// Store independent ID.
  72. /// </summary>
  73. public string id { get; private set; }
  74. /// <summary>
  75. /// The ID this product has on a specific store.
  76. /// </summary>
  77. public string storeSpecificId { get; private set; }
  78. /// <summary>
  79. /// The type of the product.
  80. /// </summary>
  81. public ProductType type { get; private set; }
  82. /// <summary>
  83. /// Whether or not the product is enabled for purchase.
  84. /// </summary>
  85. public bool enabled { get; private set; }
  86. /// <summary>
  87. /// Check if this product definition is equal to another.
  88. /// </summary>
  89. /// <param name="obj"> The product definition to compare with this object. </param>
  90. /// <returns> True if the definitions are equal </returns>
  91. public override bool Equals(object obj)
  92. {
  93. if (obj == null)
  94. {
  95. return false;
  96. }
  97. var p = obj as ProductDefinition;
  98. if (p == null)
  99. {
  100. return false;
  101. }
  102. return id == p.id;
  103. }
  104. /// <summary>
  105. /// Get the unique Hash representing the product definition.
  106. /// </summary>
  107. /// <returns> The hash code as integer </returns>
  108. public override int GetHashCode()
  109. {
  110. return id.GetHashCode();
  111. }
  112. private readonly List<PayoutDefinition> m_Payouts = new List<PayoutDefinition>();
  113. /// <summary>
  114. /// Gets all payouts attached to this product.
  115. /// </summary>
  116. /// <value>The payouts.</value>
  117. public IEnumerable<PayoutDefinition> payouts => m_Payouts;
  118. /// <summary>
  119. /// Gets the first attached payout. This is a shortcut for the case where only one payout is attached to the product.
  120. /// </summary>
  121. /// <value>The payout.</value>
  122. public PayoutDefinition payout => m_Payouts.Count > 0 ? m_Payouts[0] : null;
  123. /// <summary>
  124. /// Update this product's payouts
  125. /// </summary>
  126. /// <param name="newPayouts">A set of payouts to replace the current payouts on this product definition</param>
  127. internal void SetPayouts(IEnumerable<PayoutDefinition> newPayouts)
  128. {
  129. if (newPayouts == null)
  130. {
  131. return;
  132. }
  133. m_Payouts.Clear();
  134. m_Payouts.AddRange(newPayouts);
  135. }
  136. }
  137. }