com.amanotes.gdk 0.2.23 → 0.2.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.26 - 2023-10-30]
4
+ - Add Ads event tracking
5
+ - Check real internet connection
6
+ - Add onResult callback
7
+ - AFAdRevenue
8
+ - Fix DebugLog config
9
+ - Move SkAdNetwork Fetch to GameObject context menu
10
+ - Remove IS event publisher from Ad module
11
+
12
+ ## [0.2.25 - 2023-10-25]
13
+ Update Ads module:
14
+ - OnRewardedAvailable
15
+ - OnRewardedUnavailable
16
+ - OnAdImpression
17
+ - Report internet condition in ShowAdFail
18
+ - Polish display of ironSource config's inspector
19
+ - Move SKAdnetwork's destination to Editor
20
+
3
21
  ## [0.2.23 - 2023-10-18]
4
22
  - Fix UserProfile out of main thread
5
23
  - Handle multiple Firebase's dependency check
@@ -112,14 +112,14 @@ namespace Amanotes.Editor
112
112
  {
113
113
  CreateCachedEditor(configAsset, null, ref editor);
114
114
  float lbWidth = EditorGUIUtility.labelWidth;
115
- EditorGUIUtility.labelWidth = 200f;
115
+ EditorGUIUtility.labelWidth = 220f;
116
116
  editor.OnInspectorGUI();
117
117
  EditorGUIUtility.labelWidth = lbWidth;
118
118
  }
119
119
 
120
120
  private void DrawGUI_ConfigAsset()
121
121
  {
122
- EditorGUILayout.ObjectField(configAsset, configAsset.GetType(), false);
122
+ EditorGUILayout.ObjectField(configAsset, configAsset.GetType(), false, GUILayout.Width(EditorGUIUtility.currentViewWidth - 414), GUILayout.ExpandWidth(true));
123
123
  }
124
124
 
125
125
  private void UpdateListAdapter()
@@ -142,7 +142,7 @@ namespace Amanotes.Core
142
142
 
143
143
  private static string GetSDKName(string packageName)
144
144
  {
145
- return sdkToClassMap.Keys.FirstOrDefault(sdk => packageName.Contains(sdk));
145
+ return sdkToClassMap.Keys.FirstOrDefault(sdk => packageName.Contains(sdk)) ?? "";
146
146
  }
147
147
  }
148
148
  }
@@ -63,9 +63,12 @@ namespace Amanotes.Editor
63
63
 
64
64
  public static bool Toggle(string label, ref bool value)
65
65
  {
66
+ float lbWidth = EditorGUIUtility.labelWidth;
67
+ EditorGUIUtility.labelWidth = 220f;
66
68
  bool newValue = EditorGUILayout.Toggle(label, value);
69
+ EditorGUIUtility.labelWidth = lbWidth;
70
+
67
71
  if (newValue == value) return false;
68
-
69
72
  value = newValue;
70
73
  return true;
71
74
  }
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -12,8 +12,7 @@ namespace Amanotes.Core
12
12
  {
13
13
  public static IAdCallback OnAdOpened(this IAdCallback ad, Action callback)
14
14
  {
15
- if (ad == null)
16
- return null;
15
+ if (!MakeSureAdNotNull(ad)) return null;
17
16
  Ads.context.onOpened -= callback;
18
17
  Ads.context.onOpened += callback;
19
18
  return ad;
@@ -21,8 +20,7 @@ namespace Amanotes.Core
21
20
 
22
21
  public static IAdCallback OnRewardReceived(this IAdCallback ad, Action callback)
23
22
  {
24
- if (ad == null)
25
- return null;
23
+ if (!MakeSureAdNotNull(ad)) return null;
26
24
  Ads.context.onRewardReceived -= callback;
27
25
  Ads.context.onRewardReceived += callback;
28
26
  return ad;
@@ -30,8 +28,7 @@ namespace Amanotes.Core
30
28
 
31
29
  public static IAdCallback OnAdClicked(this IAdCallback ad, Action callback)
32
30
  {
33
- if (ad == null)
34
- return null;
31
+ if (!MakeSureAdNotNull(ad)) return null;
35
32
  Ads.context.onClicked -= callback;
36
33
  Ads.context.onClicked += callback;
37
34
  return ad;
@@ -39,8 +36,7 @@ namespace Amanotes.Core
39
36
 
40
37
  public static IAdCallback OnAdShowFailed(this IAdCallback ad, Action callback)
41
38
  {
42
- if (ad == null)
43
- return null;
39
+ if (!MakeSureAdNotNull(ad)) return null;
44
40
  Ads.context.onShowFailed -= callback;
45
41
  Ads.context.onShowFailed += callback;
46
42
  return ad;
@@ -48,8 +44,7 @@ namespace Amanotes.Core
48
44
 
49
45
  public static IAdCallback OnAdShowSuccess(this IAdCallback ad, Action callback)
50
46
  {
51
- if (ad == null)
52
- return null;
47
+ if (!MakeSureAdNotNull(ad)) return null;
53
48
  Ads.context.onShowSuccess -= callback;
54
49
  Ads.context.onShowSuccess += callback;
55
50
  return ad;
@@ -57,13 +52,29 @@ namespace Amanotes.Core
57
52
 
58
53
  public static IAdCallback OnAdClosed(this IAdCallback ad, Action callback)
59
54
  {
60
- if (ad == null)
61
- return null;
55
+ if (!MakeSureAdNotNull(ad)) return null;
62
56
  Ads.context.onClosed -= callback;
63
57
  Ads.context.onClosed += callback;
64
58
  return ad;
65
59
  }
60
+
61
+ public static IAdCallback OnAdResult(this IAdCallback ad, Action<AdResult> callback)
62
+ {
63
+ if (!MakeSureAdNotNull(ad)) return null;
64
+ Ads.context.onResult -= callback;
65
+ Ads.context.onResult += callback;
66
+ return ad;
67
+ }
66
68
 
69
+ private static bool MakeSureAdNotNull(IAdCallback ad)
70
+ {
71
+ bool isValid = (ad != null);
72
+ if (!isValid)
73
+ {
74
+ LogWarning("Something wrong:: no AdShowContext");
75
+ }
76
+ return isValid;
77
+ }
67
78
  }
68
79
 
69
80
  public partial class AmaGDK // Ads module
@@ -110,6 +121,7 @@ namespace Amanotes.Core
110
121
  public bool enableRewarded = true;
111
122
  public bool enableBanner = true;
112
123
  public bool autoMute = true;
124
+ public bool autoTimeScale = true;
113
125
 
114
126
  [Header("EDITOR")]
115
127
  [Range(0f, 1f)] public float rewardAdShowSuccessRate = 1;
@@ -123,8 +135,8 @@ namespace Amanotes.Core
123
135
  internal static AdAdapterConfig _adConfig;
124
136
  internal static IAdAdapter _adapter;
125
137
  internal static float _savedVolume = -1;
138
+ internal static float _savedTimeScale = -1;
126
139
 
127
- public static readonly AdListener Events = new AdListener();
128
140
  internal static readonly AdsData localData = new AdsData().LoadJsonFromFile();
129
141
  }
130
142
 
@@ -255,6 +267,9 @@ namespace Amanotes.Core.Internal
255
267
  AdLogic interstitial { get; }
256
268
  AdLogic rewardVideo { get; }
257
269
 
270
+ void HandleBeforeAdShow();
271
+ void HandleAfterAdShow();
272
+
258
273
  void ShowBanner(BannerPosition position);
259
274
  void HideBanner();
260
275
  }
@@ -302,10 +317,21 @@ namespace Amanotes.Core.Internal
302
317
  Banner
303
318
  }
304
319
 
320
+ public enum AdResult
321
+ {
322
+ None,
323
+ Success,
324
+ WifiAndCarrierDataDisable,
325
+ NoInternetAccess,
326
+ RequestTimeOut,
327
+ AdapterReturnError
328
+ }
329
+
305
330
  public class ShowAdContext : IAdCallback
306
331
  {
307
332
  public readonly AdType adType;
308
333
  public readonly string placementName;
334
+ public AdResult result = AdResult.None;
309
335
  public readonly Dictionary<string, object> userData;
310
336
  public AdCallback adCallback;
311
337
 
@@ -315,6 +341,8 @@ namespace Amanotes.Core.Internal
315
341
  internal Action onShowSuccess;
316
342
  internal Action onShowFailed;
317
343
  internal Action onClosed;
344
+
345
+ internal Action<AdResult> onResult;
318
346
 
319
347
  // Stats
320
348
  public float showCallAt;
@@ -350,17 +378,17 @@ namespace Amanotes.Core.Internal
350
378
  {
351
379
  if (_loadState != LoadAdsState.None)
352
380
  {
353
- LogWarning("StartLoadAd() --> Invalid state: " + _loadState);
381
+ LogWarning("[Ad] StartLoadAd() --> Invalid state: " + _loadState);
354
382
  return;
355
383
  }
356
384
 
357
- Log("StartLoadAd");
385
+ Log("[Ad] StartLoadAd");
358
386
  _loadRoutine = _instance.StartCoroutine(LoadAdRoutine());
359
387
  }
360
388
 
361
389
  public void StopLoadAd()
362
390
  {
363
- Log("StopLoadAd");
391
+ Log("[Ad] StopLoadAd");
364
392
  if (_loadState == LoadAdsState.Requesting)
365
393
  {
366
394
  _loadState = LoadAdsState.None;
@@ -375,19 +403,31 @@ namespace Amanotes.Core.Internal
375
403
  {
376
404
  if (isAdReady)
377
405
  {
406
+ Log("[Ad] LoadAdRoutine skipped because isAdReady = true!");
378
407
  _loadState = LoadAdsState.Ready;
379
408
  yield break;
380
409
  }
381
-
410
+
411
+ Log("[Ad] LoadAdRoutine start(): isAdReady = " + isAdReady);
382
412
  while (true)
383
413
  {
384
414
  yield return wait1Sec;
385
415
 
386
- if (!Ads.allowAdRequest) continue;
387
- if (Ads._adConfig.checkInternet && !hasInternet) continue;
416
+ if (!Ads.allowAdRequest)
417
+ {
418
+ Log("[Ad] LoadAdRoutine: allowAdRequest = false");
419
+ continue;
420
+ }
421
+
422
+ if (Ads._adConfig.checkInternet && !HasLocalNetworkConnection)
423
+ {
424
+ Log("[Ad] LoadAdRoutine: hasInternet = " + HasLocalNetworkConnection);
425
+ continue;
426
+ }
388
427
 
389
428
  _loadState = LoadAdsState.Requesting;
390
429
  _isRequesting = true;
430
+ Log("[Ad] LoadAdRoutine: RequestAd()");
391
431
  RequestAd();
392
432
 
393
433
  int timeout = Ads._adConfig.adLoadTimeoutInSecs;
@@ -402,22 +442,24 @@ namespace Amanotes.Core.Internal
402
442
 
403
443
  if (counter > timeout && timeout > 0) // timeout
404
444
  {
445
+ Log("[Ad] LoadAdRoutine: RequestAd not responding (timeout) " + timeout + " secs");
405
446
  continue;
406
447
  }
407
448
 
408
449
  // request should be completed here!
409
450
  if (!isAdReady)
410
451
  {
411
- LogWarning("Request complete but failed!");
452
+ LogWarning($"[Ad] Request complete but failed! (load duration = {counter} secs)");
412
453
  continue;
413
454
  }
414
455
 
415
456
  _loadState = LoadAdsState.Ready;
457
+ Log($"[Ad] LoadAdRoutine: Ad is ready! (load duration = {counter} secs)");
416
458
  yield break;
417
459
  }
418
460
  }
419
461
 
420
- bool hasInternet => Application.internetReachability != NetworkReachability.NotReachable;
462
+ bool HasLocalNetworkConnection => Application.internetReachability != NetworkReachability.NotReachable;
421
463
 
422
464
  // Override by actual Ad instance
423
465
  protected abstract AdType adType { get; }
@@ -453,7 +495,7 @@ namespace Amanotes.Core.Internal
453
495
  _loadState = LoadAdsState.None;
454
496
  StartLoadAd();
455
497
  }
456
- RestoreVolume();
498
+ HandleAfterAdShow();
457
499
  if (_showAdRoutine == null) return;
458
500
  _instance.StopCoroutine(_showAdRoutine);
459
501
  _showAdRoutine = null;
@@ -461,6 +503,9 @@ namespace Amanotes.Core.Internal
461
503
 
462
504
  IEnumerator ShowAdRoutine()
463
505
  {
506
+ // Wait 1 frame so that all AdCallback to register
507
+ yield return null;
508
+
464
509
  // Wait for Ad
465
510
  if (!isAdReady)
466
511
  {
@@ -470,11 +515,25 @@ namespace Amanotes.Core.Internal
470
515
  _loadState = LoadAdsState.None;
471
516
  }
472
517
 
473
- if (Ads._adConfig.checkInternet && !hasInternet)
518
+ if (Ads._adConfig.checkInternet)
474
519
  {
475
- _showState = ShowAdsState.ShowFail;
476
- ShowAdRoutineCompleted(false);
477
- yield break;
520
+ if (!HasLocalNetworkConnection)
521
+ {
522
+ _showState = ShowAdsState.ShowFail;
523
+ Ads.context.result = AdResult.WifiAndCarrierDataDisable;
524
+ ShowAdRoutineCompleted(false);
525
+ yield break;
526
+ }
527
+
528
+ var hasInternet = false;
529
+ yield return WebUtils.CheckInternet(result => hasInternet = result);
530
+ if (!hasInternet)
531
+ {
532
+ _showState = ShowAdsState.ShowFail;
533
+ Ads.context.result = AdResult.NoInternetAccess;
534
+ ShowAdRoutineCompleted(false);
535
+ yield break;
536
+ }
478
537
  }
479
538
 
480
539
  if (_loadState != LoadAdsState.Requesting) StartLoadAd();
@@ -492,7 +551,7 @@ namespace Amanotes.Core.Internal
492
551
 
493
552
  if (!isAdReady)
494
553
  {
495
- Ads.Events.OnShowTimeout?.Invoke();
554
+ Ads.context.result = AdResult.RequestTimeOut;
496
555
  ShowAdRoutineCompleted(false);
497
556
  yield break;
498
557
  }
@@ -501,11 +560,7 @@ namespace Amanotes.Core.Internal
501
560
  _showState = ShowAdsState.Showing;
502
561
  // Ad should be ready here!
503
562
  ShowAd();
504
- if (Ads._adConfig.autoMute && AudioListener.volume > 0 && Ads._savedVolume == -1)
505
- {
506
- Ads._savedVolume = AudioListener.volume;
507
- AudioListener.volume = 0;
508
- }
563
+ HandleBeforeAdShow();
509
564
 
510
565
  ShowAdContext context = Ads.context;
511
566
  while (!context.potentiallyCompleted)
@@ -557,8 +612,11 @@ namespace Amanotes.Core.Internal
557
612
  }
558
613
 
559
614
  _showState = isSuccess ? ShowAdsState.ShowSuccess : ShowAdsState.ShowFail;
615
+ // Extra callback
616
+ if (isSuccess) Ads.context.result = AdResult.Success;
617
+ Ads.context.onResult?.Invoke(Ads.context.result);
560
618
  Ads.context.showFinishAt = Time.realtimeSinceStartup;
561
-
619
+
562
620
  var localData = Ads.localData;
563
621
  var stat = _isInterstitial ? localData.interstitial : localData.reward;
564
622
  if (isSuccess)
@@ -574,19 +632,61 @@ namespace Amanotes.Core.Internal
574
632
  }
575
633
 
576
634
  localData.Save();
577
- RestoreVolume();
635
+ HandleAfterAdShow();
578
636
 
579
637
  Log($"[Ad] {adType} ShowAdRoutineCompleted: {isSuccess}\n{JsonUtility.ToJson(Ads.context)}");
580
638
  Ads.context = null;
581
639
  _showState = ShowAdsState.None;
582
640
  }
583
-
584
- private void RestoreVolume()
641
+
642
+ private void HandleBeforeAdShow()
585
643
  {
586
- if (!Ads._adConfig.autoMute || Ads._savedVolume <= 0)
587
- return;
588
- AudioListener.volume = Ads._savedVolume;
589
- Ads._savedVolume = -1;
644
+ bool willSaveVolume = Ads._adConfig.autoMute
645
+ && AudioListener.volume > 0
646
+ && Ads._savedVolume < 0;
647
+
648
+ bool willSaveTimeScale = Ads._adConfig.autoTimeScale
649
+ && Time.timeScale > 0
650
+ && Ads._savedTimeScale < 0;
651
+
652
+ if (willSaveVolume)
653
+ {
654
+ Ads._savedVolume = AudioListener.volume;
655
+ AudioListener.volume = 0;
656
+ }
657
+
658
+ if (willSaveTimeScale)
659
+ {
660
+ Ads._savedTimeScale = Time.timeScale;
661
+ Ads._savedTimeScale = Time.timeScale;
662
+ }
663
+
664
+ Ads._adapter.HandleBeforeAdShow();
665
+ }
666
+
667
+ private void HandleAfterAdShow()
668
+ {
669
+ bool willRestoreVolume = Ads._adConfig.autoMute
670
+ && AudioListener.volume == 0
671
+ && Ads._savedVolume > 0;
672
+
673
+ bool willRestoreTimeScale = Ads._adConfig.autoTimeScale
674
+ && Time.timeScale == 0
675
+ && Ads._savedTimeScale > 0;
676
+
677
+ if (willRestoreVolume)
678
+ {
679
+ AudioListener.volume = Ads._savedVolume;
680
+ Ads._savedVolume = -1;
681
+ }
682
+
683
+ if (willRestoreTimeScale)
684
+ {
685
+ Time.timeScale = Ads._savedTimeScale;
686
+ Ads._savedTimeScale = -1;
687
+ }
688
+
689
+ Ads._adapter.HandleAfterAdShow();
590
690
  }
591
691
 
592
692
  // Default implementation
@@ -601,13 +701,8 @@ namespace Amanotes.Core.Internal
601
701
  }
602
702
  else
603
703
  {
604
- LogWarning("OnAdClosed() Something wrong - No AdContext");
704
+ LogWarning("[Ad] OnAdClosed() Something wrong - No AdContext");
605
705
  }
606
-
607
- if (_isInterstitial)
608
- Ads.Events.OnInterstitialClosed?.Invoke();
609
- else
610
- Ads.Events.OnRewardedClosed?.Invoke();
611
706
  }
