Changed type lookup to use TypeCache, instead of iterating through all assemblies
This commit is contained in:
parent
8b927d1997
commit
733a7de800
|
|
@ -2,6 +2,12 @@
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
|
||||||
|
## [1.11.3] - 2025-05-11
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- Changed type lookup to use TypeCache, instead of iterating through all assemblies
|
||||||
|
|
||||||
|
|
||||||
## [1.11.2] - 2024-11-26
|
## [1.11.2] - 2024-11-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
|
||||||
|
using UnityEditor;
|
||||||
|
#else
|
||||||
|
using System.Reflection;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Module.NavigationTool.Editor.Toolbar
|
namespace Module.NavigationTool.Editor.Toolbar
|
||||||
{
|
{
|
||||||
internal static class ToolbarSettingsUtility
|
internal static class ToolbarSettingsUtility
|
||||||
|
|
@ -13,6 +18,21 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
|
||||||
|
var types = TypeCache.GetTypesDerivedFrom<IToolbarSettings>();
|
||||||
|
|
||||||
|
for (var i = 0; i < types.Count; i++)
|
||||||
|
{
|
||||||
|
Type type = types[i];
|
||||||
|
|
||||||
|
if (type.IsInterface || type.IsAbstract)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var toolbar = (IToolbarSettings)FormatterServices.GetUninitializedObject(type);
|
||||||
|
toolbar.Initialize();
|
||||||
|
list.Add(toolbar);
|
||||||
|
}
|
||||||
|
#else
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
Type iType = typeof(IToolbarSettings);
|
Type iType = typeof(IToolbarSettings);
|
||||||
|
|
||||||
|
|
@ -33,6 +53,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
list.Add(toolbar);
|
list.Add(toolbar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
|
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +71,21 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
|
||||||
|
var types = TypeCache.GetTypesDerivedFrom<IToolbarProjectSettings>();
|
||||||
|
|
||||||
|
for (var i = 0; i < types.Count; i++)
|
||||||
|
{
|
||||||
|
Type type = types[i];
|
||||||
|
|
||||||
|
if (type.IsInterface || type.IsAbstract)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var toolbar = (IToolbarProjectSettings)FormatterServices.GetUninitializedObject(type);
|
||||||
|
toolbar.Initialize(settings);
|
||||||
|
list.Add(toolbar);
|
||||||
|
}
|
||||||
|
#else
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
Type iType = typeof(IToolbarProjectSettings);
|
Type iType = typeof(IToolbarProjectSettings);
|
||||||
|
|
||||||
|
|
@ -70,6 +106,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
list.Add(toolbar);
|
list.Add(toolbar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
|
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@ using System.Reflection;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
|
||||||
|
using UnityEditor;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if UNITY_2019_1_OR_NEWER
|
#if UNITY_2019_1_OR_NEWER
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
#else
|
#else
|
||||||
|
|
@ -17,25 +21,26 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
{
|
{
|
||||||
private static readonly Assembly ASSEMBLY = typeof(UnityEditor.Editor).Assembly;
|
private static readonly Assembly ASSEMBLY = typeof(UnityEditor.Editor).Assembly;
|
||||||
|
|
||||||
#if UNITY_2021_1_OR_NEWER
|
#if UNITY_2021_1_OR_NEWER
|
||||||
private static ScriptableObject CURRENT_TOOLBAR;
|
private static ScriptableObject CURRENT_TOOLBAR;
|
||||||
|
private static VisualElement CURRENT_ROOT;
|
||||||
private static VisualElement CURRENT_PARENT_LEFT;
|
private static VisualElement CURRENT_PARENT_LEFT;
|
||||||
private static VisualElement CURRENT_PARENT_RIGHT;
|
private static VisualElement CURRENT_PARENT_RIGHT;
|
||||||
private static int CURRENT_INSTANCE_ID = -1;
|
private static int CURRENT_INSTANCE_ID;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if UNITY_2021_1_OR_NEWER
|
#if UNITY_2021_1_OR_NEWER
|
||||||
public static void OnUpdate(Action<VisualElement, VisualElement> callback)
|
public static void OnUpdate(Action<VisualElement, VisualElement> callback)
|
||||||
{
|
{
|
||||||
if (CURRENT_TOOLBAR == null)
|
if (CURRENT_TOOLBAR == null)
|
||||||
CURRENT_TOOLBAR = GetToolbarObject();
|
CURRENT_TOOLBAR = GetToolbarObject();
|
||||||
|
|
||||||
if (CURRENT_TOOLBAR != null && CURRENT_PARENT_LEFT != null && CURRENT_TOOLBAR.GetInstanceID() != CURRENT_INSTANCE_ID)
|
if (CURRENT_TOOLBAR != null && CURRENT_TOOLBAR.GetInstanceID() != CURRENT_INSTANCE_ID)
|
||||||
{
|
{
|
||||||
CURRENT_PARENT_LEFT.RemoveFromHierarchy();
|
CURRENT_PARENT_LEFT?.RemoveFromHierarchy();
|
||||||
CURRENT_PARENT_LEFT = null;
|
CURRENT_PARENT_LEFT = null;
|
||||||
|
|
||||||
CURRENT_PARENT_RIGHT.RemoveFromHierarchy();
|
CURRENT_PARENT_RIGHT?.RemoveFromHierarchy();
|
||||||
CURRENT_PARENT_RIGHT = null;
|
CURRENT_PARENT_RIGHT = null;
|
||||||
|
|
||||||
CURRENT_INSTANCE_ID = CURRENT_TOOLBAR.GetInstanceID();
|
CURRENT_INSTANCE_ID = CURRENT_TOOLBAR.GetInstanceID();
|
||||||
|
|
@ -44,17 +49,25 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
if (CURRENT_TOOLBAR == null)
|
if (CURRENT_TOOLBAR == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (CURRENT_PARENT_LEFT == null)
|
if (CURRENT_PARENT_LEFT == null || CURRENT_PARENT_RIGHT == null || CURRENT_ROOT == null)
|
||||||
{
|
{
|
||||||
|
CURRENT_INSTANCE_ID = CURRENT_TOOLBAR.GetInstanceID();
|
||||||
|
|
||||||
CURRENT_PARENT_LEFT?.RemoveFromHierarchy();
|
CURRENT_PARENT_LEFT?.RemoveFromHierarchy();
|
||||||
|
CURRENT_PARENT_LEFT = null;
|
||||||
|
|
||||||
CURRENT_PARENT_RIGHT?.RemoveFromHierarchy();
|
CURRENT_PARENT_RIGHT?.RemoveFromHierarchy();
|
||||||
|
CURRENT_PARENT_RIGHT = null;
|
||||||
|
|
||||||
FieldInfo root = CURRENT_TOOLBAR.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance);
|
FieldInfo root = CURRENT_TOOLBAR.GetType().GetField("m_Root", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
object rawRoot = root?.GetValue(CURRENT_TOOLBAR);
|
object rawRoot = root?.GetValue(CURRENT_TOOLBAR);
|
||||||
var mRoot = rawRoot as VisualElement;
|
CURRENT_ROOT = rawRoot as VisualElement;
|
||||||
|
|
||||||
CURRENT_PARENT_LEFT = CreateParent(mRoot, "ToolbarZoneLeftAlign", true);
|
if (CURRENT_ROOT != null)
|
||||||
CURRENT_PARENT_RIGHT = CreateParent(mRoot, "ToolbarZoneRightAlign", false);
|
{
|
||||||
|
CURRENT_PARENT_LEFT = CreateParent(CURRENT_ROOT, "ToolbarZoneLeftAlign", true);
|
||||||
|
CURRENT_PARENT_RIGHT = CreateParent(CURRENT_ROOT, "ToolbarZoneRightAlign", false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CURRENT_PARENT_LEFT != null)
|
if (CURRENT_PARENT_LEFT != null)
|
||||||
|
|
@ -111,7 +124,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
parent.Add(result);
|
parent.Add(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
public static void AddGuiListener(Action action)
|
public static void AddGuiListener(Action action)
|
||||||
{
|
{
|
||||||
ScriptableObject so = GetToolbarObject();
|
ScriptableObject so = GetToolbarObject();
|
||||||
|
|
@ -153,7 +166,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
handler += action;
|
handler += action;
|
||||||
fiImguiContainer.SetValue(container, handler);
|
fiImguiContainer.SetValue(container, handler);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private static ScriptableObject GetToolbarObject()
|
private static ScriptableObject GetToolbarObject()
|
||||||
{
|
{
|
||||||
|
|
@ -168,6 +181,17 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
#if UNITY_2021_3 || UNITY_2022_2 || UNITY_6000_0_OR_NEWER
|
||||||
|
var types = TypeCache.GetTypesDerivedFrom<AbstractToolbarDrawer>();
|
||||||
|
|
||||||
|
for (var i = 0; i < types.Count; i++)
|
||||||
|
{
|
||||||
|
Type type = types[i];
|
||||||
|
|
||||||
|
if (!type.IsAbstract)
|
||||||
|
list.Add((AbstractToolbarDrawer)FormatterServices.GetUninitializedObject(type));
|
||||||
|
}
|
||||||
|
#else
|
||||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||||
Type iType = typeof(AbstractToolbarDrawer);
|
Type iType = typeof(AbstractToolbarDrawer);
|
||||||
|
|
||||||
|
|
@ -184,6 +208,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
||||||
list.Add((AbstractToolbarDrawer)FormatterServices.GetUninitializedObject(type));
|
list.Add((AbstractToolbarDrawer)FormatterServices.GetUninitializedObject(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
list.Sort((t0, t1) => t0.Priority.CompareTo(t1.Priority));
|
list.Sort((t0, t1) => t0.Priority.CompareTo(t1.Priority));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.navigationtool",
|
"name": "com.module.navigationtool",
|
||||||
"version": "1.11.2",
|
"version": "1.11.3",
|
||||||
"displayName": "Module.NavigationTool",
|
"displayName": "Module.NavigationTool",
|
||||||
"description": "Support for navigation tools, like favorites, history and toolbars",
|
"description": "Support for navigation tools, like favorites, history and toolbars",
|
||||||
"unity": "2019.2",
|
"unity": "2019.2",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue