From b6fbd98e216309fee3fc9355691dacd231b788d0 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Sat, 21 Mar 2020 14:34:05 +0100 Subject: [PATCH 01/19] Add upm support Allow users to add this to the Packages folder for it to be used as an embedded package Users can then nicely add the repo as a submodule --- package.json | 25 +++++++++++++++++++++ scripts/Editor/UnityNativeToolEditor.asmdef | 17 ++++++++++++++ scripts/UnityNativeTool.asmdef | 13 +++++++++++ 3 files changed, 55 insertions(+) create mode 100644 package.json create mode 100644 scripts/Editor/UnityNativeToolEditor.asmdef create mode 100644 scripts/UnityNativeTool.asmdef diff --git a/package.json b/package.json new file mode 100644 index 0000000..62904cd --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "com.testpackage.unity-native-tool", + "displayName": "Unity Native Tool", + "version": "0.0.1", + "unity": "2018.1", + "description": "Tool for unloading native DLLs in the editor", + "keywords": [ + "native", + "c++", + "dll" + ], + "category": "Unity", + "type": "tool", + "author": { + "name": "John Doe", + "email": "john.doe@example.com", + "url": "https://github.com/mcpiroman/UnityNativeTool/" + }, + "repository": { + "type": "git", + "url": "git@github.com:mcpiroman/UnityNativeTool.git", + "revision": "6c6b17c36b33c72754d0bf2ee7e7236a68e10665" + } + +} \ No newline at end of file diff --git a/scripts/Editor/UnityNativeToolEditor.asmdef b/scripts/Editor/UnityNativeToolEditor.asmdef new file mode 100644 index 0000000..f38d439 --- /dev/null +++ b/scripts/Editor/UnityNativeToolEditor.asmdef @@ -0,0 +1,17 @@ +{ + "name": "UnityNativeToolEditor", + "references": [ + "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/UnityNativeTool.asmdef b/scripts/UnityNativeTool.asmdef new file mode 100644 index 0000000..d740c1c --- /dev/null +++ b/scripts/UnityNativeTool.asmdef @@ -0,0 +1,13 @@ +{ + "name": "UnityNativeTool", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file From 97e04d833f1cbab4abbbbbdfb56bb28c7b34a0ce Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Sat, 21 Mar 2020 21:59:02 +0100 Subject: [PATCH 02/19] Add meta files --- .gitignore | 1 - LICENSE.txt.meta | 7 +++++ README.md.meta | 7 +++++ package.json.meta | 7 +++++ scripts.meta | 8 ++++++ scripts/Attributes.cs.meta | 11 ++++++++ scripts/Detour.cs.meta | 11 ++++++++ scripts/DllLoadException.cs.meta | 11 ++++++++ scripts/DllManipulator.ReflectionData.cs.meta | 11 ++++++++ scripts/DllManipulator.cs.meta | 11 ++++++++ scripts/DllManipulatorScript.cs.meta | 11 ++++++++ scripts/Editor.meta | 8 ++++++ scripts/Editor/DllManipulatorEditor.cs.meta | 11 ++++++++ .../Editor/DllManipulatorWindowEditor.cs.meta | 11 ++++++++ .../Editor/UnityNativeToolEditor.asmdef.meta | 7 +++++ scripts/IlGeneratorExtensions.cs.meta | 11 ++++++++ scripts/LowLevelPluginManager.cs.meta | 11 ++++++++ scripts/MethodInvoker.cs.meta | 11 ++++++++ scripts/NativeDll.cs.meta | 11 ++++++++ scripts/NativeFunction.cs.meta | 11 ++++++++ scripts/NativeFunctionSignature.cs.meta | 11 ++++++++ scripts/PInvokes.cs.meta | 11 ++++++++ scripts/PathUtils.cs.meta | 11 ++++++++ scripts/UnityNativeTool.asmdef.meta | 7 +++++ stubLluiPlugin.c.meta | 27 +++++++++++++++++++ 25 files changed, 254 insertions(+), 1 deletion(-) create mode 100644 LICENSE.txt.meta create mode 100644 README.md.meta create mode 100644 package.json.meta create mode 100644 scripts.meta create mode 100644 scripts/Attributes.cs.meta create mode 100644 scripts/Detour.cs.meta create mode 100644 scripts/DllLoadException.cs.meta create mode 100644 scripts/DllManipulator.ReflectionData.cs.meta create mode 100644 scripts/DllManipulator.cs.meta create mode 100644 scripts/DllManipulatorScript.cs.meta create mode 100644 scripts/Editor.meta create mode 100644 scripts/Editor/DllManipulatorEditor.cs.meta create mode 100644 scripts/Editor/DllManipulatorWindowEditor.cs.meta create mode 100644 scripts/Editor/UnityNativeToolEditor.asmdef.meta create mode 100644 scripts/IlGeneratorExtensions.cs.meta create mode 100644 scripts/LowLevelPluginManager.cs.meta create mode 100644 scripts/MethodInvoker.cs.meta create mode 100644 scripts/NativeDll.cs.meta create mode 100644 scripts/NativeFunction.cs.meta create mode 100644 scripts/NativeFunctionSignature.cs.meta create mode 100644 scripts/PInvokes.cs.meta create mode 100644 scripts/PathUtils.cs.meta create mode 100644 scripts/UnityNativeTool.asmdef.meta create mode 100644 stubLluiPlugin.c.meta 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.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.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.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.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.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/UnityNativeToolEditor.asmdef.meta b/scripts/Editor/UnityNativeToolEditor.asmdef.meta new file mode 100644 index 0000000..9b7af5f --- /dev/null +++ b/scripts/Editor/UnityNativeToolEditor.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/UnityNativeTool.asmdef.meta b/scripts/UnityNativeTool.asmdef.meta new file mode 100644 index 0000000..a6b9e78 --- /dev/null +++ b/scripts/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: From 4ff816839a69f265c78b472d0c7f07becc919f8f Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Wed, 25 Mar 2020 19:49:38 +0100 Subject: [PATCH 03/19] Potential fix for assemblyPaths using their manifest name --- scripts/DllManipulator.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 2b4c5b4..ab8e495 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -55,11 +55,11 @@ internal static void Initialize(int unityMainThreadId, string assetsPath) else { 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) + assemblies = allAssemblies.Where(a => !a.IsDynamic && Options.assemblyPaths.Any(p => p == a.ManifestModule.Name)).ToArray(); + var missingAssemblies = Options.assemblyPaths.Except(assemblies.Select(a => a.ManifestModule.Name)); + foreach (var assembly in missingAssemblies) { - Debug.LogError($"Could not find assembly at path {assemblyPath}"); + Debug.LogError($"Could not find assembly: {assembly}"); } } From 4c3d9485acc1a301acf157dce39b21996b6b4244 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Mon, 30 Mar 2020 13:47:17 +0200 Subject: [PATCH 04/19] Fallback to windows #if --- scripts/DllManipulator.cs | 22 +++++++++++----------- scripts/DllManipulatorScript.cs | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index ab8e495..a2a555f 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -608,34 +608,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 return PInvokes_Linux.dlopen(filepath, (int)Options.posixDlopenFlags); #elif UNITY_STANDALONE_OSX return PInvokes_Osx.dlopen(filepath, (int)Options.posixDlopenFlags); +#else // UNITY_STANDALONE_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; +#else // UNITY_STANDALONE_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); +#else // UNITY_STANDALONE_WIN + return PInvokes_Windows.GetProcAddress(libHandle, symbol); #endif } } diff --git a/scripts/DllManipulatorScript.cs b/scripts/DllManipulatorScript.cs index fcdf870..992e190 100644 --- a/scripts/DllManipulatorScript.cs +++ b/scripts/DllManipulatorScript.cs @@ -14,12 +14,12 @@ 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", +#else // UNITY_STANDALONE_WIN Windows fallback + "{assets}/Plugins/__{name}.dll", #endif assemblyPaths = new string[0], loadingMode = DllLoadingMode.Lazy, From 00cc2cedfca81781fadf8a6a6f566075e07a04a4 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Sun, 29 Mar 2020 15:15:13 +0200 Subject: [PATCH 05/19] Rename asmdefs --- ...olEditor.asmdef => MCpiroman.UnityNativeToolEditor.asmdef} | 4 ++-- ...smdef.meta => MCpiroman.UnityNativeToolEditor.asmdef.meta} | 0 ...nityNativeTool.asmdef => MCpiroman.UnityNativeTool.asmdef} | 2 +- ...Tool.asmdef.meta => MCpiroman.UnityNativeTool.asmdef.meta} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename scripts/Editor/{UnityNativeToolEditor.asmdef => MCpiroman.UnityNativeToolEditor.asmdef} (79%) rename scripts/Editor/{UnityNativeToolEditor.asmdef.meta => MCpiroman.UnityNativeToolEditor.asmdef.meta} (100%) rename scripts/{UnityNativeTool.asmdef => MCpiroman.UnityNativeTool.asmdef} (87%) rename scripts/{UnityNativeTool.asmdef.meta => MCpiroman.UnityNativeTool.asmdef.meta} (100%) diff --git a/scripts/Editor/UnityNativeToolEditor.asmdef b/scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef similarity index 79% rename from scripts/Editor/UnityNativeToolEditor.asmdef rename to scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef index f38d439..67ed34e 100644 --- a/scripts/Editor/UnityNativeToolEditor.asmdef +++ b/scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef @@ -1,7 +1,7 @@ { - "name": "UnityNativeToolEditor", + "name": "MCpiroman.UnityNativeToolEditor", "references": [ - "UnityNativeTool" + "MCpiroman.UnityNativeTool" ], "includePlatforms": [ "Editor" diff --git a/scripts/Editor/UnityNativeToolEditor.asmdef.meta b/scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef.meta similarity index 100% rename from scripts/Editor/UnityNativeToolEditor.asmdef.meta rename to scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef.meta diff --git a/scripts/UnityNativeTool.asmdef b/scripts/MCpiroman.UnityNativeTool.asmdef similarity index 87% rename from scripts/UnityNativeTool.asmdef rename to scripts/MCpiroman.UnityNativeTool.asmdef index d740c1c..e63765b 100644 --- a/scripts/UnityNativeTool.asmdef +++ b/scripts/MCpiroman.UnityNativeTool.asmdef @@ -1,5 +1,5 @@ { - "name": "UnityNativeTool", + "name": "MCpiroman.UnityNativeTool", "references": [], "includePlatforms": [], "excludePlatforms": [], diff --git a/scripts/UnityNativeTool.asmdef.meta b/scripts/MCpiroman.UnityNativeTool.asmdef.meta similarity index 100% rename from scripts/UnityNativeTool.asmdef.meta rename to scripts/MCpiroman.UnityNativeTool.asmdef.meta From a5fd4553cbb908905af607886c99a39c318b4a20 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Mon, 6 Apr 2020 22:37:29 +0200 Subject: [PATCH 06/19] Improve finding assemblies, always search in our assembly Renamed Editor asmdef --- scripts/DllManipulator.cs | 24 +++++++++---------- ...> MCpiroman.UnityNativeTool.Editor.asmdef} | 2 +- ...iroman.UnityNativeTool.Editor.asmdef.meta} | 0 3 files changed, 12 insertions(+), 14 deletions(-) rename scripts/Editor/{MCpiroman.UnityNativeToolEditor.asmdef => MCpiroman.UnityNativeTool.Editor.asmdef} (88%) rename scripts/Editor/{MCpiroman.UnityNativeToolEditor.asmdef.meta => MCpiroman.UnityNativeTool.Editor.asmdef.meta} (100%) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index a2a555f..36b8ceb 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -47,20 +47,18 @@ internal static void Initialize(int unityMainThreadId, string assetsPath) LowLevelPluginManager.ResetStubPlugin(); - Assembly[] assemblies; - if (Options.assemblyPaths.Length == 0) + IEnumerable assemblyPathsTemp = Options.assemblyPaths; + if (!assemblyPathsTemp.Any()) + assemblyPathsTemp = new[] {"Assembly-CSharp", "Assembly-CSharp-Editor"}; + + assemblyPathsTemp = assemblyPathsTemp.Concat(new [] { "MCpiroman.UnityNativeTool", "MCpiroman.UnityNativeTool.Editor" }); + + var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); + var assemblies = allAssemblies.Where(a => !a.IsDynamic && assemblyPathsTemp.Any(p => p == Path.ChangeExtension(a.ManifestModule.Name, null))).ToArray(); + var missingAssemblies = assemblyPathsTemp.Except(assemblies.Select(a => Path.ChangeExtension(a.ManifestModule.Name, null))); + foreach (var assembly in missingAssemblies) { - assemblies = new[] { Assembly.GetExecutingAssembly() }; - } - else - { - var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); - assemblies = allAssemblies.Where(a => !a.IsDynamic && Options.assemblyPaths.Any(p => p == a.ManifestModule.Name)).ToArray(); - var missingAssemblies = Options.assemblyPaths.Except(assemblies.Select(a => a.ManifestModule.Name)); - foreach (var assembly in missingAssemblies) - { - Debug.LogError($"Could not find assembly: {assembly}"); - } + Debug.LogError($"Could not find assembly: {assembly}"); } foreach (var assembly in assemblies) diff --git a/scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef b/scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef similarity index 88% rename from scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef rename to scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef index 67ed34e..0905027 100644 --- a/scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef +++ b/scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef @@ -1,5 +1,5 @@ { - "name": "MCpiroman.UnityNativeToolEditor", + "name": "MCpiroman.UnityNativeTool.Editor", "references": [ "MCpiroman.UnityNativeTool" ], diff --git a/scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef.meta b/scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef.meta similarity index 100% rename from scripts/Editor/MCpiroman.UnityNativeToolEditor.asmdef.meta rename to scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef.meta From 042c4aa383876d43b3eb6a52a6881029d27fef22 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Mon, 6 Apr 2020 22:37:49 +0200 Subject: [PATCH 07/19] assemblyPaths small fixes, editor gui adapted EditorGUI for the target assemblies is now just a string array. Removed code to find _allKnownAssemblies. assemblyPaths renamed to assemblyNames is now a list. By default only Assembly-CSharp and the Editor variant is targeted. The assembly containing this tool is always included so we find the attributes. --- scripts/DllManipulator.cs | 18 +++++++-- scripts/DllManipulatorScript.cs | 5 ++- scripts/Editor/DllManipulatorEditor.cs | 55 ++++---------------------- 3 files changed, 25 insertions(+), 53 deletions(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 36b8ceb..eb34c1e 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -17,6 +17,16 @@ 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 DllManipulatorOptions Options { get; set; } private static int _unityMainThreadId; @@ -47,11 +57,11 @@ internal static void Initialize(int unityMainThreadId, string assetsPath) LowLevelPluginManager.ResetStubPlugin(); - IEnumerable assemblyPathsTemp = Options.assemblyPaths; + IEnumerable assemblyPathsTemp = Options.assemblyNames; if (!assemblyPathsTemp.Any()) - assemblyPathsTemp = new[] {"Assembly-CSharp", "Assembly-CSharp-Editor"}; + assemblyPathsTemp = DEFAULT_ASSEMBLY_NAMES; - assemblyPathsTemp = assemblyPathsTemp.Concat(new [] { "MCpiroman.UnityNativeTool", "MCpiroman.UnityNativeTool.Editor" }); + assemblyPathsTemp = assemblyPathsTemp.Concat(INTERNAL_ASSEMBLY_NAMES); var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); var assemblies = allAssemblies.Where(a => !a.IsDynamic && assemblyPathsTemp.Any(p => p == Path.ChangeExtension(a.ManifestModule.Name, null))).ToArray(); @@ -642,7 +652,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; diff --git a/scripts/DllManipulatorScript.cs b/scripts/DllManipulatorScript.cs index 992e190..ca88f1d 100644 --- a/scripts/DllManipulatorScript.cs +++ b/scripts/DllManipulatorScript.cs @@ -1,4 +1,5 @@ -using System; +using System; +using System.Collections.Generic; using System.Reflection; using System.Threading; using System.Linq; @@ -21,7 +22,7 @@ public class DllManipulatorScript : MonoBehaviour #else // UNITY_STANDALONE_WIN Windows fallback "{assets}/Plugins/__{name}.dll", #endif - assemblyPaths = new string[0], + assemblyNames = new List(), loadingMode = DllLoadingMode.Lazy, posixDlopenFlags = PosixDlopenFlags.Lazy, threadSafe = false, diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index 69b58ae..6db7d54 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -17,12 +17,12 @@ public class DllManipulatorEditor : Editor 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_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 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" + @@ -53,7 +53,6 @@ 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 bool _showLoadedLibraries = true; private bool _showTargetAssemblies = true; @@ -181,43 +180,17 @@ private void DrawOptions(DllManipulatorOptions options) GUI.enabled = false; 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 (options.assemblyNames.Count == 0) + options.assemblyNames.AddRange(DllManipulator.DEFAULT_ASSEMBLY_NAMES); _showTargetAssemblies = EditorGUILayout.Foldout(_showTargetAssemblies, TARGET_ASSEMBLIES_GUI_CONTENT); if (_showTargetAssemblies) @@ -225,19 +198,7 @@ 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(); - - var selectedIndex = EditorGUILayout.Popup(0, values); - return selectedIndex == 0 ? selectedAssemblies[i] : notSelectedAssemblies[selectedIndex - 1]; - }, notSelectedAssemblies.Length > 0, () => notSelectedAssemblies[0]); - options.assemblyPaths = selectedAssemblies.ToArray(); + DrawList(options.assemblyNames, i => EditorGUILayout.TextField(options.assemblyNames[i]), true, () => ""); EditorGUI.indentLevel = prevIndent2; } From 06abb19cdb524cd1cc17ae1f627f28152490437c Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Tue, 7 Apr 2020 13:59:51 +0200 Subject: [PATCH 08/19] Improve UI, dropdowns, add _allKnownAssemblies back Simplified finding all assemblies, moved to RefreshAllKnownAssemblies() Unity Assemblies are ignored by default. Option to add all known assemblies. Increased refresh time to 5 seconds from 1. --- scripts/DllManipulator.cs | 2 + scripts/Editor/DllManipulatorEditor.cs | 54 +++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index eb34c1e..4e790b3 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -27,6 +27,8 @@ public partial class DllManipulator , "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; diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index 6db7d54..86640a8 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -8,6 +8,7 @@ #endif using System.IO; using System; +using UnityEditorInternal; namespace UnityNativeTool.Internal { @@ -53,6 +54,7 @@ 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(5); private bool _showLoadedLibraries = true; private bool _showTargetAssemblies = true; @@ -189,6 +191,9 @@ private void DrawOptions(DllManipulatorOptions options) var prevIndent1 = EditorGUI.indentLevel; EditorGUI.indentLevel++; + if (_allKnownAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now) + RefreshAllKnownAssemblies(); + if (options.assemblyNames.Count == 0) options.assemblyNames.AddRange(DllManipulator.DEFAULT_ASSEMBLY_NAMES); @@ -198,7 +203,23 @@ private void DrawOptions(DllManipulatorOptions options) var prevIndent2 = EditorGUI.indentLevel; EditorGUI.indentLevel++; - DrawList(options.assemblyNames, i => EditorGUILayout.TextField(options.assemblyNames[i]), true, () => ""); + DrawList(options.assemblyNames, i => + { + var result = EditorGUILayout.TextField(options.assemblyNames[i]); + + // Show a pop up for quickly selecting an assembly + var selectedId = EditorGUILayout.Popup(0, + new[] {"Find"}.Concat(_allKnownAssemblies).ToArray(), GUILayout.Width(80)); + + if (selectedId > 0) + result = _allKnownAssemblies[selectedId - 1]; + return result; + }, true, () => "", + () => + { + options.assemblyNames = options.assemblyNames + .Concat(_allKnownAssemblies).Distinct().ToList(); + }); EditorGUI.indentLevel = prevIndent2; } @@ -242,7 +263,28 @@ 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 RefreshAllKnownAssemblies() + { + var assemblyAsmdefs = Resources.FindObjectsOfTypeAll() + .Select(p => p.name); + + var pluginImporterAsmdefs = Resources.FindObjectsOfTypeAll() + .Where(p => !p.isNativePlugin) + .Select(p => Path.GetFileNameWithoutExtension(p.assetPath)); + + _allKnownAssemblies = assemblyAsmdefs + .Concat(pluginImporterAsmdefs) + .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++) @@ -263,8 +305,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(); } From f93f3c5435f6450e1bed69daf7e0592e4461ddf2 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Tue, 7 Apr 2020 15:04:01 +0200 Subject: [PATCH 09/19] Add gui headers, info box --- scripts/Editor/DllManipulatorEditor.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index 86640a8..bbab2f5 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; @@ -15,12 +15,14 @@ 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 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", + 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 TARGET_ASSEMBLIES_GUI_CONTENT = new GUIContent("Target assemblies", "List of assembly names to mock native functions in (no file extension)."); @@ -71,6 +73,8 @@ public override void OnInspectorGUI() { var t = (DllManipulatorScript)this.target; + EditorGUILayout.HelpBox(INFO_BOX_GUI_CONTENT, MessageType.Info); + DrawOptions(t.Options); EditorGUILayout.Space(); @@ -175,6 +179,11 @@ private void DrawUsedDlls(IList usedDlls) private void DrawOptions(DllManipulatorOptions options) { + 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); var guiEnabledStack = new Stack(); guiEnabledStack.Push(GUI.enabled); @@ -227,8 +236,9 @@ private void DrawOptions(DllManipulatorOptions options) EditorGUI.indentLevel = prevIndent1; } - options.onlyInEditor = EditorGUILayout.Toggle(ONLY_IN_EDITOR, options.onlyInEditor); - + EditorGUILayout.Separator(); + EditorGUILayout.LabelField("Native Side", EditorStyles.boldLabel); + options.dllPathPattern = EditorGUILayout.TextField(DLL_PATH_PATTERN_GUI_CONTENT, options.dllPathPattern); options.loadingMode = (DllLoadingMode)EditorGUILayout.EnumPopup(DLL_LOADING_MODE_GUI_CONTENT, options.loadingMode); From 83b375126f2f610cd1e9f600199113ab0dbe301d Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Tue, 7 Apr 2020 17:58:22 +0200 Subject: [PATCH 10/19] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 252813b..ecb6875 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 From a2a212cc2ba011dd8cbe43b0ccc22fd85fa7f742 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Wed, 8 Apr 2020 18:39:26 +0200 Subject: [PATCH 11/19] Partial revert "assemblyPaths small fixes, editor gui adapted", remove UnityEditorInternal dependency Use original code to find all assemblies, use `Path.GetFileNameWithoutExtension` instead of `PathUtils.NormallizeUnityAssemblyPath`. --- scripts/Editor/DllManipulatorEditor.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index bbab2f5..7e10a25 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -8,7 +8,6 @@ #endif using System.IO; using System; -using UnityEditorInternal; namespace UnityNativeTool.Internal { @@ -279,15 +278,19 @@ private void DrawOptions(DllManipulatorOptions options) /// private void RefreshAllKnownAssemblies() { - var assemblyAsmdefs = Resources.FindObjectsOfTypeAll() - .Select(p => p.name); - - var pluginImporterAsmdefs = Resources.FindObjectsOfTypeAll() + 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)); - _allKnownAssemblies = assemblyAsmdefs - .Concat(pluginImporterAsmdefs) + _allKnownAssemblies = playerCompiledAssemblies + .Concat(editorCompiledAssemblies) + .Concat(assemblyAssets) .Where(a => !DllManipulator.IGNORED_ASSEMBLY_PREFIXES.Any(a.StartsWith)) .OrderBy(name => name) .ToArray(); From 8e1d0e370bdbeb533879ec602e39a0995ff73283 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 17 Apr 2020 10:03:20 +0200 Subject: [PATCH 12/19] Use string[] for Options.assemblyNames --- scripts/DllManipulator.cs | 2 +- scripts/DllManipulatorScript.cs | 2 +- scripts/Editor/DllManipulatorEditor.cs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 86d88f5..2870ad6 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -654,7 +654,7 @@ private static IntPtr SysGetDllProcAddress(IntPtr libHandle, string symbol) public class DllManipulatorOptions { public string dllPathPattern; - public List assemblyNames; // empty means only default assemblies + public string[] assemblyNames; // empty means only default assemblies public DllLoadingMode loadingMode; public PosixDlopenFlags posixDlopenFlags; public bool threadSafe; diff --git a/scripts/DllManipulatorScript.cs b/scripts/DllManipulatorScript.cs index 5c53f8a..8fafe78 100644 --- a/scripts/DllManipulatorScript.cs +++ b/scripts/DllManipulatorScript.cs @@ -28,7 +28,7 @@ public class DllManipulatorScript : MonoBehaviour #else // UNITY_STANDALONE_WIN Windows fallback "{assets}/Plugins/__{name}.dll", #endif - assemblyNames = new List(), + assemblyNames = new string[0], loadingMode = DllLoadingMode.Lazy, posixDlopenFlags = PosixDlopenFlags.Lazy, threadSafe = false, diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index b21e46c..97235a4 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -194,9 +194,9 @@ private void DrawOptions(DllManipulatorOptions options) GUI.enabled = false; options.mockAllNativeFunctions = EditorGUILayout.Toggle(TARGET_ALL_NATIVE_FUNCTIONS_GUI_CONTENT, options.mockAllNativeFunctions); - if (EditorGUILayout.Toggle(ONLY_ASSEMBLY_CSHARP_GUI_CONTENT, options.assemblyNames.Count == 0)) + if (EditorGUILayout.Toggle(ONLY_ASSEMBLY_CSHARP_GUI_CONTENT, options.assemblyNames.Length == 0)) { - options.assemblyNames.Clear(); + options.assemblyNames = new string[0]; } else { @@ -206,8 +206,8 @@ private void DrawOptions(DllManipulatorOptions options) if (_allKnownAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now) RefreshAllKnownAssemblies(); - if (options.assemblyNames.Count == 0) - options.assemblyNames.AddRange(DllManipulator.DEFAULT_ASSEMBLY_NAMES); + if (options.assemblyNames.Length == 0) + options.assemblyNames = DllManipulator.DEFAULT_ASSEMBLY_NAMES; _showTargetAssemblies = EditorGUILayout.Foldout(_showTargetAssemblies, TARGET_ASSEMBLIES_GUI_CONTENT); if (_showTargetAssemblies) @@ -230,7 +230,7 @@ private void DrawOptions(DllManipulatorOptions options) () => { options.assemblyNames = options.assemblyNames - .Concat(_allKnownAssemblies).Distinct().ToList(); + .Concat(_allKnownAssemblies).Distinct().ToArray(); }); EditorGUI.indentLevel = prevIndent2; From f4bb9dc870681d6e65ad807c25f4bc86f9a7b74c Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 17 Apr 2020 10:34:18 +0200 Subject: [PATCH 13/19] Changed package.json --- package.json | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 62904cd..77521a0 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,14 @@ { - "name": "com.testpackage.unity-native-tool", + "name": "com.mcpiroman.unity-native-tool", "displayName": "Unity Native Tool", - "version": "0.0.1", - "unity": "2018.1", - "description": "Tool for unloading native DLLs in the editor", + "version": "7.1.0", + "description": "Tool for unloading native DLLs in the editor. \nhttps://github.com/mcpiroman/UnityNativeTool", "keywords": [ "native", "c++", "dll" ], "category": "Unity", - "type": "tool", "author": { "name": "John Doe", "email": "john.doe@example.com", @@ -18,8 +16,6 @@ }, "repository": { "type": "git", - "url": "git@github.com:mcpiroman/UnityNativeTool.git", - "revision": "6c6b17c36b33c72754d0bf2ee7e7236a68e10665" + "url": "https://github.com/mcpiroman/UnityNativeTool.git" } - } \ No newline at end of file From 6ca1ba067e78166db227a21c49a5f32161a3afc6 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 17 Apr 2020 11:19:32 +0200 Subject: [PATCH 14/19] Bug fix, disable whole gui in play mode --- scripts/Editor/DllManipulatorEditor.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index 97235a4..6902ada 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -182,16 +182,17 @@ 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); - var guiEnabledStack = new Stack(); - guiEnabledStack.Push(GUI.enabled); - if (EditorApplication.isPlaying) - GUI.enabled = false; options.mockAllNativeFunctions = EditorGUILayout.Toggle(TARGET_ALL_NATIVE_FUNCTIONS_GUI_CONTENT, options.mockAllNativeFunctions); if (EditorGUILayout.Toggle(ONLY_ASSEMBLY_CSHARP_GUI_CONTENT, options.assemblyNames.Length == 0)) From e64dd99402dfdac8b9e3ae87d2fcd024f9e3a559 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 17 Apr 2020 10:03:20 +0200 Subject: [PATCH 15/19] Revert "Use string[] for Options.assemblyNames" This reverts commit 8e1d0e370bdbeb533879ec602e39a0995ff73283. --- scripts/DllManipulator.cs | 2 +- scripts/DllManipulatorScript.cs | 2 +- scripts/Editor/DllManipulatorEditor.cs | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 2870ad6..86d88f5 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -654,7 +654,7 @@ private static IntPtr SysGetDllProcAddress(IntPtr libHandle, string symbol) public class DllManipulatorOptions { public string dllPathPattern; - public string[] assemblyNames; // empty means only default assemblies + public List assemblyNames; // empty means only default assemblies public DllLoadingMode loadingMode; public PosixDlopenFlags posixDlopenFlags; public bool threadSafe; diff --git a/scripts/DllManipulatorScript.cs b/scripts/DllManipulatorScript.cs index 8fafe78..5c53f8a 100644 --- a/scripts/DllManipulatorScript.cs +++ b/scripts/DllManipulatorScript.cs @@ -28,7 +28,7 @@ public class DllManipulatorScript : MonoBehaviour #else // UNITY_STANDALONE_WIN Windows fallback "{assets}/Plugins/__{name}.dll", #endif - assemblyNames = new string[0], + assemblyNames = new List(), loadingMode = DllLoadingMode.Lazy, posixDlopenFlags = PosixDlopenFlags.Lazy, threadSafe = false, diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index 6902ada..931b498 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -195,9 +195,9 @@ private void DrawOptions(DllManipulatorOptions options) options.mockAllNativeFunctions = EditorGUILayout.Toggle(TARGET_ALL_NATIVE_FUNCTIONS_GUI_CONTENT, options.mockAllNativeFunctions); - if (EditorGUILayout.Toggle(ONLY_ASSEMBLY_CSHARP_GUI_CONTENT, options.assemblyNames.Length == 0)) + if (EditorGUILayout.Toggle(ONLY_ASSEMBLY_CSHARP_GUI_CONTENT, options.assemblyNames.Count == 0)) { - options.assemblyNames = new string[0]; + options.assemblyNames.Clear(); } else { @@ -207,8 +207,8 @@ private void DrawOptions(DllManipulatorOptions options) if (_allKnownAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now) RefreshAllKnownAssemblies(); - if (options.assemblyNames.Length == 0) - options.assemblyNames = DllManipulator.DEFAULT_ASSEMBLY_NAMES; + if (options.assemblyNames.Count == 0) + options.assemblyNames.AddRange(DllManipulator.DEFAULT_ASSEMBLY_NAMES); _showTargetAssemblies = EditorGUILayout.Foldout(_showTargetAssemblies, TARGET_ASSEMBLIES_GUI_CONTENT); if (_showTargetAssemblies) @@ -231,7 +231,7 @@ private void DrawOptions(DllManipulatorOptions options) () => { options.assemblyNames = options.assemblyNames - .Concat(_allKnownAssemblies).Distinct().ToArray(); + .Concat(_allKnownAssemblies).Distinct().ToList(); }); EditorGUI.indentLevel = prevIndent2; From b5d22b269911da87024e66756deaf98d52896808 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 17 Apr 2020 11:49:04 +0200 Subject: [PATCH 16/19] Bug fix, hide errors for not finding default assemblies Some project may not have any editor scripts so will always get an error as Assembly-CSharp-Editor does not exist. --- scripts/DllManipulator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 86d88f5..7b1d06e 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -68,7 +68,7 @@ internal static void Initialize(int unityMainThreadId, string assetsPath) var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); var assemblies = allAssemblies.Where(a => !a.IsDynamic && assemblyPathsTemp.Any(p => p == Path.ChangeExtension(a.ManifestModule.Name, null))).ToArray(); var missingAssemblies = assemblyPathsTemp.Except(assemblies.Select(a => Path.ChangeExtension(a.ManifestModule.Name, null))); - foreach (var assembly in missingAssemblies) + foreach (var assembly in missingAssemblies.Except(DEFAULT_ASSEMBLY_NAMES)) { Debug.LogError($"Could not find assembly: {assembly}"); } From 24ce6c553fdff01066e936f90f780f81028cc65b Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 1 May 2020 13:28:20 +0200 Subject: [PATCH 17/19] Merge fixes --- scripts/DllManipulator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index 6ea3a36..e029eef 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -704,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; @@ -720,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 && From 6ed69a9012af13f5647b5e50bf5c64d44a61e788 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 1 May 2020 15:45:11 +0200 Subject: [PATCH 18/19] Review changes --- scripts/DllManipulator.cs | 18 +++++++++--------- scripts/DllManipulatorScript.cs | 4 ++-- scripts/Editor/DllManipulatorEditor.cs | 18 +++++++++--------- ...=> mcpiroman.UnityNativeTool.Editor.asmdef} | 4 ++-- ...piroman.UnityNativeTool.Editor.asmdef.meta} | 0 ...asmdef => mcpiroman.UnityNativeTool.asmdef} | 2 +- ...a => mcpiroman.UnityNativeTool.asmdef.meta} | 0 7 files changed, 23 insertions(+), 23 deletions(-) rename scripts/Editor/{MCpiroman.UnityNativeTool.Editor.asmdef => mcpiroman.UnityNativeTool.Editor.asmdef} (79%) rename scripts/Editor/{MCpiroman.UnityNativeTool.Editor.asmdef.meta => mcpiroman.UnityNativeTool.Editor.asmdef.meta} (100%) rename scripts/{MCpiroman.UnityNativeTool.asmdef => mcpiroman.UnityNativeTool.asmdef} (87%) rename scripts/{MCpiroman.UnityNativeTool.asmdef.meta => mcpiroman.UnityNativeTool.asmdef.meta} (100%) diff --git a/scripts/DllManipulator.cs b/scripts/DllManipulator.cs index e029eef..e61840d 100644 --- a/scripts/DllManipulator.cs +++ b/scripts/DllManipulator.cs @@ -22,9 +22,9 @@ public partial class DllManipulator , "Assembly-CSharp-Editor" #endif }; - public static readonly string[] INTERNAL_ASSEMBLY_NAMES = {"MCpiroman.UnityNativeTool" + public static readonly string[] INTERNAL_ASSEMBLY_NAMES = {"mcpiroman.UnityNativeTool" #if UNITY_EDITOR - , "MCpiroman.UnityNativeTool.Editor" + , "mcpiroman.UnityNativeTool.Editor" #endif }; public static readonly string[] IGNORED_ASSEMBLY_PREFIXES = { "UnityEngine.", "UnityEditor.", "Unity.", "com.unity.", "Mono." , "nunit."}; @@ -67,8 +67,8 @@ internal static void Initialize(int unityMainThreadId, string assetsPath) assemblyPathsTemp = assemblyPathsTemp.Concat(INTERNAL_ASSEMBLY_NAMES); var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); - var assemblies = allAssemblies.Where(a => !a.IsDynamic && assemblyPathsTemp.Any(p => p == Path.ChangeExtension(a.ManifestModule.Name, null))).ToArray(); - var missingAssemblies = assemblyPathsTemp.Except(assemblies.Select(a => Path.ChangeExtension(a.ManifestModule.Name, null))); + 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)) { Debug.LogError($"Could not find assembly: {assembly}"); @@ -654,11 +654,11 @@ private static void WriteNativeCrashLog(NativeFunction nativeFunction, object[] private static IntPtr SysLoadDll(string filepath) { -#if 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); -#else // UNITY_STANDALONE_WIN +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN return PInvokes_Windows.LoadLibrary(filepath); #endif } @@ -669,7 +669,7 @@ private static bool SysUnloadDll(IntPtr libHandle) return PInvokes_Linux.dlclose(libHandle) == 0; #elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX return PInvokes_Osx.dlclose(libHandle) == 0; -#else // UNITY_STANDALONE_WIN +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN return PInvokes_Windows.FreeLibrary(libHandle); #endif } @@ -680,7 +680,7 @@ private static IntPtr SysGetDllProcAddress(IntPtr libHandle, string symbol) return PInvokes_Linux.dlsym(libHandle, symbol); #elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX return PInvokes_Osx.dlsym(libHandle, symbol); -#else // UNITY_STANDALONE_WIN +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN return PInvokes_Windows.GetProcAddress(libHandle, symbol); #endif } diff --git a/scripts/DllManipulatorScript.cs b/scripts/DllManipulatorScript.cs index 9983901..2acbafd 100644 --- a/scripts/DllManipulatorScript.cs +++ b/scripts/DllManipulatorScript.cs @@ -24,8 +24,8 @@ public class DllManipulatorScript : MonoBehaviour "{assets}/Plugins/__{name}.so", #elif UNITY_STANDALONE_OSX || UNITY_EDITOR_OSX "{assets}/Plugins/__{name}.dylib", -#else // UNITY_STANDALONE_WIN Windows fallback - "{assets}/Plugins/__{name}.dll", +#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN + "{assets}/Plugins/__{name}.dll", #endif assemblyNames = new List(), loadingMode = DllLoadingMode.Lazy, diff --git a/scripts/Editor/DllManipulatorEditor.cs b/scripts/Editor/DllManipulatorEditor.cs index 7287ff1..6fd2378 100644 --- a/scripts/Editor/DllManipulatorEditor.cs +++ b/scripts/Editor/DllManipulatorEditor.cs @@ -63,7 +63,7 @@ public class DllManipulatorEditor : Editor private bool _showLoadedLibraries = true; private bool _showTargetAssemblies = true; - private string[] _allKnownAssemblies = null; + private string[] _possibleTargetAssemblies = null; private DateTime _lastKnownAssembliesRefreshTime; /// @@ -230,8 +230,8 @@ private void DrawOptions(DllManipulatorOptions options) var prevIndent1 = EditorGUI.indentLevel; EditorGUI.indentLevel++; - if (_allKnownAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now) - RefreshAllKnownAssemblies(); + if (_possibleTargetAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now) + RefreshPossibleTargetAssemblies(); if (options.assemblyNames.Count == 0) options.assemblyNames.AddRange(DllManipulator.DEFAULT_ASSEMBLY_NAMES); @@ -248,16 +248,16 @@ private void DrawOptions(DllManipulatorOptions options) // Show a pop up for quickly selecting an assembly var selectedId = EditorGUILayout.Popup(0, - new[] {"Find"}.Concat(_allKnownAssemblies).ToArray(), GUILayout.Width(80)); + new[] {"Find"}.Concat(_possibleTargetAssemblies).ToArray(), GUILayout.Width(80)); if (selectedId > 0) - result = _allKnownAssemblies[selectedId - 1]; + result = _possibleTargetAssemblies[selectedId - 1]; return result; }, true, () => "", () => { options.assemblyNames = options.assemblyNames - .Concat(_allKnownAssemblies).Distinct().ToList(); + .Concat(_possibleTargetAssemblies).Distinct().ToList(); }); EditorGUI.indentLevel = prevIndent2; @@ -304,10 +304,10 @@ private void DrawOptions(DllManipulatorOptions options) } /// - /// Will search for all managed assemblies and store them in . + /// Will search for all managed assemblies and store them in . /// Excludes assemblies starting with /// - private void RefreshAllKnownAssemblies() + private void RefreshPossibleTargetAssemblies() { var playerCompiledAssemblies = CompilationPipeline.GetAssemblies(AssembliesType.Player) .Select(a => Path.GetFileNameWithoutExtension(a.outputPath)); @@ -319,7 +319,7 @@ private void RefreshAllKnownAssemblies() .Where(p => !p.isNativePlugin) .Select(p => Path.GetFileNameWithoutExtension(p.assetPath)); - _allKnownAssemblies = playerCompiledAssemblies + _possibleTargetAssemblies = playerCompiledAssemblies .Concat(editorCompiledAssemblies) .Concat(assemblyAssets) .Where(a => !DllManipulator.IGNORED_ASSEMBLY_PREFIXES.Any(a.StartsWith)) diff --git a/scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef b/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef similarity index 79% rename from scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef rename to scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef index 0905027..9a11a9d 100644 --- a/scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef +++ b/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef @@ -1,7 +1,7 @@ { - "name": "MCpiroman.UnityNativeTool.Editor", + "name": "mcpiroman.UnityNativeTool.Editor", "references": [ - "MCpiroman.UnityNativeTool" + "mcpiroman.UnityNativeTool" ], "includePlatforms": [ "Editor" diff --git a/scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef.meta b/scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef.meta similarity index 100% rename from scripts/Editor/MCpiroman.UnityNativeTool.Editor.asmdef.meta rename to scripts/Editor/mcpiroman.UnityNativeTool.Editor.asmdef.meta diff --git a/scripts/MCpiroman.UnityNativeTool.asmdef b/scripts/mcpiroman.UnityNativeTool.asmdef similarity index 87% rename from scripts/MCpiroman.UnityNativeTool.asmdef rename to scripts/mcpiroman.UnityNativeTool.asmdef index e63765b..e9b1f19 100644 --- a/scripts/MCpiroman.UnityNativeTool.asmdef +++ b/scripts/mcpiroman.UnityNativeTool.asmdef @@ -1,5 +1,5 @@ { - "name": "MCpiroman.UnityNativeTool", + "name": "mcpiroman.UnityNativeTool", "references": [], "includePlatforms": [], "excludePlatforms": [], diff --git a/scripts/MCpiroman.UnityNativeTool.asmdef.meta b/scripts/mcpiroman.UnityNativeTool.asmdef.meta similarity index 100% rename from scripts/MCpiroman.UnityNativeTool.asmdef.meta rename to scripts/mcpiroman.UnityNativeTool.asmdef.meta From 7d397baef80d7565e62b77929093d7241bdc6261 Mon Sep 17 00:00:00 2001 From: Roger Barton Date: Fri, 1 May 2020 16:52:49 +0200 Subject: [PATCH 19/19] Removed upm author field --- package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/package.json b/package.json index 77521a0..04f7904 100644 --- a/package.json +++ b/package.json @@ -9,11 +9,6 @@ "dll" ], "category": "Unity", - "author": { - "name": "John Doe", - "email": "john.doe@example.com", - "url": "https://github.com/mcpiroman/UnityNativeTool/" - }, "repository": { "type": "git", "url": "https://github.com/mcpiroman/UnityNativeTool.git"