612
707
 
613
708
  protected void OnAdClicked()
@@ -621,14 +716,8 @@ namespace Amanotes.Core.Internal
621
716
  }
622
717
  else
623
718
  {
624
- LogWarning("OnAdClicked() Something wrong - No AdContext");
719
+ LogWarning("[Ad] OnAdClicked() Something wrong - No AdContext");
625
720
  }
626
-
627
- if (_isInterstitial)
628
- Ads.Events.OnInterstitialClicked?.Invoke();
629
- else
630
- Ads.Events.OnRewardedClicked?.Invoke();
631
-
632
721
  }
633
722
 
634
723
  protected void OnAdShowFailed()
@@ -638,18 +727,13 @@ namespace Amanotes.Core.Internal
638
727
  if (Ads.context != null)
639
728
  {
640
729
  Ads.context.adCallback |= AdCallback.Fail;
730
+ Ads.context.result = AdResult.AdapterReturnError;
641
731
  Ads.context.onShowFailed?.Invoke();
642
732
  }
643
733
  else
644
734
  {
645
- LogWarning("OnAdShowFailed() Something wrong - No AdContext");
735
+ LogWarning("[Ad] OnAdShowFailed() Something wrong - No AdContext");
646
736
  }
647
-
648
- if (_isInterstitial)
649
- Ads.Events.OnInterstitialShowFailed?.Invoke();
650
- else
651
- Ads.Events.OnRewardedShowFailed?.Invoke();
652
-
653
737
  }
