Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/DllManipulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ public class DllManipulatorOptions
public bool crashLogsStackTrace;
public bool mockAllNativeFunctions;
public bool onlyInEditor;
public bool enableInEditMode;
}

public enum DllLoadingMode
Expand Down
41 changes: 35 additions & 6 deletions scripts/DllManipulatorScript.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using System;
using System;
using System.Reflection;
using System.Threading;
using System.Linq;
using UnityEngine;
using UnityNativeTool.Internal;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace UnityNativeTool
{
#if UNITY_EDITOR
[ExecuteInEditMode]
#endif
public class DllManipulatorScript : MonoBehaviour
{
private static DllManipulatorScript _singletonInstance = null;
Expand All @@ -30,23 +36,45 @@ public class DllManipulatorScript : MonoBehaviour
crashLogsStackTrace = false,
mockAllNativeFunctions = true,
onlyInEditor = true,
enableInEditMode = false
};

private void OnEnable()
{
#if !UNITY_EDITOR
if (Options.onlyInEditor)
#if UNITY_EDITOR
if (_singletonInstance != null)
{
if (EditorApplication.isPlaying)
Destroy(gameObject);
else
enabled = false; //Don't destroy as the user may be editing a Prefab
return;
}
_singletonInstance = this;

if(EditorApplication.isPlaying)
DontDestroyOnLoad(gameObject);

if(EditorApplication.isPlaying || Options.enableInEditMode)
Initialize();
#else
if (Options.onlyInEditor)
return;
#endif

if (_singletonInstance != null)
{
Destroy(gameObject);
return;
}
_singletonInstance = this;
DontDestroyOnLoad(gameObject);

DontDestroyOnLoad(gameObject);
Initialize();
#endif
}

private void Initialize()
{
var initTimer = System.Diagnostics.Stopwatch.StartNew();

DllManipulator.Options = Options;
Expand All @@ -66,7 +94,8 @@ private void OnDestroy()

DllManipulator.UnloadAll();
DllManipulator.ForgetAllDlls();
DllManipulator.ClearCrashLogs();
DllManipulator.ClearCrashLogs();
_singletonInstance = null;
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion scripts/Editor/DllManipulatorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public class DllManipulatorEditor : Editor
"If true, native functions will be mocked only in assembly that contains DllManipulator (usually Assembly-CSharp)");
private static readonly GUIContent ONLY_IN_EDITOR = new GUIContent("Only in editor",
"Whether to run only inside editor (which is recommended).");
private static readonly GUIContent ENABLE_IN_EDIT_MODE = new GUIContent("Enable in Edit Mode",
"Should the DLLs also be mocked in edit mode (i.e. even if you don't hit 'play' in editor). " +
"Turning this off when not needed improves performance when entering edit mode. " +
"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).");
private static readonly GUIContent TARGET_ASSEMBLIES_GUI_CONTENT = new GUIContent("Target assemblies",
"Choose from which assemblies to mock native functions");
private static readonly GUIContent DLL_PATH_PATTERN_GUI_CONTENT = new GUIContent("DLL path pattern",
Expand Down Expand Up @@ -246,6 +250,8 @@ private void DrawOptions(DllManipulatorOptions options)
}

options.onlyInEditor = EditorGUILayout.Toggle(ONLY_IN_EDITOR, options.onlyInEditor);

options.enableInEditMode = EditorGUILayout.Toggle(ENABLE_IN_EDIT_MODE, options.enableInEditMode);

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

Expand Down Expand Up @@ -334,4 +340,4 @@ public static void UnloadAll()
DllManipulator.UnloadAll();
}
}
}
}