Skip to content

Commit a830048

Browse files
authored
Merge pull request #84 from VirtueSky/dev
Dev
2 parents 58d97ba + 3d8be8a commit a830048

82 files changed

Lines changed: 4528 additions & 816 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,16 @@
2323
### 1: Download the repository and drop it into folder `Assets`
2424
### 2: Add the line below to `Packages/manifest.json`
2525

26-
- for version `3.5.4`
26+
- for version `3.5.5`
2727
```json
28-
{
29-
"scopedRegistries": [
30-
{
31-
"name": "npm",
32-
"url": "https://registry.npmjs.org/",
33-
"scopes": [
34-
"com.kyrylokuzyk"
35-
]
36-
}
37-
],
38-
"dependencies": {
39-
"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.5.4"
40-
}
41-
}
42-
28+
"com.virtuesky.sunflower":"https://github.com/VirtueSky/sunflower.git#3.5.5",
4329
```
4430
- depencies:
4531
```json
4632
"com.unity.nuget.newtonsoft-json": "3.2.1",
4733
"com.unity.serialization": "3.1.1",
4834
"com.unity.collections": "2.1.4",
4935
"com.unity.textmeshpro": "3.0.8",
50-
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.5.10",
51-
"com.kyrylokuzyk.primetween": "1.3.8",
5236
```
5337
## Includes modules
5438

