Skip to content

Commit 06abb19

Browse files
committed
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.
1 parent 042c4aa commit 06abb19

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

scripts/DllManipulator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public partial class DllManipulator
2727
, "MCpiroman.UnityNativeTool.Editor"
2828
#endif
2929
};
30+
public static readonly string[] IGNORED_ASSEMBLY_PREFIXES = { "UnityEngine.", "UnityEditor.", "Unity.", "com.unity.", "Mono." , "nunit."};
31+
3032

3133
public static DllManipulatorOptions Options { get; set; }
3234
private static int _unityMainThreadId;

scripts/Editor/DllManipulatorEditor.cs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#endif
99
using System.IO;
1010
using System;
11+
using UnityEditorInternal;
1112

1213
namespace UnityNativeTool.Internal
1314
{
@@ -53,6 +54,7 @@ public class DllManipulatorEditor : Editor
5354
"Use only if you are sure no other thread will be call mocked natives.");
5455
private static readonly GUIContent UNLOAD_ALL_DLLS_AND_PAUSE_WITH_THREAD_SAFETY_GUI_CONTENT = new GUIContent("Unload all DLLs & Pause [dangerous]",
5556
"Use only if you are sure no other thread will be call mocked natives.");
57+
private static readonly TimeSpan ASSEMBLIES_REFRESH_INTERVAL = TimeSpan.FromSeconds(5);
5658

5759
private bool _showLoadedLibraries = true;
5860
private bool _showTargetAssemblies = true;
@@ -189,6 +191,9 @@ private void DrawOptions(DllManipulatorOptions options)
189191
var prevIndent1 = EditorGUI.indentLevel;
190192
EditorGUI.indentLevel++;
191193

194+
if (_allKnownAssemblies == null || _lastKnownAssembliesRefreshTime + ASSEMBLIES_REFRESH_INTERVAL < DateTime.Now)
195+
RefreshAllKnownAssemblies();
196+
192197
if (options.assemblyNames.Count == 0)
193198
options.assemblyNames.AddRange(DllManipulator.DEFAULT_ASSEMBLY_NAMES);
194199

@@ -198,7 +203,23 @@ private void DrawOptions(DllManipulatorOptions options)
198203
var prevIndent2 = EditorGUI.indentLevel;
199204
EditorGUI.indentLevel++;
200205

201-
DrawList(options.assemblyNames, i => EditorGUILayout.TextField(options.assemblyNames[i]), true, () => "");
206+
DrawList(options.assemblyNames, i =>
207+
{
208+
var result = EditorGUILayout.TextField(options.assemblyNames[i]);
209+
210+
// Show a pop up for quickly selecting an assembly
211+
var selectedId = EditorGUILayout.Popup(0,
212+
new[] {"Find"}.Concat(_allKnownAssemblies).ToArray(), GUILayout.Width(80));
213+
214+
if (selectedId > 0)
215+
result = _allKnownAssemblies[selectedId - 1];
216+
return result;
217+
}, true, () => "",
218+
() =>
219+
{
220+
options.assemblyNames = options.assemblyNames
221+
.Concat(_allKnownAssemblies).Distinct().ToList();
222+
});
202223

203224
EditorGUI.indentLevel = prevIndent2;
204225
}
@@ -242,7 +263,28 @@ private void DrawOptions(DllManipulatorOptions options)
242263
GUI.enabled = guiEnabledStack.Pop();
243264
}
244265

245-
private void DrawList<T>(IList<T> elements, Func<int, T> drawElement, bool canAddNewElement, Func<T> getNewElement)
266+
/// <summary>
267+
/// Will search for all managed assemblies and store them in <see cref="_allKnownAssemblies"/>.
268+
/// Excludes assemblies starting with <see cref="DllManipulator.IGNORED_ASSEMBLY_PREFIXES"/>
269+
/// </summary>
270+
private void RefreshAllKnownAssemblies()
271+
{
272+
var assemblyAsmdefs = Resources.FindObjectsOfTypeAll<AssemblyDefinitionAsset>()
273+
.Select(p => p.name);
274+
275+
var pluginImporterAsmdefs = Resources.FindObjectsOfTypeAll<PluginImporter>()
276+
.Where(p => !p.isNativePlugin)
277+
.Select(p => Path.GetFileNameWithoutExtension(p.assetPath));
278+
279+
_allKnownAssemblies = assemblyAsmdefs
280+
.Concat(pluginImporterAsmdefs)
281+
.Where(a => !DllManipulator.IGNORED_ASSEMBLY_PREFIXES.Any(a.StartsWith))
282+
.OrderBy(name => name)
283+
.ToArray();
284+
_lastKnownAssembliesRefreshTime = DateTime.Now;
285+
}
286+
287+
private void DrawList<T>(IList<T> elements, Func<int, T> drawElement, bool canAddNewElement, Func<T> getNewElement, Action addAll)
246288
{
247289
int indexToRemove = -1;
248290
for (int i = 0; i < elements.Count; i++)
@@ -263,8 +305,16 @@ private void DrawList<T>(IList<T> elements, Func<int, T> drawElement, bool canAd
263305
GUILayout.Space(EditorGUI.indentLevel * 15);
264306
var prevGuiEnabled = GUI.enabled;
265307
GUI.enabled = prevGuiEnabled && canAddNewElement;
308+
266309
if (GUILayout.Button("Add", GUILayout.Width(40)))
267310
elements.Add(getNewElement());
311+
312+
if (GUILayout.Button("Add All", GUILayout.Width(80)))
313+
addAll();
314+
315+
if (GUILayout.Button("Reset", GUILayout.Width(50)))
316+
elements.Clear();
317+
268318
GUI.enabled = prevGuiEnabled;
269319
GUILayout.EndHorizontal();
270320
}

0 commit comments

Comments
 (0)