654
738
 
655
739
  protected void OnAdShowSucceeded()
@@ -663,12 +747,8 @@ namespace Amanotes.Core.Internal
663
747
  }
664
748
  else
665
749
  {
666
- LogWarning("OnAdShowSucceeded() Something wrong - No AdContext");
750
+ LogWarning("[Ad] OnAdShowSucceeded() Something wrong - No AdContext");
667
751
  }
668
-
669
- if (_isInterstitial)
670
- Ads.Events.OnInterstitialShowSucceeded?.Invoke();
671
-
672
752
  }
673
753
 
674
754
  protected void OnAdOpen()
@@ -682,13 +762,8 @@ namespace Amanotes.Core.Internal
682
762
  }
683
763
  else
684
764
  {
685
- LogWarning("OnAdOpen() Something wrong - No AdContext");
765
+ LogWarning("[Ad] OnAdOpen() Something wrong - No AdContext");
686
766
  }
687
-
688
- if (_isInterstitial)
689
- Ads.Events.OnInterstitialOpened?.Invoke();
690
- else
691
- Ads.Events.OnRewardedOpened?.Invoke();
692
767
  }
693
768
 
694
769
  protected void OnAdReward()
@@ -702,11 +777,8 @@ namespace Amanotes.Core.Internal
702
777
  }
703
778
  else
704
779
  {
705
- LogWarning("OnAdReward() Something wrong - No AdContext");
780
+ LogWarning("[Ad] OnAdReward() Something wrong - No AdContext");
706
781
  }
707
-
708
- if (!_isInterstitial)
709
- Ads.Events.OnRewardedReceived?.Invoke();
710
782
  }
711
783
 
712
784
  protected void OnAdLoadSuccess()
@@ -715,39 +787,15 @@ namespace Amanotes.Core.Internal
715
787
 
716
788
  if (!_isRequesting)
717
789
  {
718
- LogWarning("Something wrong? OnAdReady called when no ad is loading!");
790
+ LogWarning("[Ad] Something wrong? OnAdReady called when no ad is loading! AdType=" + adType);
719
791
  }
720
792
 
721
793
  _isRequesting = false;
722
- if (_isInterstitial)
723
- Ads.Events.OnInterstitialLoadSucceeded?.Invoke();
724
794
  }
725
795
 
726
796
  protected void OnAdLoadFailed(string error)
727
797
  {
728
798
  Log($"[Ad] {adType} OnAdLoadFailed: {error}");
729
-
730
- if (_isInterstitial)
731
- Ads.Events.OnInterstitialLoadFailed?.Invoke(error);
732
799
  }
