com.amanotes.gdk 0.2.25 → 0.2.27

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,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.27 - 2023-11-01]
4
+ - No longer stop ad
5
+ - Update ad status by adapter
6
+
7
+ ## [0.2.26 - 2023-10-30]
8
+ - Add Ads event tracking
9
+ - Check real internet connection
10
+ - Add onResult callback
11
+ - AFAdRevenue
12
+ - Fix DebugLog config
13
+ - Move SkAdNetwork Fetch to GameObject context menu
14
+ - Remove IS event publisher from Ad module
15
+
3
16
  ## [0.2.25 - 2023-10-25]
4
17
  Update Ads module:
5
18
  - OnRewardedAvailable
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,24 +52,28 @@ 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
 
67
- public static IAdCallback OnRewardedVideoComplete(this IAdCallback ad, Action<bool> callback)
69
+ private static bool MakeSureAdNotNull(IAdCallback ad)
68
70
  {
69
- if (ad == null)
70
- return null;
71
- void RewardedVideoComplete()
71
+ bool isValid = (ad != null);
72
+ if (!isValid)
72
73
  {
73
- callback(Ads.context.hasReward);
74
+ LogWarning("Something wrong:: no AdShowContext");
74
75
  }
75
- Ads.context.onClosed -= RewardedVideoComplete;
76
- Ads.context.onClosed += RewardedVideoComplete;
77
- return ad;
76
+ return isValid;
78
77
  }
79
78
  }
80
79
 
@@ -122,6 +121,7 @@ namespace Amanotes.Core
122
121
  public bool enableRewarded = true;
123
122
  public bool enableBanner = true;
124
123
  public bool autoMute = true;
124
+ public bool autoTimeScale = true;
125
125
 
126
126
  [Header("EDITOR")]
127
127
  [Range(0f, 1f)] public float rewardAdShowSuccessRate = 1;
@@ -135,8 +135,8 @@ namespace Amanotes.Core
135
135
  internal static AdAdapterConfig _adConfig;
136
136
  internal static IAdAdapter _adapter;
137
137
  internal static float _savedVolume = -1;
138
+ internal static float _savedTimeScale = -1;
138
139
 
139
- public static readonly AdListener Events = new AdListener();
140
140
  internal static readonly AdsData localData = new AdsData().LoadJsonFromFile();
141
141
  }
142
142
 
