1- using System ;
1+ using System ;
22using System . Reflection ;
33using System . Threading ;
44using System . Linq ;
55using UnityEngine ;
66using UnityNativeTool . Internal ;
7+ #if UNITY_EDITOR
8+ using UnityEditor ;
9+ #endif
710
811namespace UnityNativeTool
912{
13+ #if UNITY_EDITOR
14+ [ ExecuteInEditMode ]
15+ #endif
1016 public class DllManipulatorScript : MonoBehaviour
1117 {
1218 private static DllManipulatorScript _singletonInstance = null ;
@@ -30,23 +36,45 @@ public class DllManipulatorScript : MonoBehaviour
3036 crashLogsStackTrace = false ,
3137 mockAllNativeFunctions = true ,
3238 onlyInEditor = true ,
39+ enableInEditMode = false
3340 } ;
3441
3542 private void OnEnable ( )
3643 {
37- #if ! UNITY_EDITOR
38- if ( Options . onlyInEditor )
44+ #if UNITY_EDITOR
45+ if ( _singletonInstance != null )
46+ {
47+ if ( EditorApplication . isPlaying )
48+ Destroy ( gameObject ) ;
49+ else
50+ enabled = false ; //Don't destroy as the user may be editing a Prefab
51+ return ;
52+ }
53+ _singletonInstance = this ;
54+
55+ if ( EditorApplication . isPlaying )
56+ DontDestroyOnLoad ( gameObject ) ;
57+
58+ if ( EditorApplication . isPlaying || Options . enableInEditMode )
59+ Initialize ( ) ;
60+ #else
61+ if ( Options . onlyInEditor )
3962 return ;
40- #endif
4163
4264 if ( _singletonInstance != null )
4365 {
4466 Destroy ( gameObject ) ;
4567 return ;
4668 }
4769 _singletonInstance = this ;
48- DontDestroyOnLoad ( gameObject ) ;
4970
71+ DontDestroyOnLoad ( gameObject ) ;
72+ Initialize ( ) ;
73+ #endif
74+ }
75+
76+ private void Initialize ( )
77+ {
5078 var initTimer = System . Diagnostics . Stopwatch . StartNew ( ) ;
5179
5280 DllManipulator . Options = Options ;
@@ -66,7 +94,8 @@ private void OnDestroy()
6694
6795 DllManipulator . UnloadAll ( ) ;
6896 DllManipulator . ForgetAllDlls ( ) ;
69- DllManipulator . ClearCrashLogs ( ) ;
97+ DllManipulator . ClearCrashLogs ( ) ;
98+ _singletonInstance = null ;
7099 }
71100 }
72101 }
0 commit comments