File tree Expand file tree Collapse file tree 4 files changed +41
-17
lines changed Expand file tree Collapse file tree 4 files changed +41
-17
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ public class AdSettingsEditor : Editor
88 {
99 private AdSettings _adSettings ;
1010 private SerializedProperty _runtimeAutoInit ;
11+ private SerializedProperty _runtimeAutoInitType ;
1112 private SerializedProperty _adCheckingInterval ;
1213 private SerializedProperty _adLoadingInterval ;
1314 private SerializedProperty _adNetwork ;
@@ -41,6 +42,7 @@ void Initialize()
4142 {
4243 _adSettings = target as AdSettings ;
4344 _runtimeAutoInit = serializedObject . FindProperty ( "runtimeAutoInit" ) ;
45+ _runtimeAutoInitType = serializedObject . FindProperty ( "runtimeAutoInitType" ) ;
4446 _adCheckingInterval = serializedObject . FindProperty ( "adCheckingInterval" ) ;
4547 _adLoadingInterval = serializedObject . FindProperty ( "adLoadingInterval" ) ;
4648 _adNetwork = serializedObject . FindProperty ( "adNetwork" ) ;
@@ -76,6 +78,12 @@ public override void OnInspectorGUI()
7678 GuiLine ( 2 ) ;
7779 GUILayout . Space ( 10 ) ;
7880 EditorGUILayout . PropertyField ( _runtimeAutoInit ) ;
81+ if ( _runtimeAutoInit . boolValue )
82+ {
83+ EditorGUILayout . PropertyField ( _runtimeAutoInitType ) ;
84+ }
85+
86+ GUILayout . Space ( 10 ) ;
7987 EditorGUILayout . PropertyField ( _adCheckingInterval ) ;
8088 EditorGUILayout . PropertyField ( _adLoadingInterval ) ;
8189 EditorGUILayout . PropertyField ( _adNetwork ) ;
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
33using UnityEngine ;
4+ using VirtueSky . Core ;
45
56namespace VirtueSky . Ads
67{
@@ -22,6 +23,7 @@ public static AdSettings Instance
2223 }
2324
2425 [ SerializeField ] private bool runtimeAutoInit = true ;
26+ [ SerializeField ] private CoreEnum . RuntimeAutoInitType runtimeAutoInitType ;
2527 [ Range ( 5 , 100 ) , SerializeField ] private float adCheckingInterval = 8f ;
2628 [ Range ( 5 , 100 ) , SerializeField ] private float adLoadingInterval = 15f ;
2729 [ SerializeField ] private AdNetwork adNetwork = AdNetwork . Max ;
@@ -126,6 +128,7 @@ public string AppKey
126128
127129
128130 public bool RuntimeAutoInit => runtimeAutoInit ;
131+ public CoreEnum . RuntimeAutoInitType RuntimeAutoInitType => runtimeAutoInitType ;
129132 public float AdCheckingInterval => adCheckingInterval ;
130133 public float AdLoadingInterval => adLoadingInterval ;
131134
Original file line number Diff line number Diff line change 11using System ;
22using UnityEngine ;
3+ using VirtueSky . Core ;
34
45namespace VirtueSky . Ads
56{
67 public static class AdStatic
78 {
9+ #if VIRTUESKY_ADS
10+ [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . BeforeSceneLoad ) ]
11+ private static void RuntimeBeforeSceneLoad ( )
12+ {
13+ AutoInitialize ( CoreEnum . RuntimeAutoInitType . BeforeSceneLoad ) ;
14+ }
15+
16+ [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . AfterSceneLoad ) ]
17+ private static void RuntimeAfterSceneLoad ( )
18+ {
19+ AutoInitialize ( CoreEnum . RuntimeAutoInitType . AfterSceneLoad ) ;
20+ }
21+
22+ private static void AutoInitialize ( CoreEnum . RuntimeAutoInitType adsRuntimeAutoInitType )
23+ {
24+ if ( AdSettings . Instance == null ) return ;
25+ if ( ! AdSettings . Instance . RuntimeAutoInit ) return ;
26+ if ( AdSettings . Instance . RuntimeAutoInitType != adsRuntimeAutoInitType ) return ;
27+ var ads = new GameObject ( "Advertising" ) ;
28+ ads . AddComponent < Advertising > ( ) ;
29+ UnityEngine . Object . DontDestroyOnLoad ( ads ) ;
30+ }
31+
32+ #endif
833 public static bool IsRemoveAd
934 {
1035#if VIRTUESKY_DATA
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ private void Start()
4949 if ( adSettings . EnableGDPR )
5050 {
5151#if VIRTUESKY_ADMOB
52- InitGDPR ( ) ;
52+ InitGdpr ( ) ;
5353#endif
5454 }
5555 else
@@ -143,9 +143,11 @@ void AutoLoadAppOpenAds()
143143 #region Admob GDPR
144144
145145#if VIRTUESKY_ADMOB
146- private void InitGDPR ( )
146+ private void InitGdpr ( )
147147 {
148- #if ! UNITY_EDITOR
148+ #if UNITY_EDITOR
149+ InitAdClient ( ) ;
150+ #else
149151 string deviceID = SystemInfo . deviceUniqueIdentifier ;
150152 string deviceIDUpperCase = deviceID . ToUpper ( ) ;
151153
@@ -236,20 +238,6 @@ private void ShowPrivacyOptionsForm()
236238
237239 #endregion
238240
239- #if VIRTUESKY_ADS
240- [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . AfterSceneLoad ) ]
241- private static void AutoInitialize ( )
242- {
243- if ( AdSettings . Instance == null ) return ;
244- if ( AdSettings . Instance . RuntimeAutoInit )
245- {
246- var ads = new GameObject ( "Advertising" ) ;
247- ads . AddComponent < Advertising > ( ) ;
248- DontDestroyOnLoad ( ads ) ;
249- }
250- }
251- #endif
252-
253241
254242 #region Public API
255243
You can’t perform that action at this time.
0 commit comments