diff --git a/.gitignore b/.gitignore index 9f9f5d0..88034ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -*.meta scripts/LICENSE.txt *.sln .vs diff --git a/LICENSE.txt.meta b/LICENSE.txt.meta new file mode 100644 index 0000000..1de551b --- /dev/null +++ b/LICENSE.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7f4a13bbeab717a4abf582c2cdd455d9 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index 218d111..02d8afb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,11 @@ Tool created mainly to solve old problem with reloading [native plugins](https:/ ## Installation -1. Download and add unity package from [releases](https://github.com/MCpiroman/UnityNativeTool/releases), or clone this repo to your project (note that if you don't use the prebuilt package and you're willing to use [low level interface callbacks](https://docs.unity3d.com/Manual/NativePluginInterface.html), you'll need to compile the stub plugin yourself form `stubLluiPlugin.c`). +1. Download and add unity package from [releases](https://github.com/MCpiroman/UnityNativeTool/releases), or clone this repo to your project + + - Clone it into the `/Packages` folder to use it as a local [embedded package](https://docs.unity3d.com/Manual/upm-embed.html) with [upm](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@1.8/manual/index.html). + + - Note that if you don't use the prebuilt package and you're willing to use [low level interface callbacks](https://docs.unity3d.com/Manual/NativePluginInterface.html), you'll need to compile the stub plugin yourself from `stubLluiPlugin.c`. 2. In project settings, set _Api Compatibility Level_ to .NET 4.x or above. Edit > Project Settings > Player > Other Settings > Api Compatibility Level diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..60e0a78 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 8d1b3b29c21705c44a9b6b3700c72715 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..04f7904 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "com.mcpiroman.unity-native-tool", + "displayName": "Unity Native Tool", + "version": "7.1.0", + "description": "Tool for unloading native DLLs in the editor. \nhttps://github.com/mcpiroman/UnityNativeTool", + "keywords": [ + "native", + "c++", + "dll" + ], + "category": "Unity", + "repository": { + "type": "git", + "url": "https://github.com/mcpiroman/UnityNativeTool.git" + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..7f7524a --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 246fd71d40afbc74687dbcf5c273b8a9 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts.meta b/scripts.meta new file mode 100644 index 0000000..a42321b --- /dev/null +++ b/scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0de865a5ea16c5142993a91313dbea05 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/Attributes.cs.meta b/scripts/Attributes.cs.meta new file mode 100644 index 0000000..dee532f --- /dev/null +++ b/scripts/Attributes.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9bbc6aaa5a6ecef45a82fc6043d21c4b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/Detour.cs.meta b/scripts/Detour.cs.meta new file mode 100644 index 0000000..b107391 --- /dev/null +++ b/scripts/Detour.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 97f036a7a52b17248b49530ecf5a9c79 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/DllLoadException.cs.meta b/scripts/DllLoadException.cs.meta new file mode 100644 index 0000000..5925bde --- /dev/null +++ b/scripts/DllLoadException.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2fdbe6a397ce4d499cfe2d89a93cf38 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/DllManipulator.ReflectionData.cs.meta b/scripts/DllManipulator.ReflectionData.cs.meta new file mode 100644 index 0000000..c2cbed2 --- /dev/null +++ b/scripts/DllManipulator.ReflectionData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 107ce30347a400f45ae4b92c36560c28 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 147d474..e61840d 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -17,6 +17,18 @@ public partial class DllManipulator public const string DLL_PATH_PATTERN_ASSETS_MACRO = "{assets}"; public const string DLL_PATH_PATTERN_PROJECT_MACRO = "{proj}"; private const string CRASH_FILE_NAME_PREFIX = "unityNativeCrash_"; + public static readonly string[] DEFAULT_ASSEMBLY_NAMES = {"Assembly-CSharp" + #if UNITY_EDITOR + , "Assembly-CSharp-Editor" + #endif + }; + public static readonly string[] INTERNAL_ASSEMBLY_NAMES = {"mcpiroman.UnityNativeTool" + #if UNITY_EDITOR + , "mcpiroman.UnityNativeTool.Editor" + #endif + }; + public static readonly string[] IGNORED_ASSEMBLY_PREFIXES = { "UnityEngine.", "UnityEditor.", "Unity.", "com.unity.", "Mono." , "nunit."}; + public static DllManipulatorOptions Options { get; set; } private static int _unityMainThreadId; @@ -48,20 +60,18 @@ internal static void Initialize(int unityMainThreadId, string assetsPath) LowLevelPluginManager.ResetStubPlugin(); - Assembly[] assemblies; - if (Options.assemblyPaths.Length == 0) - { - assemblies = new[] { Assembly.GetExecutingAssembly() }; - } - else + IEnumerable assemblyPathsTemp = Options.assemblyNames; + if (!assemblyPathsTemp.Any()) + assemblyPathsTemp = DEFAULT_ASSEMBLY_NAMES; + + assemblyPathsTemp = assemblyPathsTemp.Concat(INTERNAL_ASSEMBLY_NAMES); + + var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); + var assemblies = allAssemblies.Where(a => !a.IsDynamic && assemblyPathsTemp.Any(p => p == Path.GetFileNameWithoutExtension(a.Location))).ToArray(); + var missingAssemblies = assemblyPathsTemp.Except(assemblies.Select(a => Path.GetFileNameWithoutExtension(a.Location))); + foreach (var assembly in missingAssemblies.Except(DEFAULT_ASSEMBLY_NAMES)) { - var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); - assemblies = allAssemblies.Where(a => !a.IsDynamic && Options.assemblyPaths.Any(p => p == PathUtils.NormallizeSystemAssemblyPath(a.Location))).ToArray(); - var missingAssemblies = Options.assemblyPaths.Except(assemblies.Select(a => PathUtils.NormallizeSystemAssemblyPath(a.Location))); - foreach (var assemblyPath in missingAssemblies) - { - Debug.LogError($"Could not find assembly at path {assemblyPath}"); - } + Debug.LogError($"Could not find assembly: {assembly}"); } foreach (var assembly in assemblies) @@ -644,34 +654,34 @@ private static void WriteNativeCrashLog(NativeFunction nativeFunction, object[] private static IntPtr SysLoadDll(string filepath) { -#if UNITY_STANDALONE_WIN - return PInvokes_Windows.LoadLibrary(filepath); -#elif UNITY_STANDALONE_LINUX +#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX return PInvokes_Linux.dlopen(filepath, (int)Options.posixDlopenFlags); -#elif UNITY_STANDALONE_OSX +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX return PInvokes_Osx.dlopen(filepath, (int)Options.posixDlopenFlags); +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + return PInvokes_Windows.LoadLibrary(filepath); #endif } private static bool SysUnloadDll(IntPtr libHandle) { -#if UNITY_STANDALONE_WIN - return PInvokes_Windows.FreeLibrary(libHandle); -#elif UNITY_STANDALONE_LINUX +#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX return PInvokes_Linux.dlclose(libHandle) == 0; -#elif UNITY_STANDALONE_OSX +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX return PInvokes_Osx.dlclose(libHandle) == 0; +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + return PInvokes_Windows.FreeLibrary(libHandle); #endif } private static IntPtr SysGetDllProcAddress(IntPtr libHandle, string symbol) { -#if UNITY_STANDALONE_WIN - return PInvokes_Windows.GetProcAddress(libHandle, symbol); -#elif UNITY_STANDALONE_LINUX +#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX return PInvokes_Linux.dlsym(libHandle, symbol); -#elif UNITY_STANDALONE_OSX +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX return PInvokes_Osx.dlsym(libHandle, symbol); +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + return PInvokes_Windows.GetProcAddress(libHandle, symbol); #endif } } @@ -680,7 +690,7 @@ private static IntPtr SysGetDllProcAddress(IntPtr libHandle, string symbol) public class DllManipulatorOptions { public string dllPathPattern; - public string[] assemblyPaths; //empty means only executing assembly + public List assemblyNames; // empty means only default assemblies public DllLoadingMode loadingMode; public PosixDlopenFlags posixDlopenFlags; public bool threadSafe; @@ -694,7 +704,7 @@ public class DllManipulatorOptions public DllManipulatorOptions CloneTo(DllManipulatorOptions other) { other.dllPathPattern = dllPathPattern; - other.assemblyPaths = (string[]) assemblyPaths.Clone(); + other.assemblyNames = assemblyNames.Select(item => (string)item.Clone()).ToList(); other.loadingMode = loadingMode; other.posixDlopenFlags = posixDlopenFlags; other.threadSafe = threadSafe; @@ -710,7 +720,7 @@ public DllManipulatorOptions CloneTo(DllManipulatorOptions other) public bool Equals(DllManipulatorOptions other) { - return other.dllPathPattern == dllPathPattern && other.assemblyPaths.SequenceEqual(assemblyPaths) && + return other.dllPathPattern == dllPathPattern && other.assemblyNames.SequenceEqual(assemblyNames) && other.loadingMode == loadingMode && other.posixDlopenFlags == posixDlopenFlags && other.threadSafe == threadSafe && other.enableCrashLogs == enableCrashLogs && other.crashLogsDir == crashLogsDir && other.crashLogsStackTrace == crashLogsStackTrace && diff --git a/scripts/DllManipulator.cs.meta b/scripts/DllManipulator.cs.meta new file mode 100644 index 0000000..135d255 --- /dev/null +++ b/scripts/DllManipulator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3e2b3e99b7e1c8a478240fd9c2c03e60 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/DllManipulatorScript.cs b/scripts/DllManipulatorScript.cs index 1245398..2acbafd 100644 --- a/scripts/DllManipulatorScript.cs +++ b/scripts/DllManipulatorScript.cs @@ -20,14 +20,14 @@ public class DllManipulatorScript : MonoBehaviour public DllManipulatorOptions Options = new DllManipulatorOptions() { dllPathPattern = -#if UNITY_STANDALONE_WIN - "{assets}/Plugins/__{name}.dll", -#elif UNITY_STANDALONE_LINUX +#if UNITY_STANDALONE_LINUX || UNITY_EDITOR_LINUX "{assets}/Plugins/__{name}.so", -#elif UNITY_STANDALONE_OSX +#elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX "{assets}/Plugins/__{name}.dylib", +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + "{assets}/Plugins/__{name}.dll", #endif - assemblyPaths = new string[0], + assemblyNames = new List(), loadingMode = DllLoadingMode.Lazy, posixDlopenFlags = PosixDlopenFlags.Lazy, threadSafe = false, diff --git a/scripts/DllManipulatorScript.cs.meta b/scripts/DllManipulatorScript.cs.meta new file mode 100644 index 0000000..c961c59 --- /dev/null +++ b/scripts/DllManipulatorScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de05c130c77e69a408c0f25cd6b50d1d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/Editor.meta b/scripts/Editor.meta new file mode 100644 index 0000000..baef018 --- /dev/null +++ b/scripts/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fbc6fd093eba8524a9eccf9b4b1385a3 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index fc3d380..6fd2378 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEditor; @@ -14,19 +14,21 @@ namespace UnityNativeTool.Internal [CustomEditor(typeof(DllManipulatorScript))] public class DllManipulatorEditor : Editor { + private static readonly string INFO_BOX_GUI_CONTENT = + "Mocks native functions to allow manually un/loading native DLLs. DLLs are always unloaded at OnDestroy."; private static readonly GUIContent TARGET_ALL_NATIVE_FUNCTIONS_GUI_CONTENT = new GUIContent("All native functions", "If true, all found native functions will be mocked.\n\n" + $"If false, you have to select them by using [{nameof(MockNativeDeclarationsAttribute)}] or [{nameof(MockNativeDeclarationAttribute)}]."); - private static readonly GUIContent TARGET_ONLY_EXECUTING_ASSEMBLY_GUI_CONTENT = new GUIContent("Only executing assembly", - "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", + private static readonly GUIContent ONLY_ASSEMBLY_CSHARP_GUI_CONTENT = new GUIContent("Only Assembly-CSharp(-Editor)", + "If true, native functions will be mocked only in Assembly-CSharp and Assembly-CSharp-Editor. Alternatively enter a list of assembly names."); + 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"); + "List of assembly names to mock native functions in (no file extension)."); private static readonly GUIContent DLL_PATH_PATTERN_GUI_CONTENT = new GUIContent("DLL path pattern", "Available macros:\n\n" + $"{DllManipulator.DLL_PATH_PATTERN_DLL_NAME_MACRO} - name of DLL as specified in [DllImport] attribute.\n\n" + @@ -57,11 +59,11 @@ public class DllManipulatorEditor : Editor "Use only if you are sure no other thread will be call mocked natives."); private static readonly GUIContent UNLOAD_ALL_DLLS_AND_PAUSE_WITH_THREAD_SAFETY_GUI_CONTENT = new GUIContent("Unload all DLLs & Pause [dangerous]", "Use only if you are sure no other thread will be call mocked natives."); - private static readonly TimeSpan ASSEMBLIES_REFRESH_INTERVAL = TimeSpan.FromSeconds(1); + private static readonly TimeSpan ASSEMBLIES_REFRESH_INTERVAL = TimeSpan.FromSeconds(5); private bool _showLoadedLibraries = true; private bool _showTargetAssemblies = true; - private string[] _allKnownAssemblies = null; + private string[] _possibleTargetAssemblies = null; private DateTime _lastKnownAssembliesRefreshTime; /// @@ -88,6 +90,8 @@ public override void OnInspectorGUI() { var t = (DllManipulatorScript)this.target; + EditorGUILayout.HelpBox(INFO_BOX_GUI_CONTENT, MessageType.Info); + DrawOptions(t.Options); EditorGUILayout.Space(); @@ -205,49 +209,32 @@ private void DrawUsedDlls(IList usedDlls) private void DrawOptions(DllManipulatorOptions options) { var guiEnabledStack = new Stack(); - guiEnabledStack.Push(GUI.enabled); if (EditorApplication.isPlaying) GUI.enabled = false; + + options.onlyInEditor = EditorGUILayout.Toggle(ONLY_IN_EDITOR, options.onlyInEditor); + options.enableInEditMode = EditorGUILayout.Toggle(ENABLE_IN_EDIT_MODE, options.enableInEditMode); + + EditorGUILayout.Separator(); + EditorGUILayout.LabelField("Managed Side", EditorStyles.boldLabel); + options.mockAllNativeFunctions = EditorGUILayout.Toggle(TARGET_ALL_NATIVE_FUNCTIONS_GUI_CONTENT, options.mockAllNativeFunctions); - if (EditorGUILayout.Toggle(TARGET_ONLY_EXECUTING_ASSEMBLY_GUI_CONTENT, options.assemblyPaths.Length == 0)) + if (EditorGUILayout.Toggle(ONLY_ASSEMBLY_CSHARP_GUI_CONTENT, options.assemblyNames.Count == 0)) { - options.assemblyPaths = new string[0]; + options.assemblyNames.Clear(); } else { var prevIndent1 = EditorGUI.indentLevel; EditorGUI.indentLevel++; - if (_allKnownAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now) - { - var playerCompiledAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Player) - .Select(a => PathUtils.NormallizeUnityAssemblyPath(a.outputPath)); - - var editorCompiledAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Editor) - .Select(a => PathUtils.NormallizeUnityAssemblyPath(a.outputPath)); - - var assemblyAssets = Resources.FindObjectsOfTypeAll() - .Where(p => !p.isNativePlugin) - .Select(p => PathUtils.NormallizeUnityAssemblyPath(p.assetPath)); - - string[] defaultAssemblyPrefixes = { "UnityEngine.", "UnityEditor.", "Unity.", "com.unity.", "Mono." , "nunit."}; - - _allKnownAssemblies = playerCompiledAssemblies - .Concat(assemblyAssets) - .Concat(editorCompiledAssemblies) - .OrderBy(path => Array.FindIndex(defaultAssemblyPrefixes, p => path.Substring(path.LastIndexOf('/') + 1).StartsWith(p))) - .ToArray(); - _lastKnownAssembliesRefreshTime = DateTime.Now; - } - - if (options.assemblyPaths.Length == 0) - { - var first = GetFirstAssemblyToList(_allKnownAssemblies); - if(first != null) - options.assemblyPaths = new[] { first }; - } + if (_possibleTargetAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now) + RefreshPossibleTargetAssemblies(); + + if (options.assemblyNames.Count == 0) + options.assemblyNames.AddRange(DllManipulator.DEFAULT_ASSEMBLY_NAMES); _showTargetAssemblies = EditorGUILayout.Foldout(_showTargetAssemblies, TARGET_ASSEMBLIES_GUI_CONTENT); if (_showTargetAssemblies) @@ -255,19 +242,23 @@ private void DrawOptions(DllManipulatorOptions options) var prevIndent2 = EditorGUI.indentLevel; EditorGUI.indentLevel++; - var selectedAssemblies = options.assemblyPaths.Where(p => _allKnownAssemblies.Any(a => PathUtils.DllPathsEqual(a, p))).ToList(); - var notSelectedAssemblies = _allKnownAssemblies.Except(selectedAssemblies).ToArray(); - DrawList(selectedAssemblies, i => - { - var values = new[] { selectedAssemblies[i] } - .Concat(notSelectedAssemblies) - .Select(a => a.Substring(a.LastIndexOf('/') + 1)) - .ToArray(); + DrawList(options.assemblyNames, i => + { + var result = EditorGUILayout.TextField(options.assemblyNames[i]); - var selectedIndex = EditorGUILayout.Popup(0, values); - return selectedIndex == 0 ? selectedAssemblies[i] : notSelectedAssemblies[selectedIndex - 1]; - }, notSelectedAssemblies.Length > 0, () => notSelectedAssemblies[0]); - options.assemblyPaths = selectedAssemblies.ToArray(); + // Show a pop up for quickly selecting an assembly + var selectedId = EditorGUILayout.Popup(0, + new[] {"Find"}.Concat(_possibleTargetAssemblies).ToArray(), GUILayout.Width(80)); + + if (selectedId > 0) + result = _possibleTargetAssemblies[selectedId - 1]; + return result; + }, true, () => "", + () => + { + options.assemblyNames = options.assemblyNames + .Concat(_possibleTargetAssemblies).Distinct().ToList(); + }); EditorGUI.indentLevel = prevIndent2; } @@ -275,9 +266,8 @@ private void DrawOptions(DllManipulatorOptions options) EditorGUI.indentLevel = prevIndent1; } - options.onlyInEditor = EditorGUILayout.Toggle(ONLY_IN_EDITOR, options.onlyInEditor); - - options.enableInEditMode = EditorGUILayout.Toggle(ENABLE_IN_EDIT_MODE, options.enableInEditMode); + EditorGUILayout.Separator(); + EditorGUILayout.LabelField("Native Side", EditorStyles.boldLabel); options.dllPathPattern = EditorGUILayout.TextField(DLL_PATH_PATTERN_GUI_CONTENT, options.dllPathPattern); @@ -313,7 +303,32 @@ private void DrawOptions(DllManipulatorOptions options) GUI.enabled = guiEnabledStack.Pop(); } - private void DrawList(IList elements, Func drawElement, bool canAddNewElement, Func getNewElement) + /// + /// Will search for all managed assemblies and store them in . + /// Excludes assemblies starting with + /// + private void RefreshPossibleTargetAssemblies() + { + var playerCompiledAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Player) + .Select(a => Path.GetFileNameWithoutExtension(a.outputPath)); + + var editorCompiledAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Editor) + .Select(a => Path.GetFileNameWithoutExtension(a.outputPath)); + + var assemblyAssets = Resources.FindObjectsOfTypeAll() + .Where(p => !p.isNativePlugin) + .Select(p => Path.GetFileNameWithoutExtension(p.assetPath)); + + _possibleTargetAssemblies = playerCompiledAssemblies + .Concat(editorCompiledAssemblies) + .Concat(assemblyAssets) + .Where(a => !DllManipulator.IGNORED_ASSEMBLY_PREFIXES.Any(a.StartsWith)) + .OrderBy(name => name) + .ToArray(); + _lastKnownAssembliesRefreshTime = DateTime.Now; + } + + private void DrawList(IList elements, Func drawElement, bool canAddNewElement, Func getNewElement, Action addAll) { int indexToRemove = -1; for (int i = 0; i < elements.Count; i++) @@ -334,8 +349,16 @@ private void DrawList(IList elements, Func drawElement, bool canAd GUILayout.Space(EditorGUI.indentLevel * 15); var prevGuiEnabled = GUI.enabled; GUI.enabled = prevGuiEnabled && canAddNewElement; + if (GUILayout.Button("Add", GUILayout.Width(40))) elements.Add(getNewElement()); + + if (GUILayout.Button("Add All", GUILayout.Width(80))) + addAll(); + + if (GUILayout.Button("Reset", GUILayout.Width(50))) + elements.Clear(); + GUI.enabled = prevGuiEnabled; GUILayout.EndHorizontal(); } diff --git a/scripts/Editor/DllManipulatorEditor.cs.meta b/scripts/Editor/DllManipulatorEditor.cs.meta new file mode 100644 index 0000000..08c46fd --- /dev/null +++ b/scripts/Editor/DllManipulatorEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0ad2b782b2fda4d40a37071c3eaa1d82 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/Editor/DllManipulatorWindowEditor.cs.meta b/scripts/Editor/DllManipulatorWindowEditor.cs.meta new file mode 100644 index 0000000..4fb7976 --- /dev/null +++ b/scripts/Editor/DllManipulatorWindowEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 01f26ee2eb448d247b2bec6b541e0c06 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef b/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef new file mode 100644 index 0000000..9a11a9d --- /dev/null +++ b/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef @@ -0,0 +1,17 @@ +{ + "name": "mcpiroman.UnityNativeTool.Editor", + "references": [ + "mcpiroman.UnityNativeTool" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef.meta b/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef.meta new file mode 100644 index 0000000..9b7af5f --- /dev/null +++ b/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 95a3621decb49d845a207123b016081e +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/IlGeneratorExtensions.cs.meta b/scripts/IlGeneratorExtensions.cs.meta new file mode 100644 index 0000000..6f46b3b --- /dev/null +++ b/scripts/IlGeneratorExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b9808b68bb4537341ae7388fb89a9da9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/LowLevelPluginManager.cs.meta b/scripts/LowLevelPluginManager.cs.meta new file mode 100644 index 0000000..1c4cdc5 --- /dev/null +++ b/scripts/LowLevelPluginManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b74bb8d3dfd914041a96c6064839490a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/MethodInvoker.cs.meta b/scripts/MethodInvoker.cs.meta new file mode 100644 index 0000000..02701c3 --- /dev/null +++ b/scripts/MethodInvoker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cdf6629838e0f6d4ba814d70f1b0f921 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/NativeDll.cs.meta b/scripts/NativeDll.cs.meta new file mode 100644 index 0000000..8acd6df --- /dev/null +++ b/scripts/NativeDll.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e31ba279e96a28a46a6d97f2a1499f92 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/NativeFunction.cs.meta b/scripts/NativeFunction.cs.meta new file mode 100644 index 0000000..f6e5a75 --- /dev/null +++ b/scripts/NativeFunction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0cd4d21f295d9e84192725524d2c666f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/NativeFunctionSignature.cs.meta b/scripts/NativeFunctionSignature.cs.meta new file mode 100644 index 0000000..b0bcd9c --- /dev/null +++ b/scripts/NativeFunctionSignature.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9a12f146767c4d44daf22b332d539167 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/PInvokes.cs.meta b/scripts/PInvokes.cs.meta new file mode 100644 index 0000000..b3f6514 --- /dev/null +++ b/scripts/PInvokes.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 49722d5c37d8fb8429ea852f077bf1cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/PathUtils.cs.meta b/scripts/PathUtils.cs.meta new file mode 100644 index 0000000..46a8467 --- /dev/null +++ b/scripts/PathUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0f84112e0e879d340a8aa44bcfe5e9bd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/scripts/mcpiroman.UnityNativeTool.asmdef b/scripts/mcpiroman.UnityNativeTool.asmdef new file mode 100644 index 0000000..e9b1f19 --- /dev/null +++ b/scripts/mcpiroman.UnityNativeTool.asmdef @@ -0,0 +1,13 @@ +{ + "name": "mcpiroman.UnityNativeTool", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/scripts/mcpiroman.UnityNativeTool.asmdef.meta b/scripts/mcpiroman.UnityNativeTool.asmdef.meta new file mode 100644 index 0000000..a6b9e78 --- /dev/null +++ b/scripts/mcpiroman.UnityNativeTool.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 727eeb8221224d74aac364bbeda23b38 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/stubLluiPlugin.c.meta b/stubLluiPlugin.c.meta new file mode 100644 index 0000000..1161909 --- /dev/null +++ b/stubLluiPlugin.c.meta @@ -0,0 +1,27 @@ +fileFormatVersion: 2 +guid: c9016db8f5579a944b899ffb1a7473a9 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 1 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: