Skip to content

Commit d39b0ce

Browse files
committed
- fix bug
- fix show aoa after close full screen ad - fix condition show for max ad unit
1 parent 4af08f9 commit d39b0ce

File tree

9 files changed

+57
-14
lines changed

9 files changed

+57
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323

2424
### Add the line below to `Packages/manifest.json`
2525

26-
for version `1.1.7`
26+
for version `1.1.8`
2727
```json
28-
"com.wolf-org.advertising":"https://github.com/unity-package/advertising-unity.git#1.1.7",
28+
"com.wolf-org.advertising":"https://github.com/unity-package/advertising-unity.git#1.1.8",
2929
```
30-
dependency `extensions-unity-1.0.5`
30+
dependency `extensions-unity-1.0.6`
3131
```json
32-
"com.wolf-org.extensions":"https://github.com/unity-package/extensions-unity.git#1.0.5",
32+
"com.wolf-org.extensions":"https://github.com/unity-package/extensions-unity.git#1.0.6",
3333
```
3434

3535
Install `app-tracking-unity` and add define symbol `VIRTUESKY_TRACKING` if you need ad revenue tracking

Runtime/Admob/AdmobAppOpenAdUnit.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class AdmobAppOpenAdUnit : AdUnit
1515
[Tooltip("Automatically show AppOpenAd when app status is changed")]
1616
public bool autoShow = false;
1717

18+
[Tooltip("Time between closing the previous full-screen ad and starting to show the app open ad - in seconds")]
19+
public float timeBetweenFullScreenAd = 2f;
20+
1821
public bool useTestId;
1922
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
2023
private AppOpenAd _appOpenAd;
@@ -46,7 +49,8 @@ public override void Load()
4649
public override bool IsReady()
4750
{
4851
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
49-
return _appOpenAd != null && _appOpenAd.CanShowAd() && DateTime.Now < _expireTime;
52+
return _appOpenAd != null && _appOpenAd.CanShowAd() && DateTime.Now < _expireTime &&
53+
(DateTime.Now - AdStatic.AdClosingTime).TotalSeconds > timeBetweenFullScreenAd;
5054
#else
5155
return false;
5256
#endif

Runtime/Admob/AdmobClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
2+
using System;
23
using GoogleMobileAds.Api;
34
#endif
45

@@ -57,8 +58,7 @@ private void RegisterAppStateChange()
5758

5859
void OnAppStateChanged(GoogleMobileAds.Common.AppState state)
5960
{
60-
if (state == GoogleMobileAds.Common.AppState.Foreground && adSettings.AdmobAppOpenAdUnit.autoShow &&
61-
!AdStatic.isShowingAd)
61+
if (state == GoogleMobileAds.Common.AppState.Foreground && adSettings.AdmobAppOpenAdUnit.autoShow)
6262
{
6363
if (adSettings.CurrentAdNetwork == AdNetwork.Admob) ShowAppOpen();
6464
}

Runtime/Admob/AdmobNativeOverlayAdUnit.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void Hide()
117117
/// </summary>
118118
public void RenderAd()
119119
{
120-
#if VIRTUESKY_ADS && VIRTUESKY_ADS
120+
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
121121
if (_nativeOverlayAd == null) return;
122122
_nativeOverlayAd.RenderTemplate(Style(), ConvertSize(), ConvertPosition(adsPosition));
123123
#endif
@@ -129,7 +129,7 @@ public void RenderAd()
129129
/// <param name="uiElement">RectTransform of uiElement, used to determine position for native overlay ads</param>
130130
public void RenderAd(RectTransform uiElement)
131131
{
132-
#if VIRTUESKY_ADS && VIRTUESKY_ADS
132+
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
133133
if (_nativeOverlayAd == null) return;
134134
(int admobX, int admobY) = ConvertUiElementPosToNativeAdsPos(uiElement);
135135
_nativeOverlayAd.RenderTemplate(Style(), admobX, admobY);
@@ -144,7 +144,7 @@ public void RenderAd(RectTransform uiElement)
144144
/// <param name="height">Custom height for native overlay ads</param>
145145
public void RenderAd(RectTransform uiElement, int width, int height)
146146
{
147-
#if VIRTUESKY_ADS && VIRTUESKY_ADS
147+
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
148148
if (_nativeOverlayAd == null) return;
149149
(int admobX, int admobY) = ConvertUiElementPosToNativeAdsPos(uiElement);
150150
_nativeOverlayAd.RenderTemplate(Style(), new AdSize(width, height), admobX, admobY);

Runtime/General/AdStatic.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,27 @@ public static bool IsRemoveAd
4141
#endif
4242
}
4343

44-
public static bool isShowingAd;
44+
public static DateTime AdClosingTime { get; internal set; }
45+
46+
internal static bool isShowingAd;
47+
48+
public static bool IsShowingAd
49+
{
50+
get => isShowingAd;
51+
internal set
52+
{
53+
isShowingAd = value;
54+
if (!value)
55+
{
56+
AdClosingTime = DateTime.Now;
57+
}
58+
}
59+
}
60+
4561
internal static Action waitAppOpenDisplayedAction;
4662
internal static Action waitAppOpenClosedAction;
4763

64+
4865
public static AdUnit OnDisplayed(this AdUnit unit, Action onDisplayed)
4966
{
5067
unit.displayedCallback = onDisplayed;

Runtime/Max/MaxAdClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public override void Initialize()
2323
#if VIRTUESKY_ADS && VIRTUESKY_APPLOVIN
2424
private void OnAppStateChange(bool pauseStatus)
2525
{
26-
if (!pauseStatus && adSettings.MaxAppOpenAdUnit.autoShow && !AdStatic.isShowingAd) ShowAppOpen();
26+
if (!pauseStatus && adSettings.MaxAppOpenAdUnit.autoShow) ShowAppOpen();
2727
}
2828
#endif
2929
}

Runtime/Max/MaxAppOpenAdUnit.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class MaxAppOpenAdUnit : AdUnit
1010
[Tooltip("Automatically show AppOpenAd when app status is changed")]
1111
public bool autoShow = false;
1212

13+
[Tooltip("Time between closing the previous full-screen ad and starting to show the app open ad - in seconds")]
14+
public float timeBetweenFullScreenAd = 2f;
1315

1416
public override void Init()
1517
{
@@ -39,12 +41,22 @@ public override void Load()
3941
public override bool IsReady()
4042
{
4143
#if VIRTUESKY_ADS && VIRTUESKY_APPLOVIN
42-
return !string.IsNullOrEmpty(Id) && MaxSdk.IsAppOpenAdReady(Id);
44+
return !string.IsNullOrEmpty(Id) && MaxSdk.IsAppOpenAdReady(Id) &&
45+
(DateTime.Now - AdStatic.AdClosingTime).TotalSeconds > timeBetweenFullScreenAd;
4346
#else
4447
return false;
4548
#endif
4649
}
4750

51+
public override AdUnit Show()
52+
{
53+
ResetChainCallback();
54+
if (!Application.isMobilePlatform || string.IsNullOrEmpty(Id) || AdStatic.IsRemoveAd || !IsReady())
55+
return this;
56+
ShowImpl();
57+
return this;
58+
}
59+
4860
protected override void ShowImpl()
4961
{
5062
#if VIRTUESKY_ADS && VIRTUESKY_APPLOVIN

Runtime/Max/MaxInterstitialAdUnit.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using UnityEngine;
23
using VirtueSky.Misc;
34

45
namespace VirtueSky.Ads
@@ -44,6 +45,15 @@ public override bool IsReady()
4445
#endif
4546
}
4647

48+
public override AdUnit Show()
49+
{
50+
ResetChainCallback();
51+
if (!Application.isMobilePlatform || string.IsNullOrEmpty(Id) || AdStatic.IsRemoveAd || !IsReady())
52+
return this;
53+
ShowImpl();
54+
return this;
55+
}
56+
4757
protected override void ShowImpl()
4858
{
4959
#if VIRTUESKY_ADS && VIRTUESKY_APPLOVIN

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "com.wolf-org.advertising",
33
"displayName": "UnityCommon-ADS",
44
"description": "Support show ads for game unity",
5-
"version": "1.1.7",
5+
"version": "1.1.8",
66
"unity": "2022.3",
77
"category": "virtuesky",
88
"license": "MIT",

0 commit comments

Comments
 (0)