PayoutDefinition.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using System;
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. namespace UnityEngine.Purchasing
  5. {
  6. /// <summary>
  7. /// Definition of a purchase payout
  8. /// </summary>
  9. [Serializable]
  10. public class PayoutDefinition
  11. {
  12. [SerializeField]
  13. PayoutType m_Type = PayoutType.Other;
  14. [SerializeField]
  15. string m_Subtype = string.Empty;
  16. [SerializeField]
  17. double m_Quantity;
  18. [SerializeField]
  19. string m_Data = string.Empty;
  20. /// <summary>
  21. /// Type of the payout
  22. /// </summary>
  23. public PayoutType type
  24. {
  25. get
  26. {
  27. return m_Type;
  28. }
  29. private set
  30. {
  31. m_Type = value;
  32. }
  33. }
  34. /// <summary>
  35. /// Type of the payout as a string
  36. /// </summary>
  37. public string typeString
  38. {
  39. get
  40. {
  41. return m_Type.ToString();
  42. }
  43. }
  44. /// <summary>
  45. /// Maximum string length of the payout subtype
  46. /// </summary>
  47. public const int MaxSubtypeLength = 64;
  48. /// <summary>
  49. /// Subtype of the payout
  50. /// </summary>
  51. public string subtype
  52. {
  53. get
  54. {
  55. return m_Subtype;
  56. }
  57. private set
  58. {
  59. if (value.Length > MaxSubtypeLength)
  60. throw new ArgumentException(string.Format("subtype cannot be longer than {0}", MaxSubtypeLength));
  61. m_Subtype = value;
  62. }
  63. }
  64. /// <summary>
  65. /// Quantity or value of the payout
  66. /// </summary>
  67. public double quantity
  68. {
  69. get
  70. {
  71. return m_Quantity;
  72. }
  73. private set
  74. {
  75. m_Quantity = value;
  76. }
  77. }
  78. /// <summary>
  79. /// Maximum number of bytes of the payout data
  80. /// </summary>
  81. public const int MaxDataLength = 1024;
  82. /// <summary>
  83. /// Payload data of the payout
  84. /// </summary>
  85. public string data
  86. {
  87. get
  88. {
  89. return m_Data;
  90. }
  91. private set
  92. {
  93. if (value.Length > MaxDataLength)
  94. throw new ArgumentException(string.Format("data cannot be longer than {0}", MaxDataLength));
  95. m_Data = value;
  96. }
  97. }
  98. /// <summary>
  99. /// Default constructor
  100. /// </summary>
  101. public PayoutDefinition()
  102. {
  103. }
  104. /// <summary>
  105. /// Parametrized constructor
  106. /// </summary>
  107. /// <param name="typeString"> The payout type, as a string. </param>
  108. /// <param name="subtype"> The payout subtype. </param>
  109. /// <param name="quantity"> The payout quantity. </param>
  110. public PayoutDefinition(string typeString, string subtype, double quantity) : this(typeString, subtype, quantity, string.Empty)
  111. {
  112. }
  113. /// <summary>
  114. /// Parametrized constructor
  115. /// </summary>
  116. /// <param name="typeString"> The payout type, as a string. </param>
  117. /// <param name="subtype"> The payout subtype. </param>
  118. /// <param name="quantity"> The payout quantity. </param>
  119. /// <param name="data"> The payout data. </param>
  120. public PayoutDefinition(string typeString, string subtype, double quantity, string data)
  121. {
  122. PayoutType t = PayoutType.Other;
  123. if (Enum.IsDefined(typeof(PayoutType), typeString))
  124. t = (PayoutType)Enum.Parse(typeof(PayoutType), typeString);
  125. this.type = t;
  126. this.subtype = subtype;
  127. this.quantity = quantity;
  128. this.data = data;
  129. }
  130. /// <summary>
  131. /// Parametrized constructor
  132. /// </summary>
  133. /// <param name="subtype"> The payout subtype. </param>
  134. /// <param name="quantity"> The payout quantity. </param>
  135. public PayoutDefinition(string subtype, double quantity) : this(PayoutType.Other, subtype, quantity, string.Empty)
  136. {
  137. }
  138. /// <summary>
  139. /// Parametrized constructor
  140. /// </summary>
  141. /// <param name="subtype"> The payout subtype. </param>
  142. /// <param name="quantity"> The payout quantity. </param>
  143. /// <param name="data"> The payout data. </param>
  144. public PayoutDefinition(string subtype, double quantity, string data) : this(PayoutType.Other, subtype, quantity, data)
  145. {
  146. }
  147. /// <summary>
  148. /// Parametrized constructor
  149. /// </summary>
  150. /// <param name="type"> The payout type. </param>
  151. /// <param name="subtype"> The payout subtype. </param>
  152. /// <param name="quantity"> The payout quantity. </param>
  153. public PayoutDefinition(PayoutType type, string subtype, double quantity) : this(type, subtype, quantity, string.Empty)
  154. {
  155. }
  156. /// <summary>
  157. /// Parametrized constructor
  158. /// </summary>
  159. /// <param name="type"> The payout type. </param>
  160. /// <param name="subtype"> The payout subtype. </param>
  161. /// <param name="quantity"> The payout quantity. </param>
  162. /// <param name="data"> The payout data. </param>
  163. public PayoutDefinition(PayoutType type, string subtype, double quantity, string data)
  164. {
  165. this.type = type;
  166. this.subtype = subtype;
  167. this.quantity = quantity;
  168. this.data = data;
  169. }
  170. }
  171. }