733
800
  }
734
-
735
- public class AdListener
736
- {
737
- public Action OnRewardedOpened;
738
- public Action OnRewardedReceived;
739
- public Action OnRewardedClicked;
740
- public Action OnRewardedShowFailed;
741
- public Action OnRewardedClosed;
742
-
743
- public Action OnInterstitialOpened;
744
- public Action OnInterstitialShowSucceeded;
745
- public Action OnInterstitialShowFailed;
746
- public Action OnInterstitialClicked;
747
- public Action OnInterstitialClosed;
748
- public Action OnInterstitialLoadSucceeded;
749
- public Action<string> OnInterstitialLoadFailed;
750
-
751
- public Action OnShowTimeout;
752
- }
753
801
  }
@@ -82,20 +82,19 @@ namespace Amanotes.Core.Internal
82
82
  }
83
83
  #endif
84
84
  }
85
-
86
- [Flags]
85
+
87
86
  public enum LogLevel
88
87
  {
89
- None = 0,
90
- Error = 1,
91
- Warning = 2,
92
- Verbose = 4
88
+ None,
89
+ Error,
90
+ Warning,
91
+ Verbose
93
92
  }
94
93
 
95
94
  [Serializable]
96
95
  public partial class SDKConfig
97
96
  {
98
- public LogLevel logLevel = LogLevel.Warning | LogLevel.Error;
97
+ public LogLevel logLevel = LogLevel.Warning;
99
98
  }
100
99
 
101
100
  [Serializable]
@@ -68,7 +68,7 @@ namespace Amanotes.Core.Internal
68
68
 
69
69
  public static void LogWarningOnce(string message, string key = null)
