com.amanotes.gdk 0.2.66 → 0.2.67
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 +14 -0
- package/Editor/Extra/GDKAutoUpdateAdapter.cs +67 -0
- package/Editor/Extra/GDKAutoUpdateAdapter.cs.meta +11 -0
- package/Extra/AmaGDKInstaller.unitypackage +0 -0
- package/Extra/CheckDiskSpace.unitypackage +0 -0
- package/Extra/ForceUpdate.unitypackage +0 -0
- package/Extra/GoogleCMP.unitypackage +0 -0
- package/Extra/LegacyGDKUpdateHelper.unitypackage +0 -0
- package/Extra/LegacyGDKUpdateHelper.unitypackage.meta +7 -0
- package/Extra/PostProcessor.unitypackage +0 -0
- package/Packages/AmaGDKConfig.unitypackage +0 -0
- package/Packages/AmaGDKExample.unitypackage +0 -0
- package/Packages/AmaGDKTest.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.PurchaseConnector.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.unitypackage +0 -0
- package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
- package/Packages/IronSourceAdapter.unitypackage +0 -0
- package/Packages/RevenueCatAdapter.unitypackage +0 -0
- package/Packages/SqliteAnalyticsAdapter.unitypackage +0 -0
- package/Runtime/Ad/AdExtension.cs +111 -0
- package/Runtime/Ad/AdExtension.cs.meta +3 -0
- package/Runtime/Ad/AdLogic.cs +530 -0
- package/Runtime/Ad/AdLogic.cs.meta +3 -0
- package/Runtime/Ad/AdModuleConfig.cs +39 -0
- package/Runtime/Ad/AdModuleConfig.cs.meta +3 -0
- package/Runtime/Ad/AdShowContext.cs +43 -0
- package/Runtime/Ad/AdShowContext.cs.meta +3 -0
- package/Runtime/Ad/AmaGDK.Ads.cs +383 -0
- package/Runtime/Ad.meta +8 -0
- package/Runtime/AmaGDK.Analytics.cs +20 -1
- package/Runtime/AmaGDK.Device.cs +105 -0
- package/Runtime/AmaGDK.Device.cs.meta +3 -0
- package/Runtime/AmaGDK.Mono.cs +0 -1
- package/Runtime/AmaGDK.cs +1 -1
- package/Runtime/Fps/AmaFPS.Utils.cs +44 -0
- package/Runtime/Fps/AmaFPS.Utils.cs.meta +3 -0
- package/Runtime/Fps/AmaFPS.cs +197 -0
- package/Runtime/Fps/AmaFPS.cs.meta +11 -0
- package/Runtime/Fps/AmaFPSVisualizer.cs +246 -0
- package/Runtime/Fps/AmaFPSVisualizer.cs.meta +11 -0
- package/Runtime/Fps/BollingerBands.cs +99 -0
- package/Runtime/Fps/BollingerBands.cs.meta +11 -0
- package/Runtime/Fps/FPSVisualizer.prefab +406 -0
- package/Runtime/Fps/FPSVisualizer.prefab.meta +7 -0
- package/Runtime/Fps/FrameRecorder.cs +172 -0
- package/Runtime/Fps/FrameRecorder.cs.meta +3 -0
- package/Runtime/Fps.meta +8 -0
- package/package.json +1 -1
- package/Runtime/AmaGDK.Ads.cs +0 -1077
- /package/Runtime/{AmaGDK.Ads.cs.meta → Ad/AmaGDK.Ads.cs.meta} +0 -0
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
using System.Collections;
|
|
2
|
+
using UnityEngine;
|
|
3
|
+
using static Amanotes.Core.Internal.Logging;
|
|
4
|
+
using static Amanotes.Core.AmaGDK;
|
|
5
|
+
|
|
6
|
+
namespace Amanotes.Core.Internal
|
|
7
|
+
{
|
|
8
|
+
public abstract class AdLogic
|
|
9
|
+
{
|
|
10
|
+
protected AdModuleConfig adConfig => Config.ad;
|
|
11
|
+
protected AdShowContext context => Ads.context;
|
|
12
|
+
|
|
13
|
+
internal LoadAdsState _loadState = LoadAdsState.None;
|
|
14
|
+
internal bool hasAd
|
|
15
|
+
{
|
|
16
|
+
get
|
|
17
|
+
{
|
|
18
|
+
if (_loadState == LoadAdsState.Ready && !isAdReady)
|
|
19
|
+
{
|
|
20
|
+
LogWarning("[Ad] Inconsistent Ready state (might caused by poor internet condition)");
|
|
21
|
+
_loadState = LoadAdsState.None;
|
|
22
|
+
StartLoadAd();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return _loadState == LoadAdsState.Ready;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
internal Coroutine _loadRoutine;
|
|
30
|
+
|
|
31
|
+
public void StartLoadAd()
|
|
32
|
+
{
|
|
33
|
+
if (_loadState != LoadAdsState.None)
|
|
34
|
+
{
|
|
35
|
+
LogWarning("[Ad] StartLoadAd() --> Invalid state: " + _loadState);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Log("[Ad] StartLoadAd");
|
|
40
|
+
_loadRoutine = _instance.StartCoroutine(LoadAdRoutine());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public void StopLoadAd()
|
|
44
|
+
{
|
|
45
|
+
Log("[Ad] StopLoadAd");
|
|
46
|
+
if (_loadState == LoadAdsState.Requesting)
|
|
47
|
+
{
|
|
48
|
+
_loadState = LoadAdsState.None;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (_loadRoutine == null) return;
|
|
52
|
+
_instance.StopCoroutine(_loadRoutine);
|
|
53
|
+
_loadRoutine = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
IEnumerator LoadAdRoutine()
|
|
57
|
+
{
|
|
58
|
+
if (isAdReady)
|
|
59
|
+
{
|
|
60
|
+
Log("[Ad] LoadAdRoutine skipped because isAdReady = true!");
|
|
61
|
+
_loadState = LoadAdsState.Ready;
|
|
62
|
+
yield break;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var wait1Sec = new WaitForSecondsRealtime(1f);
|
|
66
|
+
Log("[Ad] LoadAdRoutine start(): isAdReady = " + isAdReady);
|
|
67
|
+
while (true)
|
|
68
|
+
{
|
|
69
|
+
yield return wait1Sec;
|
|
70
|
+
|
|
71
|
+
if (!Ads.allowAdRequest)
|
|
72
|
+
{
|
|
73
|
+
Log("[Ad] LoadAdRoutine: allowAdRequest = false");
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!HasLocalNetworkConnection)
|
|
78
|
+
{
|
|
79
|
+
Log("[Ad] LoadAdRoutine: hasInternet = " + HasLocalNetworkConnection);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_loadState = LoadAdsState.Requesting;
|
|
84
|
+
_isRequesting = true;
|
|
85
|
+
Log("[Ad] LoadAdRoutine: RequestAd()");
|
|
86
|
+
RequestAd();
|
|
87
|
+
dispatcher.Dispatch(
|
|
88
|
+
_isInterstitial ? AmaGDK.Event.INTER_REQUEST : AmaGDK.Event.REWARD_REQUEST
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
int timeout = Config.ad.adLoadTimeoutInSecs;
|
|
92
|
+
var counter = 0;
|
|
93
|
+
|
|
94
|
+
while (counter < timeout || timeout == -1)
|
|
95
|
+
{
|
|
96
|
+
yield return wait1Sec;
|
|
97
|
+
counter++;
|
|
98
|
+
if (_isRequesting == false) break;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (counter > timeout && timeout > 0) // timeout
|
|
102
|
+
{
|
|
103
|
+
Log("[Ad] LoadAdRoutine: RequestAd not responding (timeout) " + timeout + " secs");
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// request should be completed here!
|
|
108
|
+
if (!isAdReady)
|
|
109
|
+
{
|
|
110
|
+
LogWarning($"[Ad] Request complete but failed! (load duration = {counter} secs)");
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
_loadState = LoadAdsState.Ready;
|
|
115
|
+
Log($"[Ad] LoadAdRoutine: Ad is ready! (load duration = {counter} secs)");
|
|
116
|
+
yield break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
bool HasLocalNetworkConnection => Application.internetReachability != NetworkReachability.NotReachable;
|
|
121
|
+
|
|
122
|
+
// Override by actual Ad instance
|
|
123
|
+
protected abstract AdType adType { get; }
|
|
124
|
+
protected abstract bool isAdReady { get; }
|
|
125
|
+
protected abstract void RequestAd();
|
|
126
|
+
protected abstract void ShowAd();
|
|
127
|
+
|
|
128
|
+
// Show Ad logic
|
|
129
|
+
internal ShowAdsState _showState = ShowAdsState.None;
|
|
130
|
+
private Coroutine _showAdRoutine;
|
|
131
|
+
protected bool _isRequesting;
|
|
132
|
+
protected bool _isInterstitial => adType == AdType.Interstitial;
|
|
133
|
+
|
|
134
|
+
public void StartShowAd()
|
|
135
|
+
{
|
|
136
|
+
unityCallbacks.OnApplicationFocus -= OnApplicationFocus;
|
|
137
|
+
unityCallbacks.OnApplicationFocus += OnApplicationFocus;
|
|
138
|
+
|
|
139
|
+
if (_showState != ShowAdsState.None)
|
|
140
|
+
{
|
|
141
|
+
LogWarning("[Ad] StartShowAd() --> Invalid _showState: " + _showState);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Log($"[Ad] {adType} StartShowAd");
|
|
145
|
+
_showState = ShowAdsState.ShowCalled;
|
|
146
|
+
|
|
147
|
+
AdStat stat = Ads.localData.GetStat(adType);
|
|
148
|
+
stat.callCount++;
|
|
149
|
+
stat.prevCallTime = stat.currentCallTime;
|
|
150
|
+
stat.currentCallTime = Time.realtimeSinceStartup;
|
|
151
|
+
|
|
152
|
+
dispatcher.Dispatch(
|
|
153
|
+
_isInterstitial ? AmaGDK.Event.INTER_SHOW_CALLED : AmaGDK.Event.REWARD_VIDEO_SHOW_CALLED
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
if (_showAdRoutine != null) _instance.StopCoroutine(_showAdRoutine);
|
|
157
|
+
_showAdRoutine = _instance.StartCoroutine(ShowAdRoutine());
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
void OnApplicationFocus(bool isFocus)
|
|
161
|
+
{
|
|
162
|
+
if (!isFocus) return;
|
|
163
|
+
|
|
164
|
+
unityCallbacks.OnApplicationFocus -= OnApplicationFocus;
|
|
165
|
+
if (context == null) return;
|
|
166
|
+
|
|
167
|
+
Log($"OnApplicationFocus Before: {context.hasClosed}");
|
|
168
|
+
context.adCallback |= AdCallback.Close;
|
|
169
|
+
Log($"OnApplicationFocus After: {context.hasClosed}");
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public void StopShowAd()
|
|
173
|
+
{
|
|
174
|
+
Log($"[Ad] {adType} StopShowAd");
|
|
175
|
+
_showState = ShowAdsState.None;
|
|
176
|
+
if (_loadState == LoadAdsState.Ready && !isAdReady)
|
|
177
|
+
{
|
|
178
|
+
_loadState = LoadAdsState.None;
|
|
179
|
+
StartLoadAd();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
TriggerOnAfterAdShow();
|
|
183
|
+
if (_showAdRoutine == null) return;
|
|
184
|
+
_instance.StopCoroutine(_showAdRoutine);
|
|
185
|
+
_showAdRoutine = null;
|
|
186
|
+
|
|
187
|
+
if (Ads.context.adType == AdType.Interstitial)
|
|
188
|
+
{
|
|
189
|
+
ShowAdRoutineCompleted(!Ads.context.hasFailedOrCancelled);
|
|
190
|
+
} else
|
|
191
|
+
{
|
|
192
|
+
ShowAdRoutineCompleted(Ads.context.hasReward);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
IEnumerator ShowAdRoutine()
|
|
197
|
+
{
|
|
198
|
+
// Wait to end frame so that all AdCallbacks finish registering
|
|
199
|
+
yield return new WaitForEndOfFrame();
|
|
200
|
+
|
|
201
|
+
// Wait for Ad
|
|
202
|
+
if (!isAdReady)
|
|
203
|
+
{
|
|
204
|
+
if (_loadState == LoadAdsState.Ready)
|
|
205
|
+
{
|
|
206
|
+
LogWarning("[Ad] Inconsistent state report: isAdReady == false while _loadState == Ready");
|
|
207
|
+
_loadState = LoadAdsState.None;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (!HasLocalNetworkConnection)
|
|
211
|
+
{
|
|
212
|
+
_showState = ShowAdsState.ShowFail;
|
|
213
|
+
OnAdShowReadyStatus(false, AdShowReadyStatus.Wifi3GDisabled);
|
|
214
|
+
ShowAdRoutineCompleted(false);
|
|
215
|
+
yield break;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
int timeout = Config.ad.adShowTimeoutInSecs;
|
|
219
|
+
if (timeout == 0) // do not wait for Ad
|
|
220
|
+
{
|
|
221
|
+
_showState = ShowAdsState.ShowFail;
|
|
222
|
+
OnAdShowReadyStatus(false, AdShowReadyStatus.TimeOut);
|
|
223
|
+
ShowAdRoutineCompleted(false);
|
|
224
|
+
yield break;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
_showState = ShowAdsState.WaitForAd;
|
|
228
|
+
OnAdShowReadyStatus(false, AdShowReadyStatus.WaitForAd);
|
|
229
|
+
|
|
230
|
+
if (_loadState != LoadAdsState.Requesting) StartLoadAd();
|
|
231
|
+
var counter = 0;
|
|
232
|
+
bool? hasInternet = null;
|
|
233
|
+
if (adConfig.checkInternet) _instance.StartCoroutine(WebUtils.CheckInternet(result => hasInternet = result));
|
|
234
|
+
|
|
235
|
+
var wait1Sec = new WaitForSecondsRealtime(1f);
|
|
236
|
+
while (counter < timeout || timeout == -1)
|
|
237
|
+
{
|
|
238
|
+
yield return wait1Sec;
|
|
239
|
+
counter++;
|
|
240
|
+
|
|
241
|
+
// finish checking internet & result is false
|
|
242
|
+
if (adConfig.checkInternet && hasInternet == false)
|
|
243
|
+
{
|
|
244
|
+
Log("[Ad] Stop WaitForAd : No internet!");
|
|
245
|
+
_showState = ShowAdsState.ShowFail;
|
|
246
|
+
OnAdShowReadyStatus(false, AdShowReadyStatus.NoInternet);
|
|
247
|
+
ShowAdRoutineCompleted(false);
|
|
248
|
+
yield break;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (_loadState != LoadAdsState.Ready) continue;
|
|
252
|
+
Log("[Ad] WaitForAd success after " + counter + " | timeout = " + timeout + " secs");
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (!isAdReady)
|
|
257
|
+
{
|
|
258
|
+
Log("[Ad] WaitForAd failed (timeout) " + counter + " | timeout = " + timeout + " secs");
|
|
259
|
+
OnAdShowReadyStatus(false, AdShowReadyStatus.TimeOut);
|
|
260
|
+
ShowAdRoutineCompleted(false);
|
|
261
|
+
yield break;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
_showState = ShowAdsState.Showing;
|
|
266
|
+
OnAdShowReadyStatus(true, AdShowReadyStatus.Ready);
|
|
267
|
+
TriggerBeforeAdShow();
|
|
268
|
+
ShowAd();
|
|
269
|
+
|
|
270
|
+
while (!context.potentiallyCompleted)
|
|
271
|
+
{
|
|
272
|
+
yield return null; // callback as quickly as possible
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (adType == AdType.Interstitial)
|
|
276
|
+
{
|
|
277
|
+
ShowAdRoutineCompleted(!context.hasFailedOrCancelled);
|
|
278
|
+
yield break;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (context.hasFailedOrCancelled)
|
|
282
|
+
{
|
|
283
|
+
Log($"[Ad] {adType} Waiting for [close]");
|
|
284
|
+
yield return null;
|
|
285
|
+
ShowAdRoutineCompleted(false);
|
|
286
|
+
yield break;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (context.hasClosed)
|
|
290
|
+
{
|
|
291
|
+
// wait 1 frame in case hasReward callback after onClose
|
|
292
|
+
if (!context.hasReward) yield return null;
|
|
293
|
+
ShowAdRoutineCompleted(context.hasReward);
|
|
294
|
+
yield break;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
var wait4CloseCounter = 0;
|
|
298
|
+
while (!context.hasClosed)
|
|
299
|
+
{
|
|
300
|
+
wait4CloseCounter++;
|
|
301
|
+
Log($"[Ad] {adType} Waiting for [close]: {wait4CloseCounter}");
|
|
302
|
+
yield return null;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
ShowAdRoutineCompleted(true);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
private void ShowAdRoutineCompleted(bool isSuccess)
|
|
309
|
+
{
|
|
310
|
+
if (_loadState == LoadAdsState.Ready)
|
|
311
|
+
{
|
|
312
|
+
_loadState = isAdReady ? LoadAdsState.Ready : LoadAdsState.None;
|
|
313
|
+
if (_loadState == LoadAdsState.None) StartLoadAd();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
_showState = isSuccess ? ShowAdsState.ShowSuccess : ShowAdsState.ShowFail;
|
|
317
|
+
|
|
318
|
+
// Extra callback
|
|
319
|
+
Ads.context.showFinishAt = Time.realtimeSinceStartup;
|
|
320
|
+
Ads.context.onAdResult?.Invoke(isSuccess);
|
|
321
|
+
|
|
322
|
+
var localData = Ads.localData;
|
|
323
|
+
var stat = _isInterstitial ? localData.interstitial : localData.reward;
|
|
324
|
+
if (isSuccess)
|
|
325
|
+
{
|
|
326
|
+
stat.success++;
|
|
327
|
+
stat.successTotal++;
|
|
328
|
+
stat.lastSuccessTime = (int)Time.realtimeSinceStartup;
|
|
329
|
+
} else
|
|
330
|
+
{
|
|
331
|
+
stat.failed++;
|
|
332
|
+
stat.failedTotal++;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
localData.Save();
|
|
336
|
+
TriggerOnAfterAdShow();
|
|
337
|
+
|
|
338
|
+
Log($"[Ad] {adType} ShowAdRoutineCompleted: {isSuccess}\n{JsonUtility.ToJson(Ads.context)}");
|
|
339
|
+
Ads.context = null;
|
|
340
|
+
_showState = ShowAdsState.None;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
private void TriggerBeforeAdShow()
|
|
344
|
+
{
|
|
345
|
+
bool willSaveVolume = Config.ad.autoMute
|
|
346
|
+
&& AudioListener.volume > 0
|
|
347
|
+
&& Ads._savedVolume < 0;
|
|
348
|
+
|
|
349
|
+
bool willSaveTimeScale = Config.ad.autoTimeScale
|
|
350
|
+
&& Time.timeScale > 0
|
|
351
|
+
&& Ads._savedTimeScale < 0;
|
|
352
|
+
|
|
353
|
+
if (willSaveVolume)
|
|
354
|
+
{
|
|
355
|
+
Ads._savedVolume = AudioListener.volume;
|
|
356
|
+
AudioListener.volume = 0;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (willSaveTimeScale)
|
|
360
|
+
{
|
|
361
|
+
Ads._savedTimeScale = Time.timeScale;
|
|
362
|
+
Time.timeScale = 0;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
dispatcher.Dispatch(_isInterstitial ? AmaGDK.Event.INTER_SHOW_BEGIN : AmaGDK.Event.REWARD_VIDEO_SHOW_BEGIN);
|
|
366
|
+
Ads.context.onBeforeAdOpen?.Invoke();
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
private void TriggerOnAfterAdShow()
|
|
370
|
+
{
|
|
371
|
+
bool willRestoreVolume = Config.ad.autoMute
|
|
372
|
+
&& AudioListener.volume == 0
|
|
373
|
+
&& Ads._savedVolume > 0;
|
|
374
|
+
|
|
375
|
+
bool willRestoreTimeScale = Config.ad.autoTimeScale
|
|
376
|
+
&& Time.timeScale == 0
|
|
377
|
+
&& Ads._savedTimeScale > 0;
|
|
378
|
+
|
|
379
|
+
if (willRestoreVolume)
|
|
380
|
+
{
|
|
381
|
+
AudioListener.volume = Ads._savedVolume;
|
|
382
|
+
Ads._savedVolume = -1;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (willRestoreTimeScale)
|
|
386
|
+
{
|
|
387
|
+
Time.timeScale = Ads._savedTimeScale;
|
|
388
|
+
Ads._savedTimeScale = -1;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
bool isSuccess = _showState == ShowAdsState.ShowSuccess;
|
|
392
|
+
dispatcher.Dispatch(_isInterstitial ? AmaGDK.Event.INTER_SHOW_END : AmaGDK.Event.REWARD_VIDEO_SHOW_END, isSuccess);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Default implementation
|
|
396
|
+
protected void OnAdClosed()
|
|
397
|
+
{
|
|
398
|
+
Log($"[Ad] {adType} OnAdClosed");
|
|
399
|
+
|
|
400
|
+
if (Ads.context != null)
|
|
401
|
+
{
|
|
402
|
+
Ads.context.adCallback |= AdCallback.Close;
|
|
403
|
+
Ads.context.onClosed?.Invoke();
|
|
404
|
+
} else
|
|
405
|
+
{
|
|
406
|
+
LogWarning("[Ad] OnAdClosed() Something wrong - No AdContext");
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
protected void OnAdClicked()
|
|
411
|
+
{
|
|
412
|
+
Log($"[Ad] {adType} OnAdClicked");
|
|
413
|
+
|
|
414
|
+
if (Ads.context != null)
|
|
415
|
+
{
|
|
416
|
+
Ads.context.adCallback |= AdCallback.Click;
|
|
417
|
+
Ads.context.onClicked?.Invoke();
|
|
418
|
+
} else
|
|
419
|
+
{
|
|
420
|
+
LogWarning("[Ad] OnAdClicked() Something wrong - No AdContext");
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
protected void OnAdShowFailed()
|
|
425
|
+
{
|
|
426
|
+
Log($"[Ad] {adType} OnAdShowFailed");
|
|
427
|
+
|
|
428
|
+
// 509 Show Fail: No ads to show
|
|
429
|
+
// 520 Show Fail: No internet connection; ShouldTrackNetworkState is enabled
|
|
430
|
+
// 524 Show Fail: Placement %@ has reached its limit as defined per pace
|
|
431
|
+
// 526 Show Fail: Ad unit has reached its daily cap per session
|
|
432
|
+
// 1022 Show Fail: Cannot show an RV while another RV is showing
|
|
433
|
+
// 1023 Show Fail: Show RV called when there are no available ads to show
|
|
434
|
+
// 1036 Show Fail: Cannot show an while another is showing
|
|
435
|
+
|
|
436
|
+
if (Ads.context != null)
|
|
437
|
+
{
|
|
438
|
+
Ads.context.adCallback |= AdCallback.Fail;
|
|
439
|
+
Ads.context.onShowFailed?.Invoke();
|
|
440
|
+
} else
|
|
441
|
+
{
|
|
442
|
+
LogWarning("[Ad] OnAdShowFailed() Something wrong - No AdContext");
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
protected void OnAdShowSucceeded()
|
|
447
|
+
{
|
|
448
|
+
Log($"[Ad] {adType} OnAdShowSucceeded");
|
|
449
|
+
|
|
450
|
+
if (Ads.context != null)
|
|
451
|
+
{
|
|
452
|
+
Ads.context.adCallback |= AdCallback.Success;
|
|
453
|
+
Ads.context.onShowSuccess?.Invoke();
|
|
454
|
+
} else
|
|
455
|
+
{
|
|
456
|
+
LogWarning("[Ad] OnAdShowSucceeded() Something wrong - No AdContext");
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
protected void OnAdShowReadyStatus(bool isReady, AdShowReadyStatus status)
|
|
461
|
+
{
|
|
462
|
+
if (Ads.context == null)
|
|
463
|
+
{
|
|
464
|
+
LogWarning("[Ad] OnAdOpen() Something wrong - No AdContext");
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
Ads.context.adCallback |= AdCallback.ShowReadyStatus;
|
|
469
|
+
Ads.context.onAdShowReadyStatus?.Invoke(status);
|
|
470
|
+
if (status == AdShowReadyStatus.Ready)
|
|
471
|
+
{
|
|
472
|
+
dispatcher.Dispatch(
|
|
473
|
+
_isInterstitial ? AmaGDK.Event.INTER_SHOW_READY : AmaGDK.Event.REWARD_VIDEO_SHOW_READY
|
|
474
|
+
);
|
|
475
|
+
} else if (status == AdShowReadyStatus.NoInternet || status == AdShowReadyStatus.TimeOut || status == AdShowReadyStatus.Wifi3GDisabled)
|
|
476
|
+
{
|
|
477
|
+
dispatcher.Dispatch(
|
|
478
|
+
_isInterstitial ? AmaGDK.Event.INTER_SHOW_NOT_READY : AmaGDK.Event.REWARD_VIDEO_SHOW_NOT_READY,
|
|
479
|
+
status
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
protected void OnAdOpen()
|
|
485
|
+
{
|
|
486
|
+
Log($"[Ad] {adType} OnAdOpen");
|
|
487
|
+
|
|
488
|
+
if (Ads.context != null)
|
|
489
|
+
{
|
|
490
|
+
Ads.context.adCallback |= AdCallback.Open;
|
|
491
|
+
Ads.context.onOpened?.Invoke();
|
|
492
|
+
} else
|
|
493
|
+
{
|
|
494
|
+
LogWarning("[Ad] OnAdOpen() Something wrong - No AdContext");
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
protected void OnAdReward()
|
|
499
|
+
{
|
|
500
|
+
Log($"[Ad] {adType} OnAdReward");
|
|
501
|
+
|
|
502
|
+
if (Ads.context != null)
|
|
503
|
+
{
|
|
504
|
+
Ads.context.adCallback |= AdCallback.Reward;
|
|
505
|
+
Ads.context.onRewardReceived?.Invoke();
|
|
506
|
+
} else
|
|
507
|
+
{
|
|
508
|
+
LogWarning("[Ad] OnAdReward() Something wrong - No AdContext");
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
protected void OnAdLoadSuccess()
|
|
513
|
+
{
|
|
514
|
+
Log($"[Ad] {adType} OnAdLoadSuccess");
|
|
515
|
+
|
|
516
|
+
if (!_isRequesting && adType == AdType.Interstitial)
|
|
517
|
+
{
|
|
518
|
+
LogWarning("[Ad] Something wrong? OnAdReady called when no ad is loading! AdType=" + adType);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
_isRequesting = false;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
protected void OnAdLoadFailed(string error)
|
|
525
|
+
{
|
|
526
|
+
Log($"[Ad] {adType} OnAdLoadFailed: {error}");
|
|
527
|
+
_isRequesting = false;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using UnityEngine;
|
|
3
|
+
|
|
4
|
+
namespace Amanotes.Core.Internal
|
|
5
|
+
{
|
|
6
|
+
[Serializable] public class AdModuleConfig
|
|
7
|
+
{
|
|
8
|
+
[Tooltip("Automatically retry requesting ad if an ad failed to response in this amount of time (in secs)")]
|
|
9
|
+
public int adLoadTimeoutInSecs = 30;
|
|
10
|
+
|
|
11
|
+
[Tooltip("When an ad is not ready to show, keep waiting for this amount of time (in secs)\n\nIf the ad is ready during that time, it would be shown normally.")]
|
|
12
|
+
public int adShowTimeoutInSecs = 5;
|
|
13
|
+
|
|
14
|
+
[Tooltip("When an ad is not ready to show, verify that there is an internet connection by ping the internet check URL .\nIf there is no internet connection, we will not need to wait for adShowTimeout secs")]
|
|
15
|
+
public bool checkInternet = true;
|
|
16
|
+
|
|
17
|
+
[NonSerialized] public bool enableInterstitial = true;
|
|
18
|
+
[NonSerialized] public bool enableRewarded = true;
|
|
19
|
+
[NonSerialized] public bool enableBanner = true;
|
|
20
|
+
|
|
21
|
+
[Tooltip("Before showing an ad: set AudioListener.volume to 0\nAfter the ad is closed: restore the previously saved AudioListener.volume")]
|
|
22
|
+
public bool autoMute = true;
|
|
23
|
+
|
|
24
|
+
[Tooltip("Before showing an ad: set Time.timeScale to 0\nAfter the ad is closed: restore the previously saved Time.timeScale")]
|
|
25
|
+
public bool autoTimeScale = true;
|
|
26
|
+
|
|
27
|
+
[Tooltip("Preload banner right when Ad module init (default = false)")]
|
|
28
|
+
public bool preloadBanner = false;
|
|
29
|
+
|
|
30
|
+
[Header("EDITOR")]
|
|
31
|
+
[Tooltip("Only applicable in Editor\n0 = 0% success\n1 = 100% success")]
|
|
32
|
+
[Range(0f, 1f)] public float rewardAdShowSuccessRate = 1;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public partial class ConfigAsset
|
|
36
|
+
{
|
|
37
|
+
[SerializeField] public AdModuleConfig ad;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
namespace Amanotes.Core.Internal
|
|
5
|
+
{
|
|
6
|
+
public class AdShowContext : IAdCallback
|
|
7
|
+
{
|
|
8
|
+
public readonly AdType adType;
|
|
9
|
+
public readonly string placementName;
|
|
10
|
+
public readonly Dictionary<string, object> userData;
|
|
11
|
+
public AdCallback adCallback;
|
|
12
|
+
|
|
13
|
+
internal Action onBeforeAdOpen;
|
|
14
|
+
internal Action onOpened;
|
|
15
|
+
internal Action onRewardReceived;
|
|
16
|
+
internal Action onClicked;
|
|
17
|
+
internal Action onShowSuccess;
|
|
18
|
+
internal Action onShowFailed;
|
|
19
|
+
internal Action onClosed;
|
|
20
|
+
internal Action<AdShowReadyStatus> onAdShowReadyStatus;
|
|
21
|
+
internal Action<bool> onAdResult;
|
|
22
|
+
|
|
23
|
+
// Stats
|
|
24
|
+
public float showCallAt;
|
|
25
|
+
public float showFinishAt;
|
|
26
|
+
|
|
27
|
+
public AdShowContext(AdType adType, string placementName, Dictionary<string, object> userData)
|
|
28
|
+
{
|
|
29
|
+
this.adType = adType;
|
|
30
|
+
this.userData = userData;
|
|
31
|
+
this.placementName = placementName;
|
|
32
|
+
adCallback = AdCallback.None;
|
|
33
|
+
showCallAt = Time.realtimeSinceStartup;
|
|
34
|
+
showFinishAt = 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public bool hasFailedOrCancelled => (adCallback & (AdCallback.Fail | AdCallback.Cancel)) != 0;
|
|
38
|
+
public bool potentiallyCompleted => (adCallback & (AdCallback.Close | AdCallback.Fail | AdCallback.Reward | AdCallback.Cancel)) != 0;
|
|
39
|
+
public bool hasReward => (adCallback & AdCallback.Reward) != 0;
|
|
40
|
+
public bool hasClosed => (adCallback & AdCallback.Close) != 0;
|
|
41
|
+
public bool hasClicked => (adCallback & AdCallback.Click) != 0;
|
|
42
|
+
}
|
|
43
|
+
}
|