Changed type lookup to use TypeCache, instead of iterating through all assemblies
This commit is contained in:
parent
8b927d1997
commit
733a7de800
4 changed files with 85 additions and 17 deletions
|
|
@ -1,8 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
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
|
||||
{
|
||||
internal static class ToolbarSettingsUtility
|
||||
|
|
@ -13,6 +18,21 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
|
||||
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();
|
||||
Type iType = typeof(IToolbarSettings);
|
||||
|
||||
|
|
@ -33,6 +53,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
list.Add(toolbar);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
|
||||
}
|
||||
|
|
@ -50,6 +71,21 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
|
||||
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();
|
||||
Type iType = typeof(IToolbarProjectSettings);
|
||||
|
||||
|
|
@ -70,6 +106,7 @@ namespace Module.NavigationTool.Editor.Toolbar
|
|||
list.Add(toolbar);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
list.Sort((s0, s1) => string.Compare(s0.Title, s1.Title, StringComparison.Ordinal));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue