@@ -65,9 +65,15 @@ public class KongregateUserItem
65
65
[ DisallowMultipleComponent ]
66
66
public class KongregateWeb : MonoBehaviour
67
67
{
68
- private static KongregateWeb _instance ;
68
+ public enum ApiStatus
69
+ {
70
+ Uninitialized ,
71
+ Unavailable ,
72
+ Ready
73
+ }
69
74
70
- private bool _kongregateApiLoaded = false ;
75
+ private static KongregateWeb _instance ;
76
+ private ApiStatus _status = ApiStatus . Uninitialized ;
71
77
private string _username ;
72
78
private int _userId ;
73
79
private string _gameAuthToken ;
@@ -236,12 +242,21 @@ public static event Action<bool> AdClosed
236
242
}
237
243
}
238
244
245
+ public static ApiStatus Status
246
+ {
247
+ get
248
+ {
249
+ AssertInstanceExists ( ) ;
250
+ return _instance . _status ;
251
+ }
252
+ }
253
+
239
254
public static bool IsReady
240
255
{
241
256
get
242
257
{
243
258
AssertInstanceExists ( ) ;
244
- return _instance . _kongregateApiLoaded ;
259
+ return _instance . _status == ApiStatus . Ready ;
245
260
}
246
261
}
247
262
@@ -418,7 +433,7 @@ private static void AssertIsReady()
418
433
{
419
434
AssertInstanceExists ( ) ;
420
435
421
- if ( ! _instance . _kongregateApiLoaded )
436
+ if ( _instance . _status != ApiStatus . Ready )
422
437
{
423
438
throw new Exception ( $ "Do not call any methods on { typeof ( KongregateWeb ) . Name } until the Kongregate web API has finished loading") ;
424
439
}
@@ -428,7 +443,7 @@ private static void AssertIsReady()
428
443
#region Callbacks from JS
429
444
private void OnInitSucceeded ( )
430
445
{
431
- _kongregateApiLoaded = true ;
446
+ _status = ApiStatus . Ready ;
432
447
433
448
if ( ! isGuest ( ) )
434
449
{
@@ -441,6 +456,11 @@ private void OnInitSucceeded()
441
456
_onBecameReady = null ;
442
457
}
443
458
459
+ private void OnInitFailed ( )
460
+ {
461
+ _status = ApiStatus . Unavailable ;
462
+ }
463
+
444
464
private void OnLogin ( string userInfo )
445
465
{
446
466
_userId = getUserId ( ) ;
@@ -541,7 +561,7 @@ private void OnAdClosed(int completed)
541
561
[ DllImport ( "__Internal" ) ]
542
562
private static extern void submitStats ( string statisticName , int value ) ;
543
563
#else
544
- private static void initKongregateAPI ( string gameObjectName ) { }
564
+ private static void initKongregateAPI ( string gameObjectName ) { _instance . _status = ApiStatus . Unavailable ; }
545
565
private static bool isGuest ( ) { return true ; }
546
566
private static int getUserId ( ) { return 0 ; }
547
567
private static string getUsername ( ) { return null ; }
0 commit comments