com.amanotes.gdk 0.2.46 → 0.2.47
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 +4 -0
- package/Editor/AmaGDKEditor.cs +281 -104
- package/Editor/MatchSDKVersion.cs +3 -6
- package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +5 -1
- package/Extra/AmaGDKInstaller.unitypackage +0 -0
- package/Extra/AmaGDKProject.unitypackage +0 -0
- package/Packages/AmaGDKConfig.unitypackage +0 -0
- package/Packages/AmaGDKExample.unitypackage +0 -0
- package/Packages/AmaGDKTest.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.unitypackage +0 -0
- package/Packages/{FirebaseRemoteConfigAdapter_v9.1.0.unitypackage.meta → AppsFlyerAdapter.unitypackage.meta} +1 -1
- package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
- package/Packages/{AppsFlyerAdapter_v6.5.4.unitypackage.meta → FirebaseAnalyticsAdapter.unitypackage.meta} +1 -1
- package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
- package/Packages/{IronSourceAdapter_v7.5.2.unitypackage.meta → FirebaseRemoteConfigAdapter.unitypackage.meta} +1 -1
- package/Packages/IronSourceAdapter.unitypackage +0 -0
- package/Packages/{FirebaseAnalyticsAdapter_v9.1.0.unitypackage.meta → IronSourceAdapter.unitypackage.meta} +1 -1
- package/Packages/RevenueCatAdapter.unitypackage +0 -0
- package/Packages/RevenueCatAdapter.unitypackage.meta +7 -0
- package/Runtime/AmaGDK.Adapters.cs +55 -77
- package/Runtime/AmaGDK.Ads.cs +160 -174
- package/Runtime/AmaGDK.Analytics.cs +245 -125
- package/Runtime/AmaGDK.Config.cs +2 -1
- package/Runtime/AmaGDK.IAP.cs +47 -48
- package/Runtime/AmaGDK.RemoteConfig.cs +38 -35
- package/Runtime/AmaGDK.UserProfile.cs +27 -19
- package/Runtime/AmaGDK.cs +158 -111
- package/Runtime/Core.meta +8 -0
- package/Runtime/Internal/AmaGDK.Internal.AmaGUI.cs +8 -3
- package/Runtime/Internal/AmaGDK.Internal.SemVer.cs +21 -17
- package/Runtime/Internal/AmaGDK.Internal.cs +17 -6
- package/Runtime/Internal/AmaGDK.Utils.cs +78 -11
- package/package.json +1 -1
- package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
- package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage +0 -0
- package/Packages/IronSourceAdapter_v7.5.2.unitypackage +0 -0
- package/Packages/IronsourceAdapter_v7.2.6.unitypackage +0 -0
- package/Packages/IronsourceAdapter_v7.2.6.unitypackage.meta +0 -7
- package/Packages/RevenueCatAdapter_v6.0.0.unitypackage +0 -0
- package/Packages/RevenueCatAdapter_v6.0.0.unitypackage.meta +0 -7
package/Runtime/AmaGDK.Ads.cs
CHANGED
|
@@ -3,6 +3,7 @@ using System.Collections;
|
|
|
3
3
|
using System.Collections.Generic;
|
|
4
4
|
using UnityEngine;
|
|
5
5
|
using Amanotes.Core.Internal;
|
|
6
|
+
|
|
6
7
|
using static Amanotes.Core.Internal.Logging;
|
|
7
8
|
using static Amanotes.Core.AmaGDK;
|
|
8
9
|
|
|
@@ -96,7 +97,6 @@ namespace Amanotes.Core
|
|
|
96
97
|
return isValid;
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
|
-
|
|
100
100
|
public partial class AmaGDK // Ads module
|
|
101
101
|
{
|
|
102
102
|
[Serializable]
|
|
@@ -168,27 +168,30 @@ namespace Amanotes.Core
|
|
|
168
168
|
|
|
169
169
|
public partial class Ads
|
|
170
170
|
{
|
|
171
|
-
public static ShowAdContext context;
|
|
172
171
|
public static bool allowAdRequest = true;
|
|
173
172
|
|
|
174
|
-
internal
|
|
175
|
-
internal static IAdAdapter _adapter;
|
|
176
|
-
internal static float _savedVolume = -1;
|
|
177
|
-
internal static float _savedTimeScale = -1;
|
|
178
|
-
|
|
173
|
+
// internal use
|
|
179
174
|
internal static readonly AdsData localData = new AdsData().LoadJsonFromFile();
|
|
180
|
-
|
|
181
|
-
|
|
175
|
+
|
|
176
|
+
internal protected static AdShowContext context;
|
|
177
|
+
internal protected static AdAdapter _adapter;
|
|
178
|
+
internal protected static float _savedVolume = -1;
|
|
179
|
+
internal protected static float _savedTimeScale = -1;
|
|
182
180
|
}
|
|
183
181
|
|
|
184
182
|
public partial class Ads // Public
|
|
185
183
|
{
|
|
186
|
-
internal static
|
|
184
|
+
internal static bool InitModule()
|
|
187
185
|
{
|
|
188
|
-
_adapter =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
186
|
+
_adapter = Adapter2.GetAdapter<AdAdapter>();
|
|
187
|
+
return _adapter == null;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
internal static void StartModule()
|
|
191
|
+
{
|
|
192
|
+
if (_adapter == null) return;
|
|
193
|
+
_adapter.interstitial.StartLoadAd();
|
|
194
|
+
_adapter.rewardVideo.StartLoadAd();
|
|
192
195
|
|
|
193
196
|
if (_isBannerShowing)
|
|
194
197
|
{
|
|
@@ -201,92 +204,54 @@ namespace Amanotes.Core
|
|
|
201
204
|
public static bool HasRewardedVideo => _adapter.rewardVideo.hasAd;
|
|
202
205
|
public static bool IsBannerShowing => _isBannerShowing;
|
|
203
206
|
public static bool IsAdShowing => context != null;
|
|
204
|
-
|
|
207
|
+
|
|
205
208
|
private static bool ClearPrevContext()
|
|
206
209
|
{
|
|
207
210
|
if (context == null) return true;
|
|
208
211
|
float duration = Time.realtimeSinceStartup - context.showCallAt;
|
|
209
|
-
// bool willSkip = duration < Mathf.Max(60f, _adConfig.adShowTimeoutInSecs);
|
|
210
212
|
LogWarning($"[AD] ShowRequest IGNORED as another ad is showing (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
|
|
211
213
|
return false;
|
|
212
|
-
|
|
213
|
-
// if (willSkip)
|
|
214
|
-
// {
|
|
215
|
-
// LogWarning($"[AD] ShowRequest IGNORED as another ad is showing (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
|
|
216
|
-
// return false;
|
|
217
|
-
// }
|
|
218
|
-
//
|
|
219
|
-
// LogWarning($"[AD] FORCE STOPPED the previous ad, as it seems to hang (elapsedTime: {duration:n2}s):\n" + JsonUtility.ToJson(context, true));
|
|
220
|
-
// // possibly hang: force stop
|
|
221
|
-
// if (context.adType == AdType.Interstitial)
|
|
222
|
-
// {
|
|
223
|
-
// _adapter.interstitial.StopShowAd();
|
|
224
|
-
// } else
|
|
225
|
-
// {
|
|
226
|
-
// _adapter.rewardVideo.StopShowAd();
|
|
227
|
-
// }
|
|
228
|
-
// return true;
|
|
229
214
|
}
|
|
230
215
|
|
|
231
216
|
public static IAdCallback ShowInterstitial(string placementName = null, Dictionary<string, object> userData = null)
|
|
232
217
|
{
|
|
233
218
|
if (!ClearPrevContext()) return null;
|
|
234
219
|
|
|
235
|
-
context = new
|
|
220
|
+
context = new AdShowContext(AdType.Interstitial, placementName, userData);
|
|
236
221
|
_adapter.interstitial.StartShowAd();
|
|
237
222
|
return context;
|
|
238
223
|
}
|
|
239
224
|
|
|
240
|
-
public static bool IsInterstitialShowing
|
|
241
|
-
{
|
|
242
|
-
get
|
|
243
|
-
{
|
|
244
|
-
if (context == null) return false;
|
|
245
|
-
return context.adType == AdType.Interstitial;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
225
|
+
public static bool IsInterstitialShowing => (context != null) && (context.adType == AdType.Interstitial);
|
|
248
226
|
|
|
249
227
|
public static IAdCallback ShowRewardedVideo(string placementName = null, Dictionary<string, object> userData = null)
|
|
250
228
|
{
|
|
251
229
|
if (!ClearPrevContext()) return null;
|
|
252
|
-
|
|
253
|
-
context = new
|
|
230
|
+
|
|
231
|
+
context = new AdShowContext(AdType.VideoReward, placementName, userData);
|
|
254
232
|
_adapter.rewardVideo.StartShowAd();
|
|
255
233
|
return context;
|
|
256
234
|
}
|
|
257
|
-
|
|
258
|
-
public static bool IsRewardedVideoShowing
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
{
|
|
262
|
-
if (context == null) return false;
|
|
263
|
-
return context.adType == AdType.VideoReward;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
235
|
+
|
|
236
|
+
public static bool IsRewardedVideoShowing => (context != null) && (context.adType == AdType.VideoReward);
|
|
237
|
+
|
|
238
|
+
|
|
267
239
|
private static bool _isBannerShowing;
|
|
268
|
-
private static BannerPosition
|
|
240
|
+
private static BannerPosition _showingBannerPosition;
|
|
269
241
|
|
|
270
242
|
public static void ShowBanner(BannerPosition? bannerPosition = null)
|
|
271
243
|
{
|
|
272
244
|
if (_isBannerShowing) return;
|
|
273
245
|
_isBannerShowing = true;
|
|
274
|
-
_showingBannerPosition = bannerPosition;
|
|
275
|
-
|
|
246
|
+
_showingBannerPosition = bannerPosition ?? Config.ad.bannerPosition;
|
|
247
|
+
|
|
276
248
|
if (_adapter == null)
|
|
277
249
|
{
|
|
278
250
|
//Debug.LogWarning("Adapter not found???");
|
|
279
251
|
return;
|
|
280
252
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
{
|
|
284
|
-
//Debug.LogWarning("_adConfig not found???");
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
_showingBannerPosition = bannerPosition ?? _adConfig.bannerPosition;
|
|
289
|
-
_adapter.ShowBanner(_showingBannerPosition.Value);
|
|
253
|
+
|
|
254
|
+
_adapter.ShowBanner(_showingBannerPosition);
|
|
290
255
|
}
|
|
291
256
|
|
|
292
257
|
public static void HideBanner()
|
|
@@ -306,7 +271,7 @@ namespace Amanotes.Core
|
|
|
306
271
|
else
|
|
307
272
|
_adapter.rewardVideo.StopShowAd();
|
|
308
273
|
}
|
|
309
|
-
|
|
274
|
+
|
|
310
275
|
/// <summary>
|
|
311
276
|
/// Capping for interstitial ad
|
|
312
277
|
/// - Time since last interstitial show success > interstitialCappingTime
|
|
@@ -321,16 +286,16 @@ namespace Amanotes.Core
|
|
|
321
286
|
bool rewardCapped = (rewardedVideoCappingTime > 0) && TimeSinceLastVideoRewardSucceed < rewardedVideoCappingTime;
|
|
322
287
|
return interCapped || rewardCapped;
|
|
323
288
|
}
|
|
324
|
-
|
|
289
|
+
|
|
325
290
|
public static int TimeSinceLastInterstitialSucceed => localData.TimeSinceLastShowSuccess(AdType.Interstitial);
|
|
326
291
|
public static int TimeSinceLastVideoRewardSucceed => localData.TimeSinceLastShowSuccess(AdType.VideoReward);
|
|
327
|
-
public static int TimeSinceLastAdSucceed => Math.Min(TimeSinceLastInterstitialSucceed, TimeSinceLastVideoRewardSucceed)
|
|
292
|
+
public static int TimeSinceLastAdSucceed => Math.Min(TimeSinceLastInterstitialSucceed, TimeSinceLastVideoRewardSucceed);
|
|
328
293
|
public static int TimeSinceLastInterstitialShowCalled => localData.TimeSinceLastShowCalled(AdType.Interstitial);
|
|
329
294
|
public static int TimeSinceLastVideoRewardShowCalled => localData.TimeSinceLastShowCalled(AdType.VideoReward);
|
|
330
|
-
|
|
295
|
+
|
|
331
296
|
public static int InterstitialShowCalledInSession => localData.ShowCallCount(AdType.Interstitial);
|
|
332
297
|
public static int RewardVideoShowCalledInSession => localData.ShowCallCount(AdType.VideoReward);
|
|
333
|
-
|
|
298
|
+
|
|
334
299
|
public static void SetUserId(string userId)
|
|
335
300
|
{
|
|
336
301
|
_adapter.SetUserId(userId);
|
|
@@ -341,22 +306,51 @@ namespace Amanotes.Core
|
|
|
341
306
|
|
|
342
307
|
namespace Amanotes.Core.Internal
|
|
343
308
|
{
|
|
344
|
-
public
|
|
309
|
+
[Serializable] public class AdModuleConfig
|
|
310
|
+
{
|
|
311
|
+
// [Header("----- MODULE CONFIG -----")]
|
|
312
|
+
// public bool manualInit;
|
|
313
|
+
public int adLoadTimeoutInSecs = 60;
|
|
314
|
+
public int adShowTimeoutInSecs = 5;
|
|
315
|
+
public BannerPosition bannerPosition = BannerPosition.BOTTOM;
|
|
316
|
+
public bool autoLogEvent = true;
|
|
317
|
+
|
|
318
|
+
public bool enableInterstitial = true;
|
|
319
|
+
public bool enableRewarded = true;
|
|
320
|
+
public bool enableBanner = true;
|
|
321
|
+
|
|
322
|
+
public bool autoMute = true;
|
|
323
|
+
public bool autoTimeScale = true;
|
|
324
|
+
|
|
325
|
+
[Header("EDITOR")]
|
|
326
|
+
[Range(0f, 1f)] public float rewardAdShowSuccessRate = 1;
|
|
327
|
+
}
|
|
345
328
|
|
|
346
|
-
public
|
|
329
|
+
public partial class ConfigAsset
|
|
330
|
+
{
|
|
331
|
+
[SerializeField] public AdModuleConfig ad;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
[Serializable] public abstract class AdAdapter : Adapter2
|
|
347
335
|
{
|
|
348
|
-
|
|
349
|
-
|
|
336
|
+
protected AdShowContext context => Ads.context;
|
|
337
|
+
protected AdModuleConfig moduleConfig => Config.ad;
|
|
350
338
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
void ShowBanner(BannerPosition position);
|
|
355
|
-
void HideBanner();
|
|
339
|
+
// APIs
|
|
340
|
+
internal protected abstract AdLogic interstitial { get; }
|
|
341
|
+
internal protected abstract AdLogic rewardVideo { get; }
|
|
356
342
|
|
|
357
|
-
void
|
|
358
|
-
|
|
343
|
+
public abstract void ShowBanner(BannerPosition bannerPosition);
|
|
344
|
+
public abstract void HideBanner();
|
|
359
345
|
|
|
346
|
+
// Internally used
|
|
347
|
+
internal protected abstract void HandleBeforeAdShow();
|
|
348
|
+
internal protected abstract void HandleAfterAdShow();
|
|
349
|
+
internal protected abstract void SetUserId(string userId);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
public interface IAdCallback { }
|
|
353
|
+
|
|
360
354
|
public enum LoadAdsState
|
|
361
355
|
{
|
|
362
356
|
None,
|
|
@@ -412,7 +406,7 @@ namespace Amanotes.Core.Internal
|
|
|
412
406
|
Ready,
|
|
413
407
|
}
|
|
414
408
|
|
|
415
|
-
public class
|
|
409
|
+
public class AdShowContext : IAdCallback
|
|
416
410
|
{
|
|
417
411
|
public readonly AdType adType;
|
|
418
412
|
public readonly string placementName;
|
|
@@ -433,7 +427,7 @@ namespace Amanotes.Core.Internal
|
|
|
433
427
|
public float showCallAt;
|
|
434
428
|
public float showFinishAt;
|
|
435
429
|
|
|
436
|
-
public
|
|
430
|
+
public AdShowContext(AdType adType, string placementName, Dictionary<string, object> userData)
|
|
437
431
|
{
|
|
438
432
|
this.adType = adType;
|
|
439
433
|
this.userData = userData;
|
|
@@ -452,6 +446,10 @@ namespace Amanotes.Core.Internal
|
|
|
452
446
|
|
|
453
447
|
public abstract class AdLogic
|
|
454
448
|
{
|
|
449
|
+
internal protected AdAdapter adapter => Ads._adapter;
|
|
450
|
+
protected AdModuleConfig adConfig => Config.ad;
|
|
451
|
+
protected AdShowContext context => Ads.context;
|
|
452
|
+
|
|
455
453
|
internal LoadAdsState _loadState = LoadAdsState.None;
|
|
456
454
|
internal bool hasAd
|
|
457
455
|
{
|
|
@@ -463,7 +461,7 @@ namespace Amanotes.Core.Internal
|
|
|
463
461
|
_loadState = LoadAdsState.None;
|
|
464
462
|
StartLoadAd();
|
|
465
463
|
}
|
|
466
|
-
|
|
464
|
+
|
|
467
465
|
return _loadState == LoadAdsState.Ready;
|
|
468
466
|
}
|
|
469
467
|
}
|
|
@@ -481,7 +479,7 @@ namespace Amanotes.Core.Internal
|
|
|
481
479
|
Log("[Ad] StartLoadAd");
|
|
482
480
|
_loadRoutine = _instance.StartCoroutine(LoadAdRoutine());
|
|
483
481
|
}
|
|
484
|
-
|
|
482
|
+
|
|
485
483
|
public void StopLoadAd()
|
|
486
484
|
{
|
|
487
485
|
Log("[Ad] StopLoadAd");
|
|
@@ -489,7 +487,7 @@ namespace Amanotes.Core.Internal
|
|
|
489
487
|
{
|
|
490
488
|
_loadState = LoadAdsState.None;
|
|
491
489
|
}
|
|
492
|
-
|
|
490
|
+
|
|
493
491
|
if (_loadRoutine == null) return;
|
|
494
492
|
_instance.StopCoroutine(_loadRoutine);
|
|
495
493
|
_loadRoutine = null;
|
|
@@ -503,7 +501,7 @@ namespace Amanotes.Core.Internal
|
|
|
503
501
|
_loadState = LoadAdsState.Ready;
|
|
504
502
|
yield break;
|
|
505
503
|
}
|
|
506
|
-
|
|
504
|
+
|
|
507
505
|
var wait1Sec = new WaitForSecondsRealtime(1f);
|
|
508
506
|
Log("[Ad] LoadAdRoutine start(): isAdReady = " + isAdReady);
|
|
509
507
|
while (true)
|
|
@@ -515,19 +513,19 @@ namespace Amanotes.Core.Internal
|
|
|
515
513
|
Log("[Ad] LoadAdRoutine: allowAdRequest = false");
|
|
516
514
|
continue;
|
|
517
515
|
}
|
|
518
|
-
|
|
516
|
+
|
|
519
517
|
if (!HasLocalNetworkConnection)
|
|
520
518
|
{
|
|
521
519
|
Log("[Ad] LoadAdRoutine: hasInternet = " + HasLocalNetworkConnection);
|
|
522
520
|
continue;
|
|
523
521
|
}
|
|
524
|
-
|
|
522
|
+
|
|
525
523
|
_loadState = LoadAdsState.Requesting;
|
|
526
524
|
_isRequesting = true;
|
|
527
525
|
Log("[Ad] LoadAdRoutine: RequestAd()");
|
|
528
526
|
RequestAd();
|
|
529
527
|
|
|
530
|
-
int timeout =
|
|
528
|
+
int timeout = Config.ad.adLoadTimeoutInSecs;
|
|
531
529
|
var counter = 0;
|
|
532
530
|
|
|
533
531
|
while (counter < timeout || timeout == -1)
|
|
@@ -576,15 +574,15 @@ namespace Amanotes.Core.Internal
|
|
|
576
574
|
{
|
|
577
575
|
LogWarning("[Ad] StartShowAd() --> Invalid _showState: " + _showState);
|
|
578
576
|
}
|
|
579
|
-
|
|
577
|
+
|
|
580
578
|
Log($"[Ad] {adType} StartShowAd");
|
|
581
579
|
_showState = ShowAdsState.ShowCalled;
|
|
582
|
-
|
|
583
|
-
AdStat stat = Ads.localData.GetStat(adType);
|
|
580
|
+
|
|
581
|
+
AdStat stat = Ads.localData.GetStat(adType);
|
|
584
582
|
stat.callCount++;
|
|
585
583
|
stat.lastCallTime = Time.realtimeSinceStartup;
|
|
586
584
|
OnAdShowCalled();
|
|
587
|
-
|
|
585
|
+
|
|
588
586
|
if (_showAdRoutine != null) _instance.StopCoroutine(_showAdRoutine);
|
|
589
587
|
_showAdRoutine = _instance.StartCoroutine(ShowAdRoutine());
|
|
590
588
|
}
|
|
@@ -598,7 +596,7 @@ namespace Amanotes.Core.Internal
|
|
|
598
596
|
_loadState = LoadAdsState.None;
|
|
599
597
|
StartLoadAd();
|
|
600
598
|
}
|
|
601
|
-
|
|
599
|
+
|
|
602
600
|
HandleAfterAdShow();
|
|
603
601
|
if (_showAdRoutine == null) return;
|
|
604
602
|
_instance.StopCoroutine(_showAdRoutine);
|
|
@@ -606,9 +604,8 @@ namespace Amanotes.Core.Internal
|
|
|
606
604
|
|
|
607
605
|
if (Ads.context.adType == AdType.Interstitial)
|
|
608
606
|
{
|
|
609
|
-
ShowAdRoutineCompleted(!Ads.context.hasFailedOrCancelled);
|
|
610
|
-
}
|
|
611
|
-
else
|
|
607
|
+
ShowAdRoutineCompleted(!Ads.context.hasFailedOrCancelled);
|
|
608
|
+
} else
|
|
612
609
|
{
|
|
613
610
|
ShowAdRoutineCompleted(Ads.context.hasReward);
|
|
614
611
|
}
|
|
@@ -618,7 +615,7 @@ namespace Amanotes.Core.Internal
|
|
|
618
615
|
{
|
|
619
616
|
// Wait to end frame so that all AdCallbacks finish registering
|
|
620
617
|
yield return new WaitForEndOfFrame();
|
|
621
|
-
|
|
618
|
+
|
|
622
619
|
// Wait for Ad
|
|
623
620
|
if (!isAdReady)
|
|
624
621
|
{
|
|
@@ -627,7 +624,7 @@ namespace Amanotes.Core.Internal
|
|
|
627
624
|
LogWarning("[Ad] Inconsistent state report: isAdReady == false while _loadState == Ready");
|
|
628
625
|
_loadState = LoadAdsState.None;
|
|
629
626
|
}
|
|
630
|
-
|
|
627
|
+
|
|
631
628
|
if (!HasLocalNetworkConnection)
|
|
632
629
|
{
|
|
633
630
|
_showState = ShowAdsState.ShowFail;
|
|
@@ -635,8 +632,8 @@ namespace Amanotes.Core.Internal
|
|
|
635
632
|
ShowAdRoutineCompleted(false);
|
|
636
633
|
yield break;
|
|
637
634
|
}
|
|
638
|
-
|
|
639
|
-
int timeout =
|
|
635
|
+
|
|
636
|
+
int timeout = Config.ad.adShowTimeoutInSecs;
|
|
640
637
|
if (timeout == 0) // do not wait for Ad
|
|
641
638
|
{
|
|
642
639
|
_showState = ShowAdsState.ShowFail;
|
|
@@ -644,15 +641,15 @@ namespace Amanotes.Core.Internal
|
|
|
644
641
|
ShowAdRoutineCompleted(false);
|
|
645
642
|
yield break;
|
|
646
643
|
}
|
|
647
|
-
|
|
644
|
+
|
|
648
645
|
_showState = ShowAdsState.WaitForAd;
|
|
649
646
|
OnAdShowReadyStatus(false, AdShowReadyStatus.WaitForAd);
|
|
650
|
-
|
|
647
|
+
|
|
651
648
|
if (_loadState != LoadAdsState.Requesting) StartLoadAd();
|
|
652
649
|
var counter = 0;
|
|
653
650
|
bool? hasInternet = null;
|
|
654
651
|
_instance.StartCoroutine(WebUtils.CheckInternet(result => hasInternet = result));
|
|
655
|
-
|
|
652
|
+
|
|
656
653
|
var wait1Sec = new WaitForSecondsRealtime(1f);
|
|
657
654
|
while (counter < timeout || timeout == -1)
|
|
658
655
|
{
|
|
@@ -673,7 +670,7 @@ namespace Amanotes.Core.Internal
|
|
|
673
670
|
Log("[Ad] WaitForAd success after " + counter + " | timeout = " + timeout + " secs");
|
|
674
671
|
break;
|
|
675
672
|
}
|
|
676
|
-
|
|
673
|
+
|
|
677
674
|
if (!isAdReady)
|
|
678
675
|
{
|
|
679
676
|
Log("[Ad] WaitForAd failed (timeout) " + counter + " | timeout = " + timeout + " secs");
|
|
@@ -682,13 +679,13 @@ namespace Amanotes.Core.Internal
|
|
|
682
679
|
yield break;
|
|
683
680
|
}
|
|
684
681
|
}
|
|
685
|
-
|
|
682
|
+
|
|
686
683
|
_showState = ShowAdsState.Showing;
|
|
687
684
|
OnAdShowReadyStatus(true, AdShowReadyStatus.Ready);
|
|
688
685
|
HandleBeforeAdShow();
|
|
689
686
|
ShowAd();
|
|
690
|
-
|
|
691
|
-
|
|
687
|
+
|
|
688
|
+
AdShowContext context = Ads.context;
|
|
692
689
|
while (!context.potentiallyCompleted)
|
|
693
690
|
{
|
|
694
691
|
yield return null; // callback as quickly as possible
|
|
@@ -715,7 +712,7 @@ namespace Amanotes.Core.Internal
|
|
|
715
712
|
ShowAdRoutineCompleted(context.hasReward);
|
|
716
713
|
yield break;
|
|
717
714
|
}
|
|
718
|
-
|
|
715
|
+
|
|
719
716
|
while (!context.hasClosed)
|
|
720
717
|
{
|
|
721
718
|
Log($"[Ad] {adType} Waiting for [close]");
|
|
@@ -727,25 +724,18 @@ namespace Amanotes.Core.Internal
|
|
|
727
724
|
|
|
728
725
|
private void ShowAdRoutineCompleted(bool isSuccess)
|
|
729
726
|
{
|
|
730
|
-
ShowAdContext lastContext = Ads.context;
|
|
731
|
-
Ads.context = null;
|
|
732
|
-
if (lastContext == null)
|
|
733
|
-
{
|
|
734
|
-
LogWarning("Something wrong: lastContext == null!");
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
727
|
if (_loadState == LoadAdsState.Ready)
|
|
739
728
|
{
|
|
740
729
|
_loadState = isAdReady ? LoadAdsState.Ready : LoadAdsState.None;
|
|
741
730
|
if (_loadState == LoadAdsState.None) StartLoadAd();
|
|
742
731
|
}
|
|
743
|
-
|
|
732
|
+
|
|
744
733
|
_showState = isSuccess ? ShowAdsState.ShowSuccess : ShowAdsState.ShowFail;
|
|
745
|
-
|
|
734
|
+
|
|
746
735
|
// Extra callback
|
|
747
|
-
|
|
748
|
-
|
|
736
|
+
Ads.context.showFinishAt = Time.realtimeSinceStartup;
|
|
737
|
+
Ads.context.onAdResult?.Invoke(isSuccess);
|
|
738
|
+
|
|
749
739
|
var localData = Ads.localData;
|
|
750
740
|
var stat = _isInterstitial ? localData.interstitial : localData.reward;
|
|
751
741
|
if (isSuccess)
|
|
@@ -753,8 +743,7 @@ namespace Amanotes.Core.Internal
|
|
|
753
743
|
stat.success++;
|
|
754
744
|
stat.successTotal++;
|
|
755
745
|
stat.lastSuccessTime = (int)Time.realtimeSinceStartup;
|
|
756
|
-
}
|
|
757
|
-
else
|
|
746
|
+
} else
|
|
758
747
|
{
|
|
759
748
|
stat.failed++;
|
|
760
749
|
stat.failedTotal++;
|
|
@@ -762,59 +751,60 @@ namespace Amanotes.Core.Internal
|
|
|
762
751
|
|
|
763
752
|
localData.Save();
|
|
764
753
|
HandleAfterAdShow();
|
|
765
|
-
|
|
766
|
-
Log($"[Ad] {adType} ShowAdRoutineCompleted: {isSuccess}\n{JsonUtility.ToJson(
|
|
767
|
-
|
|
754
|
+
|
|
755
|
+
Log($"[Ad] {adType} ShowAdRoutineCompleted: {isSuccess}\n{JsonUtility.ToJson(Ads.context)}");
|
|
756
|
+
Ads.context = null;
|
|
757
|
+
_showState = ShowAdsState.None;
|
|
768
758
|
}
|
|
769
|
-
|
|
759
|
+
|
|
770
760
|
private void HandleBeforeAdShow()
|
|
771
761
|
{
|
|
772
|
-
bool willSaveVolume =
|
|
762
|
+
bool willSaveVolume = Config.ad.autoMute
|
|
773
763
|
&& AudioListener.volume > 0
|
|
774
764
|
&& Ads._savedVolume < 0;
|
|
775
|
-
|
|
776
|
-
bool willSaveTimeScale =
|
|
765
|
+
|
|
766
|
+
bool willSaveTimeScale = Config.ad.autoTimeScale
|
|
777
767
|
&& Time.timeScale > 0
|
|
778
768
|
&& Ads._savedTimeScale < 0;
|
|
779
|
-
|
|
769
|
+
|
|
780
770
|
if (willSaveVolume)
|
|
781
771
|
{
|
|
782
772
|
Ads._savedVolume = AudioListener.volume;
|
|
783
773
|
AudioListener.volume = 0;
|
|
784
774
|
}
|
|
785
|
-
|
|
775
|
+
|
|
786
776
|
if (willSaveTimeScale)
|
|
787
777
|
{
|
|
788
778
|
Ads._savedTimeScale = Time.timeScale;
|
|
789
779
|
Time.timeScale = 0;
|
|
790
780
|
}
|
|
791
|
-
|
|
781
|
+
|
|
792
782
|
Ads.context.onBeforeAdOpen?.Invoke();
|
|
793
783
|
Ads._adapter.HandleBeforeAdShow();
|
|
794
784
|
}
|
|
795
|
-
|
|
785
|
+
|
|
796
786
|
private void HandleAfterAdShow()
|
|
797
787
|
{
|
|
798
|
-
bool willRestoreVolume =
|
|
788
|
+
bool willRestoreVolume = Config.ad.autoMute
|
|
799
789
|
&& AudioListener.volume == 0
|
|
800
790
|
&& Ads._savedVolume > 0;
|
|
801
|
-
|
|
802
|
-
bool willRestoreTimeScale =
|
|
791
|
+
|
|
792
|
+
bool willRestoreTimeScale = Config.ad.autoTimeScale
|
|
803
793
|
&& Time.timeScale == 0
|
|
804
794
|
&& Ads._savedTimeScale > 0;
|
|
805
|
-
|
|
795
|
+
|
|
806
796
|
if (willRestoreVolume)
|
|
807
797
|
{
|
|
808
798
|
AudioListener.volume = Ads._savedVolume;
|
|
809
799
|
Ads._savedVolume = -1;
|
|
810
800
|
}
|
|
811
|
-
|
|
801
|
+
|
|
812
802
|
if (willRestoreTimeScale)
|
|
813
803
|
{
|
|
814
804
|
Time.timeScale = Ads._savedTimeScale;
|
|
815
805
|
Ads._savedTimeScale = -1;
|
|
816
806
|
}
|
|
817
|
-
|
|
807
|
+
|
|
818
808
|
Ads._adapter.HandleAfterAdShow();
|
|
819
809
|
}
|
|
820
810
|
|
|
@@ -822,13 +812,12 @@ namespace Amanotes.Core.Internal
|
|
|
822
812
|
protected void OnAdClosed()
|
|
823
813
|
{
|
|
824
814
|
Log($"[Ad] {adType} OnAdClosed");
|
|
825
|
-
|
|
815
|
+
|
|
826
816
|
if (Ads.context != null)
|
|
827
817
|
{
|
|
828
818
|
Ads.context.adCallback |= AdCallback.Close;
|
|
829
819
|
Ads.context.onClosed?.Invoke();
|
|
830
|
-
}
|
|
831
|
-
else
|
|
820
|
+
} else
|
|
832
821
|
{
|
|
833
822
|
LogWarning("[Ad] OnAdClosed() Something wrong - No AdContext");
|
|
834
823
|
}
|
|
@@ -837,13 +826,12 @@ namespace Amanotes.Core.Internal
|
|
|
837
826
|
protected void OnAdClicked()
|
|
838
827
|
{
|
|
839
828
|
Log($"[Ad] {adType} OnAdClicked");
|
|
840
|
-
|
|
829
|
+
|
|
841
830
|
if (Ads.context != null)
|
|
842
831
|
{
|
|
843
832
|
Ads.context.adCallback |= AdCallback.Click;
|
|
844
833
|
Ads.context.onClicked?.Invoke();
|
|
845
|
-
}
|
|
846
|
-
else
|
|
834
|
+
} else
|
|
847
835
|
{
|
|
848
836
|
LogWarning("[Ad] OnAdClicked() Something wrong - No AdContext");
|
|
849
837
|
}
|
|
@@ -852,13 +840,12 @@ namespace Amanotes.Core.Internal
|
|
|
852
840
|
protected void OnAdShowFailed()
|
|
853
841
|
{
|
|
854
842
|
Log($"[Ad] {adType} OnAdShowFailed");
|
|
855
|
-
|
|
843
|
+
|
|
856
844
|
if (Ads.context != null)
|
|
857
845
|
{
|
|
858
846
|
Ads.context.adCallback |= AdCallback.Fail;
|
|
859
847
|
Ads.context.onShowFailed?.Invoke();
|
|
860
|
-
}
|
|
861
|
-
else
|
|
848
|
+
} else
|
|
862
849
|
{
|
|
863
850
|
LogWarning("[Ad] OnAdShowFailed() Something wrong - No AdContext");
|
|
864
851
|
}
|
|
@@ -867,13 +854,12 @@ namespace Amanotes.Core.Internal
|
|
|
867
854
|
protected void OnAdShowSucceeded()
|
|
868
855
|
{
|
|
869
856
|
Log($"[Ad] {adType} OnAdShowSucceeded");
|
|
870
|
-
|
|
857
|
+
|
|
871
858
|
if (Ads.context != null)
|
|
872
859
|
{
|
|
873
860
|
Ads.context.adCallback |= AdCallback.Success;
|
|
874
861
|
Ads.context.onShowSuccess?.Invoke();
|
|
875
|
-
}
|
|
876
|
-
else
|
|
862
|
+
} else
|
|
877
863
|
{
|
|
878
864
|
LogWarning("[Ad] OnAdShowSucceeded() Something wrong - No AdContext");
|
|
879
865
|
}
|
|
@@ -886,33 +872,34 @@ namespace Amanotes.Core.Internal
|
|
|
886
872
|
LogWarning("[Ad] OnAdOpen() Something wrong - No AdContext");
|
|
887
873
|
return;
|
|
888
874
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
875
|
+
|
|
876
|
+
Ads.context.adCallback |= AdCallback.ShowReadyStatus;
|
|
877
|
+
Ads.context.onAdShowReadyStatus?.Invoke(status);
|
|
892
878
|
if (status == AdShowReadyStatus.Ready)
|
|
893
|
-
{
|
|
894
|
-
OnAdShowReady();
|
|
895
|
-
}
|
|
896
|
-
else if (status == AdShowReadyStatus.NoInternet || status == AdShowReadyStatus.TimeOut || status == AdShowReadyStatus.Wifi3GDisabled)
|
|
897
879
|
{
|
|
898
|
-
|
|
880
|
+
OnAdShowReady();
|
|
881
|
+
} else if (status == AdShowReadyStatus.NoInternet || status == AdShowReadyStatus.TimeOut || status == AdShowReadyStatus.Wifi3GDisabled)
|
|
882
|
+
{
|
|
883
|
+
OnAdShowNotReady(status);
|
|
899
884
|
}
|
|
900
885
|
}
|
|
901
|
-
|
|
902
|
-
protected virtual void OnAdShowCalled()
|
|
903
|
-
|
|
904
|
-
protected virtual void
|
|
905
|
-
|
|
886
|
+
|
|
887
|
+
protected virtual void OnAdShowCalled()
|
|
888
|
+
{ }
|
|
889
|
+
protected virtual void OnAdShowReady()
|
|
890
|
+
{ }
|
|
891
|
+
protected virtual void OnAdShowNotReady(AdShowReadyStatus status)
|
|
892
|
+
{ }
|
|
893
|
+
|
|
906
894
|
protected void OnAdOpen()
|
|
907
895
|
{
|
|
908
896
|
Log($"[Ad] {adType} OnAdOpen");
|
|
909
|
-
|
|
897
|
+
|
|
910
898
|
if (Ads.context != null)
|
|
911
899
|
{
|
|
912
900
|
Ads.context.adCallback |= AdCallback.Open;
|
|
913
901
|
Ads.context.onOpened?.Invoke();
|
|
914
|
-
}
|
|
915
|
-
else
|
|
902
|
+
} else
|
|
916
903
|
{
|
|
917
904
|
LogWarning("[Ad] OnAdOpen() Something wrong - No AdContext");
|
|
918
905
|
}
|
|
@@ -921,13 +908,12 @@ namespace Amanotes.Core.Internal
|
|
|
921
908
|
protected void OnAdReward()
|
|
922
909
|
{
|
|
923
910
|
Log($"[Ad] {adType} OnAdReward");
|
|
924
|
-
|
|
911
|
+
|
|
925
912
|
if (Ads.context != null)
|
|
926
913
|
{
|
|
927
914
|
Ads.context.adCallback |= AdCallback.Reward;
|
|
928
915
|
Ads.context.onRewardReceived?.Invoke();
|
|
929
|
-
}
|
|
930
|
-
else
|
|
916
|
+
} else
|
|
931
917
|
{
|
|
932
918
|
LogWarning("[Ad] OnAdReward() Something wrong - No AdContext");
|
|
933
919
|
}
|
|
@@ -936,7 +922,7 @@ namespace Amanotes.Core.Internal
|
|
|
936
922
|
protected void OnAdLoadSuccess()
|
|
937
923
|
{
|
|
938
924
|
Log($"[Ad] {adType} OnAdLoadSuccess");
|
|
939
|
-
|
|
925
|
+
|
|
940
926
|
if (!_isRequesting && adType == AdType.Interstitial)
|
|
941
927
|
{
|
|
942
928
|
LogWarning("[Ad] Something wrong? OnAdReady called when no ad is loading! AdType=" + adType);
|