@@ -159,24 +159,26 @@ namespace Amanotes.Core
159
159
  {
160
160
  if (context == null) return true;
161
161
  float duration = Time.realtimeSinceStartup - context.showCallAt;
162
- bool willSkip = duration < Mathf.Max(5f, _adConfig.adShowTimeoutInSecs);
163
- if (willSkip)
164
- {
165
- LogWarning($"[AD] ShowRequest IGNORED as another ad is showing (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
166
- return false;
167
- }
168
-
169
- LogWarning($"[AD] FORCE STOPPED the previous ad, as it seems to hang (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
170
- // possibly hang: force stop
171
- if (context.adType == AdType.Interstitial)
172
- {
173
- _adapter.interstitial.StopShowAd();
174
- } else
175
- {
176
- _adapter.rewardVideo.StopShowAd();
177
- }
178
- context = null;
179
- return true;
162
+ // bool willSkip = duration < Mathf.Max(60f, _adConfig.adShowTimeoutInSecs);
163
+ LogWarning($"[AD] ShowRequest IGNORED as another ad is showing (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
164
+ return false;
165
+
166
+ // if (willSkip)
167
+ // {
168
+ // LogWarning($"[AD] ShowRequest IGNORED as another ad is showing (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
169
+ // return false;
170
+ // }
171
+ //
172
+ // LogWarning($"[AD] FORCE STOPPED the previous ad, as it seems to hang (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
173
+ // // possibly hang: force stop
174
+ // if (context.adType == AdType.Interstitial)
175
+ // {
176
+ // _adapter.interstitial.StopShowAd();
177
+ // } else
178
+ // {
179
+ // _adapter.rewardVideo.StopShowAd();
180
+ // }
181
+ // return true;
180
182
  }
181
183
 
182
184
  public static IAdCallback ShowInterstitial(string placementName = null, Dictionary<string, object> userData = null)
@@ -242,7 +244,7 @@ namespace Amanotes.Core
242
244
  {
243
245
  if (context == null)
244
246
  return;
245
-
247
+
246
248
  if (context.adType == AdType.Interstitial)
247
249
  _adapter.interstitial.StopShowAd();
248
250
  else
@@ -267,6 +269,9 @@ namespace Amanotes.Core.Internal
267
269
  AdLogic interstitial { get; }
268
270
  AdLogic rewardVideo { get; }
269
271
 
272
+ void HandleBeforeAdShow();
273
+ void HandleAfterAdShow();
274
+
270
275
  void ShowBanner(BannerPosition position);
271
276
  void HideBanner();
272
277
  }
@@ -314,11 +319,21 @@ namespace Amanotes.Core.Internal
314
319
  Banner
315
320
  }
316
321
 
322
+ public enum AdResult
323
+ {
324
+ None,
325
+ Success,
326
+ WifiAndCarrierDataDisable,
327
+ NoInternetAccess,
328
+ RequestTimeOut,
329
+ AdapterReturnError
330
+ }
331
+
317
332
  public class ShowAdContext : IAdCallback
318
333
  {
319
334
  public readonly AdType adType;
320
335
  public readonly string placementName;
321
- public string errorMessage;
336
+ public AdResult result = AdResult.None;
322
337
  public readonly Dictionary<string, object> userData;
323
338
  public AdCallback adCallback;
324
339
 
@@ -328,6 +343,8 @@ namespace Amanotes.Core.Internal
328
343
  internal Action onShowSuccess;
329
344
  internal Action onShowFailed;
330
345
  internal Action onClosed;
346
+
347
+ internal Action<AdResult> onResult;
331
348
 
332
349
  // Stats
333
350
  public float showCallAt;
@@ -355,7 +372,20 @@ namespace Amanotes.Core.Internal
355
372
  private static readonly WaitForSeconds wait1Sec = new WaitForSeconds(1f);
356
373
 
357
374
  internal LoadAdsState _loadState = LoadAdsState.None;
358
- internal bool hasAd => _loadState == LoadAdsState.Ready;
375
+ internal bool hasAd
376
+ {
377
+ get
378
+ {
379
+ if (_loadState == LoadAdsState.Ready && !isAdReady)
380
+ {
381
+ LogWarning("[Ad] Inconsistent Ready state (might caused by poor internet condition)");
382
+ _loadState = LoadAdsState.None;
383
+ StartLoadAd();
384
+ }
385
+
386
+ return _loadState == LoadAdsState.Ready;
387
+ }
388
+ }
359
389
 
360
390
  internal Coroutine _loadRoutine;
361
391
 
@@ -363,17 +393,17 @@ namespace Amanotes.Core.Internal
363
393
  {
364
394
  if (_loadState != LoadAdsState.None)
365
395
  {
366
- LogWarning("StartLoadAd() --> Invalid state: " + _loadState);
396
+ LogWarning("[Ad] StartLoadAd() --> Invalid state: " + _loadState);
367
397
  return;
368
398
  }
369
399
 
370
- Log("StartLoadAd");
400
+ Log("[Ad] StartLoadAd");
371
401
  _loadRoutine = _instance.StartCoroutine(LoadAdRoutine());
372
402
  }
373
403
 
374
404
  public void StopLoadAd()
375
405
  {
376
- Log("StopLoadAd");
406
+ Log("[Ad] StopLoadAd");
377
407
  if (_loadState == LoadAdsState.Requesting)
378
408
  {
379
409
  _loadState = LoadAdsState.None;
@@ -388,19 +418,31 @@ namespace Amanotes.Core.Internal
388
418
  {
389
419
  if (isAdReady)
390
420
  {
421
+ Log("[Ad] LoadAdRoutine skipped because isAdReady = true!");
391
422
  _loadState = LoadAdsState.Ready;
392
423
  yield break;
393
424
  }
394
-
425
+
426
+ Log("[Ad] LoadAdRoutine start(): isAdReady = " + isAdReady);
395
427
  while (true)
396
428
  {
397
429
  yield return wait1Sec;
398
430
 
399
- if (!Ads.allowAdRequest) continue;
400
- if (Ads._adConfig.checkInternet && !hasInternet) continue;
431
+ if (!Ads.allowAdRequest)
432
+ {
433
+ Log("[Ad] LoadAdRoutine: allowAdRequest = false");
434
+ continue;
435
+ }
436
+
437
+ if (Ads._adConfig.checkInternet && !HasLocalNetworkConnection)
438
+ {
439
+ Log("[Ad] LoadAdRoutine: hasInternet = " + HasLocalNetworkConnection);
440
+ continue;
441
+ }
401
442
 
402
443
  _loadState = LoadAdsState.Requesting;
403
444
  _isRequesting = true;
445
+ Log("[Ad] LoadAdRoutine: RequestAd()");
404
446
  RequestAd();
405
447
 
406
448
  int timeout = Ads._adConfig.adLoadTimeoutInSecs;
@@ -415,22 +457,24 @@ namespace Amanotes.Core.Internal
415
457
 
416
458
  if (counter > timeout && timeout > 0) // timeout
417
459
  {
460
+ Log("[Ad] LoadAdRoutine: RequestAd not responding (timeout) " + timeout + " secs");
418
461
  continue;
419
462
  }
420
463
 
421
464
  // request should be completed here!
422
465
  if (!isAdReady)
423
466
  {
424
- LogWarning("Request complete but failed!");
467
+ LogWarning($"[Ad] Request complete but failed! (load duration = {counter} secs)");
425
468
  continue;
426
469
  }
427
470
 
428
471
  _loadState = LoadAdsState.Ready;
472
+ Log($"[Ad] LoadAdRoutine: Ad is ready! (load duration = {counter} secs)");
429
473
  yield break;
430
474
  }
431
475
  }
432
476
 
433
- bool hasInternet => Application.internetReachability != NetworkReachability.NotReachable;
477
+ bool HasLocalNetworkConnection => Application.internetReachability != NetworkReachability.NotReachable;
434
478
 
435
479
  // Override by actual Ad instance
436
480
  protected abstract AdType adType { get; }
@@ -466,14 +510,26 @@ namespace Amanotes.Core.Internal
466
510
  _loadState = LoadAdsState.None;
467
511
  StartLoadAd();
468
512
  }
469
- RestoreVolume();
513
+ HandleAfterAdShow();
470
514
  if (_showAdRoutine == null) return;
471
515
  _instance.StopCoroutine(_showAdRoutine);
472
516
  _showAdRoutine = null;
517
+
518
+ if (Ads.context.adType == AdType.Interstitial)
519
+ {
520
+ ShowAdRoutineCompleted(!Ads.context.hasFailedOrCancelled);
521
+ }
522
+ else
523
+ {
524
+ ShowAdRoutineCompleted(Ads.context.hasReward);
525
+ }
473
526
  }
474
527
 
475
528
  IEnumerator ShowAdRoutine()
476
529
  {
530
+ // Wait to end frame so that all AdCallbacks finish registering
531
+ yield return new WaitForEndOfFrame();
532
+
477
533
  // Wait for Ad
478
534
  if (!isAdReady)
479
535
  {
@@ -483,14 +539,25 @@ namespace Amanotes.Core.Internal
483
539
  _loadState = LoadAdsState.None;
484
540
  }
485
541
 
486
- if (Ads._adConfig.checkInternet && !hasInternet)
542
+ if (Ads._adConfig.checkInternet)
487
543
  {
488
- _showState = ShowAdsState.ShowFail;
489
- Ads.context.errorMessage = "Please check you internet connection";
490
- if (_isInterstitial) Ads.Events.OnInterstitialShowFailed?.Invoke();
491
- else Ads.Events.OnRewardedShowFailed?.Invoke();
492
- ShowAdRoutineCompleted(false);
493
- yield break;
544
+ if (!HasLocalNetworkConnection)
545
+ {
546
+ _showState = ShowAdsState.ShowFail;
547
+ Ads.context.result = AdResult.WifiAndCarrierDataDisable;
548
+ ShowAdRoutineCompleted(false);
549
+ yield break;
550
+ }
551
+
552
+ var hasInternet = false;
553
+ yield return WebUtils.CheckInternet(result => hasInternet = result);
554
+ if (!hasInternet)
555
+ {
556
+ _showState = ShowAdsState.ShowFail;
557
+ Ads.context.result = AdResult.NoInternetAccess;
558
+ ShowAdRoutineCompleted(false);
559
+ yield break;
560
+ }
494
561
  }
495
562
 
496
563
  if (_loadState != LoadAdsState.Requesting) StartLoadAd();
@@ -508,7 +575,7 @@ namespace Amanotes.Core.Internal
508
575
 
509
576
  if (!isAdReady)
510
577
  {
511
- Ads.Events.OnShowTimeout?.Invoke();
578
+ Ads.context.result = AdResult.RequestTimeOut;
512
579
  ShowAdRoutineCompleted(false);
513
580
  yield break;
514
581
  }
@@ -517,11 +584,7 @@ namespace Amanotes.Core.Internal
517
584
  _showState = ShowAdsState.Showing;
518
585
  // Ad should be ready here!
519
586
  ShowAd();
520
- if (Ads._adConfig.autoMute && AudioListener.volume > 0 && Ads._savedVolume == -1)
521
- {
522
- Ads._savedVolume = AudioListener.volume;
523
- AudioListener.volume = 0;
524
- }
587
+ HandleBeforeAdShow();
525
588
 
526
589
  ShowAdContext context = Ads.context;
527
590
  while (!context.potentiallyCompleted)
@@ -573,8 +636,11 @@ namespace Amanotes.Core.Internal
573
636
  }
574
637
 
575
638
  _showState = isSuccess ? ShowAdsState.ShowSuccess : ShowAdsState.ShowFail;
639
+ // Extra callback
640
+ if (isSuccess) Ads.context.result = AdResult.Success;
641
+ Ads.context.onResult?.Invoke(Ads.context.result);
576
642
  Ads.context.showFinishAt = Time.realtimeSinceStartup;
577
-
643
+
578
644
  var localData = Ads.localData;
579
645
  var stat = _isInterstitial ? localData.interstitial : localData.reward;
580
646
  if (isSuccess)
@@ -590,19 +656,61 @@ namespace Amanotes.Core.Internal
590
656
  }
591
657
 
592
658
  localData.Save();
593
- RestoreVolume();
659
+ HandleAfterAdShow();
594
660
 
595
661
  Log($"[Ad] {adType} ShowAdRoutineCompleted: {isSuccess}\n{JsonUtility.ToJson(Ads.context)}");
596
662
  Ads.context = null;
597
663
  _showState = ShowAdsState.None;
598
664
  }
599
-
600
- private void RestoreVolume()
665
+
666
+ private void HandleBeforeAdShow()
601
667
  {
602
- if (!Ads._adConfig.autoMute || Ads._savedVolume <= 0)
603
- return;
604
- AudioListener.volume = Ads._savedVolume;
605
- Ads._savedVolume = -1;
668
+ bool willSaveVolume = Ads._adConfig.autoMute
669
+ && AudioListener.volume > 0
670
+ && Ads._savedVolume < 0;
671
+
672
+ bool willSaveTimeScale = Ads._adConfig.autoTimeScale
673
+ && Time.timeScale > 0
674
+ && Ads._savedTimeScale < 0;
675
+
676
+ if (willSaveVolume)
677
+ {
678
+ Ads._savedVolume = AudioListener.volume;
679
+ AudioListener.volume = 0;
680
+ }
681
+
682
+ if (willSaveTimeScale)
683
+ {
684
+ Ads._savedTimeScale = Time.timeScale;
685
+ Ads._savedTimeScale = Time.timeScale;
686
+ }
687
+
688
+ Ads._adapter.HandleBeforeAdShow();
689
+ }
690
+
691
+ private void HandleAfterAdShow()
692
+ {
693
+ bool willRestoreVolume = Ads._adConfig.autoMute
694
+ && AudioListener.volume == 0
695
+ && Ads._savedVolume > 0;
696
+
697
+ bool willRestoreTimeScale = Ads._adConfig.autoTimeScale
698
+ && Time.timeScale == 0
699
+ && Ads._savedTimeScale > 0;
700
+
701
+ if (willRestoreVolume)
702
+ {
703
+ AudioListener.volume = Ads._savedVolume;
704
+ Ads._savedVolume = -1;
705
+ }
706
+
707
+ if (willRestoreTimeScale)
708
+ {
709
+ Time.timeScale = Ads._savedTimeScale;
710
+ Ads._savedTimeScale = -1;
711
+ }
712
+
713
+ Ads._adapter.HandleAfterAdShow();
606
714
  }
607
715
 
608
716
  // Default implementation
@@ -617,13 +725,8 @@ namespace Amanotes.Core.Internal
617
725
  }
