using System; using System.Collections.Generic; using UnityEngine; namespace UnityEngine.Purchasing { /// /// Definition of a purchase payout /// [Serializable] public class PayoutDefinition { [SerializeField] PayoutType m_Type = PayoutType.Other; [SerializeField] string m_Subtype = string.Empty; [SerializeField] double m_Quantity; [SerializeField] string m_Data = string.Empty; /// /// Type of the payout /// public PayoutType type { get => m_Type; private set => m_Type = value; } /// /// Type of the payout as a string /// public string typeString => m_Type.ToString(); /// /// Maximum string length of the payout subtype /// public const int MaxSubtypeLength = 64; /// /// Subtype of the payout /// public string subtype { get => m_Subtype; private set { if (value.Length > MaxSubtypeLength) { throw new ArgumentException(string.Format("subtype cannot be longer than {0}", MaxSubtypeLength)); } m_Subtype = value; } } /// /// Quantity or value of the payout /// public double quantity { get => m_Quantity; private set => m_Quantity = value; } /// /// Maximum number of bytes of the payout data /// public const int MaxDataLength = 1024; /// /// Payload data of the payout /// public string data { get => m_Data; private set { if (value.Length > MaxDataLength) { throw new ArgumentException(string.Format("data cannot be longer than {0}", MaxDataLength)); } m_Data = value; } } /// /// Default constructor /// public PayoutDefinition() { } /// /// Parametrized constructor /// /// The payout type, as a string. /// The payout subtype. /// The payout quantity. public PayoutDefinition(string typeString, string subtype, double quantity) : this(typeString, subtype, quantity, string.Empty) { } /// /// Parametrized constructor /// /// The payout type, as a string. /// The payout subtype. /// The payout quantity. /// The payout data. public PayoutDefinition(string typeString, string subtype, double quantity, string data) { var t = PayoutType.Other; if (Enum.IsDefined(typeof(PayoutType), typeString)) { t = (PayoutType)Enum.Parse(typeof(PayoutType), typeString); } type = t; this.subtype = subtype; this.quantity = quantity; this.data = data; } /// /// Parametrized constructor /// /// The payout subtype. /// The payout quantity. public PayoutDefinition(string subtype, double quantity) : this(PayoutType.Other, subtype, quantity, string.Empty) { } /// /// Parametrized constructor /// /// The payout subtype. /// The payout quantity. /// The payout data. public PayoutDefinition(string subtype, double quantity, string data) : this(PayoutType.Other, subtype, quantity, data) { } /// /// Parametrized constructor /// /// The payout type. /// The payout subtype. /// The payout quantity. public PayoutDefinition(PayoutType type, string subtype, double quantity) : this(type, subtype, quantity, string.Empty) { } /// /// Parametrized constructor /// /// The payout type. /// The payout subtype. /// The payout quantity. /// The payout data. public PayoutDefinition(PayoutType type, string subtype, double quantity, string data) { this.type = type; this.subtype = subtype; this.quantity = quantity; this.data = data; } } }