暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PayoutDefinition.cs 5.3KB

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