618
726
  else
619
727
  {
620
- LogWarning("OnAdClosed() Something wrong - No AdContext");
728
+ LogWarning("[Ad] OnAdClosed() Something wrong - No AdContext");
621
729
  }
622
-
623
- if (_isInterstitial)
624
- Ads.Events.OnInterstitialClosed?.Invoke();
625
- else
626
- Ads.Events.OnRewardedClosed?.Invoke();
627
730
  }
628
731
 
629
732
  protected void OnAdClicked()
@@ -637,14 +740,8 @@ namespace Amanotes.Core.Internal
637
740
  }
638
741
  else
639
742
  {
640
- LogWarning("OnAdClicked() Something wrong - No AdContext");
743
+ LogWarning("[Ad] OnAdClicked() Something wrong - No AdContext");
641
744
  }
642
-
643
- if (_isInterstitial)
644
- Ads.Events.OnInterstitialClicked?.Invoke();
645
- else
646
- Ads.Events.OnRewardedClicked?.Invoke();
647
-
648
745
  }
649
746
 
650
747
  protected void OnAdShowFailed()
@@ -654,18 +751,13 @@ namespace Amanotes.Core.Internal
654
751
  if (Ads.context != null)
655
752
  {
656
753
  Ads.context.adCallback |= AdCallback.Fail;
754
+ Ads.context.result = AdResult.AdapterReturnError;
657
755
  Ads.context.onShowFailed?.Invoke();
658
756
  }