70
70
  {
71
- if ((Config.common.logLevel & LogLevel.Warning) == 0) return;
71
+ if (Config.common.logLevel < LogLevel.Warning) return;
72
72
  if (string.IsNullOrEmpty(key)) key = message;
73
73
  if (logWarningDict.Contains(key)) return;
74
74
  logWarningDict.Add(key);
@@ -76,15 +76,15 @@ namespace Amanotes.Core.Internal
76
76
  }
77
77
  public static void LogWarning(string message)
78
78
  {
79
- if ((Config.common.logLevel & LogLevel.Warning) != 0) Debug.LogWarning($"AmaGDK {message}");
79
+ if (Config.common.logLevel >= LogLevel.Warning) Debug.LogWarning($"AmaGDK {message}");
80
80
  }
81
81
  public static void LogError(string message)
82
82
  {
83
- if ((Config.common.logLevel & LogLevel.Error) != 0) Debug.LogError($"AmaGDK {message}");
83
+ if (Config.common.logLevel >= LogLevel.Error) Debug.LogError($"AmaGDK {message}");
84
84
  }
85
85
  public static void Log(string message)
86
86
  {
87
- if ((Config.common.logLevel & LogLevel.Verbose) != 0) Debug.Log($"AmaGDK {message}");
87
+ if (Config.common.logLevel == LogLevel.Verbose) Debug.Log($"AmaGDK {message}");
88
88
  }
89
89
  }
90
90
 
@@ -28,6 +28,7 @@ namespace Amanotes.Core.Internal
28
28
  {
29
29
  SetRequestHeader(kvp.Key, kvp.Value);
30
30
  }
31
+
31
32
  return this;
32
33
  }
33
34
 
@@ -95,12 +96,14 @@ namespace Amanotes.Core.Internal
95
96
 
96
97
  internal class WebUtils
97
98
  {
98
- public static Coroutine PostJson(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
99
+ public static Coroutine PostJson(string url, string jsonData, Action<bool, string> onComplete = null,
100
+ Dictionary<string, string> headers = null)
99
101
  {
100
102
  return AmaGDK._instance.StartCoroutine(PostJsonCoroutine(url, jsonData, onComplete, headers));
101
103
  }
102
104
 
103
- private static IEnumerator PostJsonCoroutine(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
105
+ private static IEnumerator PostJsonCoroutine(string url, string jsonData,
106
+ Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
104
107
  {
105
108
  var webRequest = new UnityWebRequest(url, "POST");
106
109
  if (headers != null)
@@ -125,5 +128,29 @@ namespace Amanotes.Core.Internal
125
128
  onComplete?.Invoke(true, webRequest.downloadHandler.text);
126
129
  }
127
130
  }
131
+
132
+ public static void CheckInternetConnection(Action<bool> hasInternet)
133
+ {
134
+ AmaGDK._instance.StartCoroutine(CheckInternet(hasInternet));
135
+ }
136
+
137
+ public static IEnumerator CheckInternet(Action<bool> hasInternet)
138
+ {
139
+ UnityWebRequest www = new UnityWebRequest(AmaGDK.Config.common.internetCheckUrl);
140
+ yield return www.SendWebRequest();
141
+
142
+ if (www.error != null && www.responseCode != 429) //429 = Too many requests
143
+ {
144
+ hasInternet?.Invoke(false);
145
+ yield break;
146
+ }
147
+
148
+ hasInternet?.Invoke(true);
149
+ }
150
+ }
151
+
152
+ public partial class SDKConfig
153
+ {
154
+ public string internetCheckUrl = "http://www.google.com";
128
155
  }
129
156
  }
package/Runtime/AmaGDK.cs CHANGED
@@ -14,7 +14,7 @@ namespace Amanotes.Core
14
14
  {
15
15
  public partial class AmaGDK : MonoBehaviour
16
16
  {
17
- public const string VERSION = "0.2.23";
17
+ public const string VERSION = "0.2.26";
18
18
 
19
19
  internal static AmaGDK _instance;
20
20
  internal static Status _status = Status.None;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.2.23",
3
+ "version": "0.2.26",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2019.4",