5
5
using UnityEngine ;
6
6
using UnityEngine . Purchasing ;
7
7
using UnityEngine . Purchasing . Extension ;
8
+
8
9
namespace VirtueSky . Iap
9
10
{
10
11
public class IapManager : MonoBehaviour , IDetailedStoreListener
@@ -13,6 +14,7 @@ public class IapManager : MonoBehaviour, IDetailedStoreListener
13
14
public static event Action < string > OnPurchaseSucceedEvent ;
14
15
public static event Action < string > OnPurchaseFailedEvent ;
15
16
public static event Action < Product > OnIapTrackingRevenueEvent ;
17
+ public static event Action < bool > OnShowIapNativePopupEvent ;
16
18
17
19
private IStoreController _controller ;
18
20
private IExtensionProvider _extensionProvider ;
@@ -70,16 +72,6 @@ private void PurchaseProductInternal(IapDataProduct product)
70
72
#endif
71
73
}
72
74
73
- private void PurchaseProductInternal ( string id )
74
- {
75
- #if ( UNITY_ANDROID || UNITY_IOS ) && ! UNITY_EDITOR
76
- _controller ? . InitiatePurchase ( id ) ;
77
- #elif UNITY_EDITOR
78
- InternalPurchaseSuccess ( id ) ;
79
- #endif
80
- }
81
-
82
-
83
75
private void RequestProductData ( ConfigurationBuilder builder )
84
76
{
85
77
foreach ( var p in iapSettings . IapDataProducts )
@@ -90,7 +82,7 @@ private void RequestProductData(ConfigurationBuilder builder)
90
82
91
83
private void InternalPurchaseFailed ( string id )
92
84
{
93
- //AdStatic.OnChangePreventDisplayAppOpenEvent ?.Invoke(false);
85
+ OnShowIapNativePopupEvent ? . Invoke ( false ) ;
94
86
foreach ( var product in iapSettings . IapDataProducts )
95
87
{
96
88
if ( product . Id != id ) continue ;
@@ -157,14 +149,13 @@ public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
157
149
158
150
void PurchaseVerified ( PurchaseEventArgs purchaseEvent )
159
151
{
160
- //AdStatic.OnChangePreventDisplayAppOpenEvent ?.Invoke(false);
152
+ OnShowIapNativePopupEvent ? . Invoke ( false ) ;
161
153
OnIapTrackingRevenueEvent ? . Invoke ( purchaseEvent . purchasedProduct ) ;
162
154
InternalPurchaseSuccess ( purchaseEvent . purchasedProduct . definition . id ) ;
163
155
}
164
156
165
157
void InternalPurchaseSuccess ( string id )
166
158
{
167
- //AdStatic.OnChangePreventDisplayAppOpenEvent?.Invoke(false);
168
159
foreach ( var product in iapSettings . IapDataProducts )
169
160
{
170
161
if ( product . Id != id ) continue ;
@@ -250,26 +241,28 @@ private static void AutoInitialize()
250
241
DontDestroyOnLoad ( iapManager ) ;
251
242
}
252
243
}
244
+
253
245
private void CallActionAndClean ( ref Action action )
254
246
{
255
247
if ( action == null ) return ;
256
248
var a = action ;
257
249
a ( ) ;
258
250
action = null ;
259
251
}
252
+
260
253
#region API
261
254
262
255
public IapDataProduct PurchaseProduct ( string id )
263
256
{
264
- //AdStatic.OnChangePreventDisplayAppOpenEvent ?.Invoke(true);
257
+ OnShowIapNativePopupEvent ? . Invoke ( true ) ;
265
258
var product = iapSettings . GetIapProduct ( id ) ;
266
259
PurchaseProductInternal ( product ) ;
267
260
return product ;
268
261
}
269
262
270
263
public IapDataProduct PurchaseProduct ( IapDataProduct product )
271
264
{
272
- //AdStatic.OnChangePreventDisplayAppOpenEvent ?.Invoke(true);
265
+ OnShowIapNativePopupEvent ? . Invoke ( true ) ;
273
266
PurchaseProductInternal ( product ) ;
274
267
return product ;
275
268
}
0 commit comments