com.amanotes.gdk 0.2.70-1 → 0.2.70-2
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/Runtime/Ad/AdLogic.cs +50 -46
- package/Runtime/Ad/AdShowContext.cs +1 -1
- package/Runtime/AmaGDK.cs +1 -1
- package/package.json +1 -1
package/Runtime/Ad/AdLogic.cs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
using System;
|
|
1
2
|
using System.Collections;
|
|
2
3
|
using UnityEngine;
|
|
3
4
|
using static Amanotes.Core.Internal.Logging;
|
|
@@ -131,14 +132,9 @@ namespace Amanotes.Core.Internal
|
|
|
131
132
|
private Coroutine _showAdRoutine;
|
|
132
133
|
protected bool _isRequesting;
|
|
133
134
|
protected bool _isInterstitial => adType == AdType.Interstitial;
|
|
134
|
-
private bool isFocus;
|
|
135
135
|
|
|
136
136
|
public void StartShowAd()
|
|
137
137
|
{
|
|
138
|
-
isFocus = false;
|
|
139
|
-
unityCallbacks.OnApplicationFocus -= OnApplicationFocus;
|
|
140
|
-
unityCallbacks.OnApplicationFocus += OnApplicationFocus;
|
|
141
|
-
|
|
142
138
|
if (_showState != ShowAdsState.None)
|
|
143
139
|
{
|
|
144
140
|
LogWarning("[Ad] StartShowAd() --> Invalid _showState: " + _showState);
|
|
@@ -160,14 +156,6 @@ namespace Amanotes.Core.Internal
|
|
|
160
156
|
_showAdRoutine = _instance.StartCoroutine(ShowAdRoutine());
|
|
161
157
|
}
|
|
162
158
|
|
|
163
|
-
private void OnApplicationFocus(bool focus)
|
|
164
|
-
{
|
|
165
|
-
if (!focus) return;
|
|
166
|
-
|
|
167
|
-
unityCallbacks.OnApplicationFocus -= OnApplicationFocus;
|
|
168
|
-
isFocus = true;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
159
|
public void StopShowAd()
|
|
172
160
|
{
|
|
173
161
|
Log($"[Ad] {adType} StopShowAd");
|
|
@@ -235,14 +223,61 @@ namespace Amanotes.Core.Internal
|
|
|
235
223
|
_showState = ShowAdsState.Showing;
|
|
236
224
|
OnAdShowReadyStatus(true, AdShowReadyStatus.Ready);
|
|
237
225
|
TriggerBeforeAdShow();
|
|
226
|
+
#if !UNITY_EDITOR && UNITY_ANDROID
|
|
227
|
+
GDKUtils.StartCoroutine(HandleAdActivityKilledSilently());
|
|
228
|
+
#endif
|
|
238
229
|
ShowAd();
|
|
239
230
|
|
|
240
231
|
yield return WaitForMediationCallback();
|
|
241
232
|
|
|
242
|
-
// wait 1 frame in case hasReward callback after onClose
|
|
243
|
-
if (!context.hasReward && adType == AdType.VideoReward && !context.hasFailedOrCancelled) yield return null;
|
|
244
233
|
ShowAdRoutineCompleted(context.isSuccess);
|
|
245
234
|
}
|
|
235
|
+
|
|
236
|
+
private IEnumerator WaitForMediationCallback()
|
|
237
|
+
{
|
|
238
|
+
while (context != null && !context.potentiallyCompleted)
|
|
239
|
+
{
|
|
240
|
+
yield return null;
|
|
241
|
+
}
|
|
242
|
+
// wait 1 frame in case hasReward callback after onClose
|
|
243
|
+
if (context != null && !context.hasReward && adType == AdType.VideoReward && !context.hasFailedOrCancelled) yield return null;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private IEnumerator HandleAdActivityKilledSilently()
|
|
247
|
+
{
|
|
248
|
+
bool hasOutOfFocus = false;
|
|
249
|
+
bool hasFocusAgain = false;
|
|
250
|
+
Action<bool> onApplicationFocusCallback = focus =>
|
|
251
|
+
{
|
|
252
|
+
if (focus)
|
|
253
|
+
{
|
|
254
|
+
hasFocusAgain = true;
|
|
255
|
+
}
|
|
256
|
+
else
|
|
257
|
+
{
|
|
258
|
+
hasOutOfFocus = true;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
unityCallbacks.OnApplicationFocus += onApplicationFocusCallback;
|
|
262
|
+
int counter = 0;
|
|
263
|
+
while (context != null && !context.potentiallyCompleted)
|
|
264
|
+
{
|
|
265
|
+
if (hasFocusAgain && hasOutOfFocus)
|
|
266
|
+
{
|
|
267
|
+
// Start counting frames only after closed the ad
|
|
268
|
+
counter++;
|
|
269
|
+
}
|
|
270
|
+
if (counter > MAX_FRAMES_WAIT_FOR_CALLBACK)
|
|
271
|
+
{
|
|
272
|
+
// Timeout reached, force close the ad
|
|
273
|
+
LogError("Force close the ad");
|
|
274
|
+
StopShowAd();
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
yield return null;
|
|
278
|
+
}
|
|
279
|
+
unityCallbacks.OnApplicationFocus -= onApplicationFocusCallback;
|
|
280
|
+
}
|
|
246
281
|
|
|
247
282
|
private void EndShowAdRoutineWithFailure(AdShowReadyStatus status)
|
|
248
283
|
{
|
|
@@ -279,37 +314,6 @@ namespace Amanotes.Core.Internal
|
|
|
279
314
|
}
|
|
280
315
|
}
|
|
281
316
|
|
|
282
|
-
private IEnumerator WaitForMediationCallback()
|
|
283
|
-
{
|
|
284
|
-
#if !UNITY_EDITOR
|
|
285
|
-
while (!isFocus) yield return null;
|
|
286
|
-
#endif
|
|
287
|
-
|
|
288
|
-
int wait4CallbackCounter = 0;
|
|
289
|
-
while (!context.potentiallyCompleted && wait4CallbackCounter <= MAX_FRAMES_WAIT_FOR_CALLBACK)
|
|
290
|
-
{
|
|
291
|
-
wait4CallbackCounter++;
|
|
292
|
-
yield return null;
|
|
293
|
-
}
|
|
294
|
-
Log($"[Ad] Waiting for potentially completed callback: {wait4CallbackCounter} frames");
|
|
295
|
-
|
|
296
|
-
if (!context.hasClosed) yield return WaitForAdClosedCallback();
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
private IEnumerator WaitForAdClosedCallback()
|
|
300
|
-
{
|
|
301
|
-
int counter = 0;
|
|
302
|
-
while (!context.hasClosed && counter <= MAX_FRAMES_WAIT_FOR_CALLBACK)
|
|
303
|
-
{
|
|
304
|
-
counter++;
|
|
305
|
-
yield return null;
|
|
306
|
-
}
|
|
307
|
-
Log($"[Ad] Waiting for ad closed callback: {counter} frames");
|
|
308
|
-
if (context.hasClosed) yield break;
|
|
309
|
-
LogWarning("[Ad] Force close ad (mediation missing OnAdClose callback)");
|
|
310
|
-
OnAdClosed();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
317
|
private void ShowAdRoutineCompleted(bool isSuccess)
|
|
314
318
|
{
|
|
315
319
|
if (_loadState == LoadAdsState.Ready)
|
|
@@ -35,7 +35,7 @@ namespace Amanotes.Core.Internal
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public bool hasFailedOrCancelled => (adCallback & (AdCallback.Fail | AdCallback.Cancel)) != 0;
|
|
38
|
-
public bool potentiallyCompleted => (adCallback & (AdCallback.Close | AdCallback.Fail | AdCallback.
|
|
38
|
+
public bool potentiallyCompleted => (adCallback & (AdCallback.Close | AdCallback.Fail | AdCallback.Cancel)) != 0;
|
|
39
39
|
public bool hasReward => (adCallback & AdCallback.Reward) != 0;
|
|
40
40
|
public bool hasClosed => (adCallback & AdCallback.Close) != 0;
|
|
41
41
|
public bool hasClicked => (adCallback & AdCallback.Click) != 0;
|
package/Runtime/AmaGDK.cs
CHANGED
|
@@ -17,7 +17,7 @@ namespace Amanotes.Core
|
|
|
17
17
|
{
|
|
18
18
|
public partial class AmaGDK : MonoBehaviour
|
|
19
19
|
{
|
|
20
|
-
public const string VERSION = "0.2.70-
|
|
20
|
+
public const string VERSION = "0.2.70-2";
|
|
21
21
|
|
|
22
22
|
internal static Status _status = Status.None;
|
|
23
23
|
private static ConfigAsset _config = null;
|