659
757
  else
660
758
  {
661
- LogWarning("OnAdShowFailed() Something wrong - No AdContext");
759
+ LogWarning("[Ad] OnAdShowFailed() Something wrong - No AdContext");
662
760
  }
663
-
664
- if (_isInterstitial)
665
- Ads.Events.OnInterstitialShowFailed?.Invoke();
666
- else
667
- Ads.Events.OnRewardedShowFailed?.Invoke();
668
-
669
761
  }
670
762
 
671
763
  protected void OnAdShowSucceeded()
@@ -679,12 +771,8 @@ namespace Amanotes.Core.Internal
679
771
  }
680
772
  else
681
773
  {
682
- LogWarning("OnAdShowSucceeded() Something wrong - No AdContext");
774
+ LogWarning("[Ad] OnAdShowSucceeded() Something wrong - No AdContext");
683
775
  }
684
-
685
- if (_isInterstitial)
686
- Ads.Events.OnInterstitialShowSucceeded?.Invoke();
687
-
688
776
  }
689
777
 
690
778
  protected void OnAdOpen()
@@ -698,13 +786,8 @@ namespace Amanotes.Core.Internal
698
786
  }
699
787
  else
700
788
  {
701
- LogWarning("OnAdOpen() Something wrong - No AdContext");
789
+ LogWarning("[Ad] OnAdOpen() Something wrong - No AdContext");
702
790
  }