VirtueSky/Advertising/Editor/AdSettingEditor.cs

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ namespace VirtueSky.Ads
1111
public class AdSettingEditor : Editor
1212
{
1313
private AdSetting _adSetting;
14-
14+
15+
private SerializedProperty _mediationLoadMode;
16+
private SerializedProperty _currentMediation;
1517
private SerializedProperty _useApplovin;
1618
private SerializedProperty _useAdmob;
1719
private SerializedProperty _useLevelPlay;
@@ -42,17 +44,20 @@ public class AdSettingEditor : Editor
4244
private SerializedProperty _androidAppKey;
4345
private SerializedProperty _iOSAppKey;
4446
private SerializedProperty _useTestAppKey;
47+
private SerializedProperty _enableTestSuiteDefault;
4548
private SerializedProperty _levelPlayBannerVariable;
4649
private SerializedProperty _levelPlayInterVariable;
4750
private SerializedProperty _levelPlayRewardVariable;
4851

4952
const string pathMax = "/Ads/Applovin";
5053
const string pathAdmob = "/Ads/Admob";
5154
const string pathIronSource = "/Ads/LevelPlay";
52-
55+
private bool isSingleMediation = false;
5356
void Initialize()
5457
{
5558
_adSetting = target as AdSetting;
59+
_mediationLoadMode = serializedObject.FindProperty("mediationLoadMode");
60+
_currentMediation = serializedObject.FindProperty("currentMediation");
5661
_useApplovin = serializedObject.FindProperty("useAppLovin");
5762
_useAdmob = serializedObject.FindProperty("useAdmob");
5863
_useLevelPlay = serializedObject.FindProperty("useLevelPlay");
@@ -81,6 +86,7 @@ void Initialize()
8186
_androidAppKey = serializedObject.FindProperty("androidAppKey");
8287
_iOSAppKey = serializedObject.FindProperty("iOSAppKey");
8388
_useTestAppKey = serializedObject.FindProperty("useTestAppKey");
89+
_enableTestSuiteDefault = serializedObject.FindProperty("enableTestSuiteDefault");
8490
_levelPlayBannerVariable = serializedObject.FindProperty("levelPlayBannerVariable");
8591
_levelPlayInterVariable = serializedObject.FindProperty("levelPlayInterVariable");
8692
_levelPlayRewardVariable = serializedObject.FindProperty("levelPlayRewardVariable");
@@ -95,9 +101,22 @@ void Draw()
95101
GUILayout.Space(10);
96102
EditorGUILayout.PropertyField(_adCheckingInterval);
97103
EditorGUILayout.PropertyField(_adLoadingInterval);
98-
EditorGUILayout.PropertyField(_useApplovin);
99-
EditorGUILayout.PropertyField(_useAdmob);
100-
EditorGUILayout.PropertyField(_useLevelPlay);
104+
EditorGUILayout.PropertyField(_mediationLoadMode);
105+
GUILayout.Space(10);
106+
GuiLine();
107+
GUILayout.Space(10);
108+
if ((MediationLoadMode)_mediationLoadMode.enumValueIndex == MediationLoadMode.Single)
109+
{
110+
isSingleMediation = true;
111+
EditorGUILayout.PropertyField(_currentMediation);
112+
}
113+
else
114+
{
115+
isSingleMediation = false;
116+
EditorGUILayout.PropertyField(_useApplovin);
117+
EditorGUILayout.PropertyField(_useAdmob);
118+
EditorGUILayout.PropertyField(_useLevelPlay);
119+
}
101120
EditorGUILayout.PropertyField(_enableTrackAdRevenue);
102121
EditorGUILayout.PropertyField(_enableGDPR);
103122
if (_enableGDPR.boolValue)
@@ -106,9 +125,27 @@ void Draw()
106125
}
107126

108127
GUILayout.Space(10);
109-
if (_useApplovin.boolValue) SetupMax();
110-
if (_useAdmob.boolValue) SetupAdmob();
111-
if (_useLevelPlay.boolValue) SetupIronSource();
128+
if (isSingleMediation)
129+
{
130+
switch ((AdMediation)_currentMediation.enumValueIndex)
131+
{
132+
case AdMediation.AppLovin:
133+
SetupMax();
134+
break;
135+
case AdMediation.Admob:
136+
SetupAdmob();
137+
break;
138+
case AdMediation.LevelPlay:
139+
SetupIronSource();
140+
break;
141+
}
142+
}
143+
else
144+
{
145+
if (_useApplovin.boolValue) SetupMax();
146+
if (_useAdmob.boolValue) SetupAdmob();
147+
if (_useLevelPlay.boolValue) SetupIronSource();
148+
}
112149

113150
EditorUtility.SetDirty(target);
114151
serializedObject.ApplyModifiedProperties();
Lines changed: 57 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
22
using GoogleMobileAds.Api;
33
#endif
4+
using UnityEngine;
45
using VirtueSky.Core;
56
using VirtueSky.Tracking;
67

@@ -15,28 +16,16 @@ public AdmobAdClient(AdSetting _adSetting)
1516

1617
public override void Initialize()
1718
{
19+
SdkInitializationCompleted = false;
1820
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
1921
#if UNITY_IOS
2022
// On Android, Unity is paused when displaying interstitial or rewarded video.
2123
// This setting makes iOS behave consistently with Android.
22-
MobileAds.SetiOSAppPauseOnBackground(true);
24+
MobileAds.SetiOSAppPauseOnBackground(true);
2325
#endif
2426

25-
// When true all events raised by GoogleMobileAds will be raised
26-
// on the Unity main thread. The default value is false.
27-
// https://developers.google.com/admob/unity/quick-start#raise_ad_events_on_the_unity_main_thread
28-
MobileAds.RaiseAdEventsOnUnityMainThread = true;
29-
30-
MobileAds.Initialize(initStatus =>
31-
{
32-
App.RunOnMainThread(() =>
33-
{
34-
if (!adSetting.AdmobEnableTestMode) return;
35-
var configuration = new RequestConfiguration
36-
{ TestDeviceIds = adSetting.AdmobDevicesTest };
37-
MobileAds.SetRequestConfiguration(configuration);
38-
});
39-
});
27+
TestMode();
28+
MobileAds.Initialize(OnInitializeComplete);
4029
FirebaseAnalyticTrackingRevenue.autoTrackAdImpressionAdmob = adSetting.AutoTrackingAdImpressionAdmob;
4130
adSetting.AdmobBannerVariable.Init();
4231
adSetting.AdmobInterVariable.Init();
@@ -46,12 +35,6 @@ public override void Initialize()
4635
adSetting.AdmobNativeOverlayVariable.Init();
4736

4837
RegisterAppStateChange();
49-
LoadInterstitial();
50-
LoadRewarded();
51-
LoadRewardedInterstitial();
52-
LoadAppOpen();
53-
LoadBanner();
54-
LoadNativeOverlay();
5538
#endif
5639
}
5740

@@ -66,9 +49,28 @@ void OnAppStateChanged(GoogleMobileAds.Common.AppState state)
6649
{
6750
if (state == GoogleMobileAds.Common.AppState.Foreground && adSetting.AdmobAppOpenVariable.autoShow)
6851
{
69-
if (adSetting.UseAdmob) ShowAppOpen();
52+
if (adSetting.IsAdmob()) ShowAppOpen();
7053
}
7154
}
55+
56+
private void OnInitializeComplete(InitializationStatus initStatus)
57+
{
58+
SdkInitializationCompleted = true;
59+
LoadInterstitial();
60+
LoadRewarded();
61+
LoadRewardedInterstitial();
62+
LoadAppOpen();
63+
LoadNativeOverlay();
64+
LoadBanner();
65+
}
66+
67+
private void TestMode()
68+
{
69+
if (!adSetting.AdmobEnableTestMode) return;
70+
var configuration = new RequestConfiguration
71+
{ TestDeviceIds = adSetting.AdmobDevicesTest };
72+
MobileAds.SetRequestConfiguration(configuration);
73+
}
7274
#endif
7375
public override void LoadBanner()
7476
{
@@ -78,26 +80,27 @@ public override void LoadBanner()
7880

7981
public override void LoadInterstitial()
8082
{
81-
if (adSetting.AdmobInterVariable == null) return;
82-
if (!adSetting.AdmobInterVariable.IsReady()) adSetting.AdmobInterVariable.Load();
83+
if (adSetting.AdmobInterVariable == null || adSetting.AdmobInterVariable.IsShowing) return;
84+
if (!adSetting.AdmobInterVariable.IsReady() && !adSetting.AdmobInterVariable.IsLoading) adSetting.AdmobInterVariable.Load();
8385
}
8486

8587
public override void LoadRewarded()
8688
{
87-
if (adSetting.AdmobRewardVariable == null) return;
88-
if (!adSetting.AdmobRewardVariable.IsReady()) adSetting.AdmobRewardVariable.Load();
89+
if (adSetting.AdmobRewardVariable == null || adSetting.AdmobRewardVariable.IsShowing) return;
90+
if (!adSetting.AdmobRewardVariable.IsReady() && !adSetting.AdmobRewardVariable.IsLoading) adSetting.AdmobRewardVariable.Load();
8991
}
9092

9193
public override void LoadRewardedInterstitial()
9294
{
93-
if (adSetting.AdmobRewardInterVariable == null) return;
94-
if (!adSetting.AdmobRewardInterVariable.IsReady()) adSetting.AdmobRewardInterVariable.Load();
95+
if (adSetting.AdmobRewardInterVariable == null || adSetting.AdmobRewardInterVariable.IsShowing) return;
96+
if (!adSetting.AdmobRewardInterVariable.IsReady() && !adSetting.AdmobRewardInterVariable.IsLoading)
97+
adSetting.AdmobRewardInterVariable.Load();
9598
}
9699

97100
public override void LoadAppOpen()
98101
{
99102
if (adSetting.AdmobAppOpenVariable == null) return;
100-
if (!adSetting.AdmobAppOpenVariable.IsReady()) adSetting.AdmobAppOpenVariable.Load();
103+
if (!adSetting.AdmobAppOpenVariable.IsReady() && !adSetting.AdmobAppOpenVariable.IsLoading) adSetting.AdmobAppOpenVariable.Load();
101104
}
102105

103106
public override void ShowAppOpen()
@@ -111,5 +114,29 @@ public override void LoadNativeOverlay()
111114
if (adSetting.AdmobNativeOverlayVariable == null) return;
112115
if (!adSetting.AdmobNativeOverlayVariable.IsReady()) adSetting.AdmobNativeOverlayVariable.Load();
113116
}
117+
118+
public override void ShowAdMediationDebugger()
119+
{
120+
#if VIRTUESKY_ADS && VIRTUESKY_ADMOB
121+
if (SdkInitializationCompleted)
122+
{
123+
MobileAds.OpenAdInspector((result) =>
124+
{
125+
if (result != null)
126+
{
127+
Debug.LogError($"Failed to open Ad Inspector: {result.GetCode()} / {result.GetMessage()}");
128+
}
129+
else
130+
{
131+
Debug.Log("Ad Inspector opened successfully.");
132+
}
133+
});
134+
}
135+
else
136+
{
137+
Debug.LogWarning("Failed to open Ad Inspector: SDK not initialized.");
138+
}
139+
#endif
140+
}
114141
}
115142
}

VirtueSky/Advertising/Runtime/Admob/AdmobAdUnitVariable.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class AdmobAdUnitVariable : AdUnitVariable
1010
[NonSerialized] private string idRuntime = string.Empty;
1111

1212
public override bool IsShowing { get; internal set; }
13+
public override bool IsLoading { get; internal set; }
1314

1415
public override string Id
1516
{

0 commit comments

Comments
 (0)