Skip to content

Commit 3d11bc8

Browse files
committed
Merge branch 'master' into shortcuts
2 parents 87dcb2a + 3efdf0d commit 3d11bc8

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

scripts/DllManipulator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ public class DllManipulatorOptions
652652
public bool crashLogsStackTrace;
653653
public bool mockAllNativeFunctions;
654654
public bool onlyInEditor;
655+
public bool enableInEditMode;
655656
}
656657

657658
public enum DllLoadingMode

scripts/DllManipulatorScript.cs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
using System;
1+
using System;
22
using System.Reflection;
33
using System.Threading;
44
using System.Linq;
55
using UnityEngine;
66
using UnityNativeTool.Internal;
7+
#if UNITY_EDITOR
8+
using UnityEditor;
9+
#endif
710

811
namespace 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
}

scripts/Editor/DllManipulatorEditor.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public class DllManipulatorEditor : Editor
2121
"If true, native functions will be mocked only in assembly that contains DllManipulator (usually Assembly-CSharp)");
2222
private static readonly GUIContent ONLY_IN_EDITOR = new GUIContent("Only in editor",
2323
"Whether to run only inside editor (which is recommended).");
24+
private static readonly GUIContent ENABLE_IN_EDIT_MODE = new GUIContent("Enable in Edit Mode",
25+
"Should the DLLs also be mocked in edit mode (i.e. even if you don't hit 'play' in editor). " +
26+
"Turning this off when not needed improves performance when entering edit mode. " +
27+
"Changes are currently only visible on the next time edit mode is entered (i.e. when OnEnable is called so hit 'play' then 'stop' to apply).");
2428
private static readonly GUIContent TARGET_ASSEMBLIES_GUI_CONTENT = new GUIContent("Target assemblies",
2529
"Choose from which assemblies to mock native functions");
2630
private static readonly GUIContent DLL_PATH_PATTERN_GUI_CONTENT = new GUIContent("DLL path pattern",
@@ -254,6 +258,8 @@ private void DrawOptions(DllManipulatorOptions options)
254258
}
255259

256260
options.onlyInEditor = EditorGUILayout.Toggle(ONLY_IN_EDITOR, options.onlyInEditor);
261+
262+
options.enableInEditMode = EditorGUILayout.Toggle(ENABLE_IN_EDIT_MODE, options.enableInEditMode);
257263

258264
options.dllPathPattern = EditorGUILayout.TextField(DLL_PATH_PATTERN_GUI_CONTENT, options.dllPathPattern);
259265

@@ -349,4 +355,4 @@ public static void RepaintAll()
349355
RepaintAllEditors.Invoke();
350356
}
351357
}
352-
}
358+
}

0 commit comments

Comments
 (0)