@@ -16,7 +16,13 @@ public class LootLockerVirtualStore : MonoBehaviour
16
16
public string catalogKey = "" ;
17
17
public string walletID = "" ;
18
18
19
- private string currencyCode ;
19
+ private string playerUlid = "" ;
20
+
21
+ private string currencyCode = "gld" ;
22
+ private string currencyDisplayCode = "" ;
23
+ private string currencyIdentifier = "" ;
24
+
25
+ private string grantCurrencyAmount = "200" ;
20
26
21
27
public void Awake ( )
22
28
{
@@ -33,12 +39,37 @@ public void Awake()
33
39
{
34
40
if ( ! response . success )
35
41
{
36
- Debug . Log ( "Could not start guest session" ) ;
42
+ Debug . Log ( "Could not start guest session\n Error: " + response . errorData . ToString ( ) ) ;
43
+ return ;
44
+ }
45
+
46
+ playerUlid = response . player_ulid ;
47
+
48
+ FetchGameCurrencies ( ) ;
49
+ } ) ;
50
+ }
51
+
52
+ public void FetchGameCurrencies ( )
53
+ {
54
+ LootLockerSDKManager . ListCurrencies ( ( response ) =>
55
+ {
56
+
57
+ if ( ! response . success )
58
+ {
59
+ Debug . Log ( "Could not find Currencies\n Error: " + response . errorData . ToString ( ) ) ;
37
60
return ;
38
61
}
39
- FetchPlayerWallet ( response . player_ulid ) ;
40
- FetchVirtualProductsFromCatalog ( ) ;
41
62
63
+ foreach ( var currency in response . currencies )
64
+ {
65
+ if ( currency . code == currencyCode )
66
+ {
67
+ currencyIdentifier = currency . id ;
68
+ currencyDisplayCode = currency . code . ToUpper ( ) + ": " ;
69
+ }
70
+ }
71
+
72
+ FetchPlayerWallet ( playerUlid ) ;
42
73
} ) ;
43
74
}
44
75
@@ -48,13 +79,15 @@ public void FetchPlayerWallet(string ulid)
48
79
{
49
80
if ( ! response . success )
50
81
{
51
- Debug . Log ( "Could not start guest session" ) ;
82
+ Debug . Log ( "Could not Get Players Wallet \n Error: " + response . errorData . ToString ( ) ) ;
52
83
return ;
53
84
}
54
85
55
86
walletID = response . id ;
56
- GiveGold ( ) ;
57
87
88
+ FetchVirtualProductsFromCatalog ( ) ;
89
+
90
+ GiveGold ( ) ;
58
91
} ) ;
59
92
}
60
93
@@ -64,36 +97,27 @@ public void GetPlayerGold()
64
97
{
65
98
if ( ! response . success )
66
99
{
67
- Debug . Log ( "Could not list balances" ) ;
100
+ Debug . Log ( "Could not list balances\n Error: " + response . errorData . ToString ( ) ) ;
68
101
return ;
69
102
}
70
103
71
- //Default to hard coded variables
72
- if ( response . balances . Length <= 0 )
73
- {
74
- currencyCode = "GLD: " ;
75
- return ;
76
- }
77
- currencyCode = response . balances [ 0 ] . currency . code . ToUpper ( ) + ": " ;
104
+ goldAmount . text = currencyDisplayCode + response . balances [ 0 ] . amount ;
78
105
79
- goldAmount . text = currencyCode + response . balances [ 0 ] . amount ;
80
106
} ) ;
81
107
}
82
108
83
-
84
109
public void FetchVirtualProductsFromCatalog ( )
85
110
{
86
111
LootLockerSDKManager . ListCatalogItems ( catalogKey , 0 , "" , ( response ) =>
87
112
{
88
113
if ( ! response . success )
89
114
{
90
- Debug . Log ( "Could not fetch Catalog Items" ) ;
115
+ Debug . Log ( "Could not fetch Catalog Items\n Error: " + response . errorData . ToString ( ) ) ;
91
116
return ;
92
117
}
93
118
94
119
foreach ( var item in response . entries )
95
120
{
96
- Debug . Log ( "Item: " + item . entity_name + " | " + item . prices [ 0 ] . display_amount ) ;
97
121
var obj = Instantiate ( virtualPurchaseProductPrefab , storeUI ) ;
98
122
obj . GetComponent < VirtualPurchaseProduct > ( ) . CreateProduct ( item . entity_name ,
99
123
item . prices [ 0 ] . amount ,
@@ -104,17 +128,17 @@ public void FetchVirtualProductsFromCatalog()
104
128
105
129
public void GiveGold ( )
106
130
{
107
- LootLockerSDKManager . CreditBalanceToWallet ( walletID , "01J3MK8BTC6JC9850YTXGXP1H5" , "200" , ( response ) =>
131
+ LootLockerSDKManager . CreditBalanceToWallet ( walletID , currencyIdentifier , grantCurrencyAmount , ( response ) =>
108
132
{
109
133
if ( ! response . success )
110
134
{
111
- Debug . Log ( "Could not Credit gold" ) ;
135
+ Debug . Log ( "Could not Credit gold\n Error: " + response . errorData . ToString ( ) ) ;
112
136
return ;
113
137
}
114
138
115
- goldAmount . text = currencyCode + response . amount ;
139
+ goldAmount . text = currencyDisplayCode + response . amount ;
116
140
GetPlayerGold ( ) ;
117
141
} ) ;
118
142
}
119
143
}
120
- }
144
+ }
0 commit comments