PayoutDefinition.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. get {
  25. return m_Type;
  26. }
  27. private set {
  28. m_Type = value;
  29. }
  30. }
  31. /// <summary>
  32. /// Type of the payout as a string
  33. /// </summary>
  34. public string typeString {
  35. get {
  36. return m_Type.ToString ();
  37. }
  38. }
  39. /// <summary>
  40. /// Maximum string length of the payout subtype
  41. /// </summary>
  42. public const int MaxSubtypeLength = 64;
  43. /// <summary>
  44. /// Subtype of the payout
  45. /// </summary>
  46. public string subtype {
  47. get {
  48. return m_Subtype;
  49. }
  50. private set {
  51. if (value.Length > MaxSubtypeLength)
  52. throw new ArgumentException(string.Format("subtype cannot be longer than {0}", MaxSubtypeLength));
  53. m_Subtype = value;
  54. }
  55. }
  56. /// <summary>
  57. /// Quantity or value of the payout
  58. /// </summary>
  59. public double quantity {
  60. get {
  61. return m_Quantity;
  62. }
  63. private set {
  64. m_Quantity = value;
  65. }
  66. }
  67. /// <summary>
  68. /// Maximum number of bytes of the payout data
  69. /// </summary>
  70. public const int MaxDataLength = 1024;
  71. /// <summary>
  72. /// Payload data of the payout
  73. /// </summary>
  74. public string data {
  75. get {
  76. return m_Data;
  77. }
  78. private set {
  79. if (value.Length > MaxDataLength)
  80. throw new ArgumentException (string.Format ("data cannot be longer than {0}", MaxDataLength));
  81. m_Data = value;
  82. }
  83. }
  84. /// <summary>
  85. /// Default constructor
  86. /// </summary>
  87. public PayoutDefinition()
  88. {
  89. }
  90. /// <summary>
  91. /// Parametrized constructor
  92. /// </summary>
  93. /// <param name="typeString"> The payout type, as a string. </param>
  94. /// <param name="subtype"> The payout subtype. </param>
  95. /// <param name="quantity"> The payout quantity. </param>
  96. public PayoutDefinition (string typeString, string subtype, double quantity) : this (typeString, subtype, quantity, string.Empty)
  97. {
  98. }
  99. /// <summary>
  100. /// Parametrized constructor
  101. /// </summary>
  102. /// <param name="typeString"> The payout type, as a string. </param>
  103. /// <param name="subtype"> The payout subtype. </param>
  104. /// <param name="quantity"> The payout quantity. </param>
  105. /// <param name="data"> The payout data. </param>
  106. public PayoutDefinition (string typeString, string subtype, double quantity, string data)
  107. {
  108. PayoutType t = PayoutType.Other;
  109. if (Enum.IsDefined(typeof(PayoutType), typeString))
  110. t = (PayoutType)Enum.Parse (typeof (PayoutType), typeString);
  111. this.type = t;
  112. this.subtype = subtype;
  113. this.quantity = quantity;
  114. this.data = data;
  115. }
  116. /// <summary>
  117. /// Parametrized constructor
  118. /// </summary>
  119. /// <param name="subtype"> The payout subtype. </param>
  120. /// <param name="quantity"> The payout quantity. </param>
  121. public PayoutDefinition (string subtype, double quantity) : this (PayoutType.Other, subtype, quantity, string.Empty)
  122. {
  123. }
  124. /// <summary>
  125. /// Parametrized constructor
  126. /// </summary>
  127. /// <param name="subtype"> The payout subtype. </param>
  128. /// <param name="quantity"> The payout quantity. </param>
  129. /// <param name="data"> The payout data. </param>
  130. public PayoutDefinition (string subtype, double quantity, string data) : this (PayoutType.Other, subtype, quantity, data)
  131. {
  132. }
  133. /// <summary>
  134. /// Parametrized constructor
  135. /// </summary>
  136. /// <param name="type"> The payout type. </param>
  137. /// <param name="subtype"> The payout subtype. </param>
  138. /// <param name="quantity"> The payout quantity. </param>
  139. public PayoutDefinition (PayoutType type, string subtype, double quantity) : this (type, subtype, quantity, string.Empty)
  140. {
  141. }
  142. /// <summary>
  143. /// Parametrized constructor
  144. /// </summary>
  145. /// <param name="type"> The payout type. </param>
  146. /// <param name="subtype"> The payout subtype. </param>
  147. /// <param name="quantity"> The payout quantity. </param>
  148. /// <param name="data"> The payout data. </param>
  149. public PayoutDefinition (PayoutType type, string subtype, double quantity, string data)
  150. {
  151. this.type = type;
  152. this.subtype = subtype;
  153. this.quantity = quantity;
  154. this.data = data;
  155. }
  156. }
  157. }