-
Notifications
You must be signed in to change notification settings - Fork 0
/
IAPGetProductInfo.cs
143 lines (107 loc) · 3.22 KB
/
IAPGetProductInfo.cs
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
// (c) Copyright HutongGames, LLC 2010-2017. All rights reserved.
using UnityEngine;
using UnityEngine.Purchasing;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory("IAP")]
[Tooltip("Get information about existing product by ID in the Unity IAP catalog.")]
public class IAPGetProductInfo : FsmStateAction
{
[RequiredField]
[Tooltip("Enter the product ID")]
public FsmString productId;
[ActionSection("Results")]
[UIHint(UIHint.Variable)]
public FsmString productTitle;
[UIHint(UIHint.Variable)]
public FsmString productDescription;
[UIHint(UIHint.Variable)]
[ObjectType(typeof(ProductType))]
public FsmEnum productEnum;
[ActionSection("Options")]
public FsmBool everyFrame;
private string _productId;
private bool checkProduct;
public override void Reset()
{
everyFrame = false;
productTitle = null;
productDescription = null;
}
public override void OnEnter()
{
doCheck();
if (!everyFrame.Value)
Finish();
}
public override void OnUpdate()
{
doCheck();
}
void doCheck()
{
_productId = productId.Value;
checkProduct = StoreManager.Instance.HasProductInCatalog(_productId);
if(checkProduct)
{
StoreManager.Instance.productInformation(_productId);
productTitle.Value = StoreManager.Instance.currentProduct.defaultDescription.Title;
productDescription.Value = StoreManager.Instance.currentProduct.defaultDescription.Description;
productEnum.Value = StoreManager.Instance.currentProduct.type;
}
else
{
Debug.Log("This product does not exist in your catalog. Do you have the right product ID?");
return;
}
}
public class StoreManager
{
private static StoreManager instance = new StoreManager();
private ProductCatalog catalog;
public ProductCatalogItem currentProduct;
private StoreManager()
{
catalog = ProductCatalog.LoadDefaultCatalog();
StandardPurchasingModule module = StandardPurchasingModule.Instance();
ConfigurationBuilder builder = ConfigurationBuilder.Instance(module);
foreach (var product in catalog.allProducts) {
if (product.allStoreIDs.Count > 0) {
var ids = new IDs();
foreach (var storeID in product.allStoreIDs) {
ids.Add(storeID.id, storeID.store);
}
builder.AddProduct(product.id, product.type, ids);
} else {
builder.AddProduct(product.id, product.type);
}
}
}
public static StoreManager Instance {
get {
return instance;
}
}
// Check to See if Items Exist in Catalog
public bool HasProductInCatalog(string productID)
{
foreach (var product in catalog.allProducts) {
if (product.id == productID) {
return true;
}
}
return false;
}
// Get Product Information
public void productInformation(string productID)
{
foreach (var product in catalog.allProducts) {
if (product.id == productID)
{
currentProduct = product;
}
}
}
}
}
}