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