703
-
704
- if (_isInterstitial)
705
- Ads.Events.OnInterstitialOpened?.Invoke();
706
- else
707
- Ads.Events.OnRewardedOpened?.Invoke();
708
791
  }
709
792
 
710
793
  protected void OnAdReward()
@@ -718,11 +801,8 @@ namespace Amanotes.Core.Internal
718
801
  }
719
802
  else
720
803
  {
721
- LogWarning("OnAdReward() Something wrong - No AdContext");
804
+ LogWarning("[Ad] OnAdReward() Something wrong - No AdContext");
722
805
  }
723
-
724
- if (!_isInterstitial)
725
- Ads.Events.OnRewardedReceived?.Invoke();
726
806
  }
727
807
 
728
808
  protected void OnAdLoadSuccess()
@@ -731,42 +811,15 @@ namespace Amanotes.Core.Internal
731
811
 
732
812
  if (!_isRequesting)
733
813
  {
734
- LogWarning("Something wrong? OnAdReady called when no ad is loading!");
814
+ LogWarning("[Ad] Something wrong? OnAdReady called when no ad is loading! AdType=" + adType);
735
815
  }
736
816
 
737
817
  _isRequesting = false;
738
- if (_isInterstitial)
739
- Ads.Events.OnInterstitialLoadSucceeded?.Invoke();
740
818
  }
741
819
 
742
820
  protected void OnAdLoadFailed(string error)
743
821
  {
744
822
  Log($"[Ad] {adType} OnAdLoadFailed: {error}");
745
-
746
- if (_isInterstitial)
747
- Ads.Events.OnInterstitialLoadFailed?.Invoke(error);
748
823
  }
749
824
  }
750
-
751
- public class AdListener
752
- {
753
- public Action OnRewardedAvailable;
754
- public Action OnRewardedUnavailable;
755
- public Action OnRewardedOpened;
756
- public Action OnRewardedReceived;
757
- public Action OnRewardedClicked;
758
- public Action OnRewardedShowFailed;
759
- public Action OnRewardedClosed;
760
-
761
- public Action OnInterstitialOpened;
762
- public Action OnInterstitialShowSucceeded;
763
- public Action OnInterstitialShowFailed;
764
- public Action OnInterstitialClicked;
765
- public Action OnInterstitialClosed;
766
- public Action OnInterstitialLoadSucceeded;
767
- public Action<string> OnInterstitialLoadFailed;
768
-
769
- public Action OnShowTimeout;
770
- public Action<object> OnAdImpression;
771
- }
772
825
  }
@@ -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.25";
17
+ public const string VERSION = "0.2.27";
18
18
 
19
19
  internal static AmaGDK _instance;
20
20
  internal static Status _status = Status.None;
@@ -297,6 +297,7 @@ namespace Amanotes.Core
297
297
  }
298
298
 
299
299
  UpdateManifest(output);
300
+ Log("AmaGDK changes to dev mode successfully");
300
301
  }
301
302
 
302
303
  private string RunShellCommand(string command)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.2.25",
3
+ "version": "0.2.27",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2019.4",