Skip to content

Commit 930b0f7

Browse files
authored
Optimizations for RuntimeInspectorUtils.GetType (#69)
1 parent ec8421f commit 930b0f7

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Plugins/RuntimeInspector/Scripts/RuntimeInspector/Helpers/RuntimeInspectorUtils.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static class RuntimeInspectorUtils
2222
{
2323
private static readonly Dictionary<Type, MemberInfo[]> typeToVariables = new Dictionary<Type, MemberInfo[]>( 89 ) { { typeof( object ), null } };
2424
private static readonly Dictionary<Type, ExposedMethod[]> typeToExposedMethods = new Dictionary<Type, ExposedMethod[]>( 89 );
25+
private static readonly Dictionary<string, Type> typeNameToType = new Dictionary<string, Type>( 89 );
2526

2627
private static readonly HashSet<Type> commonSerializableTypes = new HashSet<Type>()
2728
{
@@ -833,6 +834,17 @@ public static object Instantiate( this Type type )
833834
}
834835

835836
public static Type GetType( string typeName )
837+
{
838+
Type cachedType;
839+
if( typeNameToType.TryGetValue( typeName, out cachedType ) )
840+
return cachedType;
841+
842+
Type result = GetTypeUncached( typeName );
843+
typeNameToType[typeName] = result;
844+
return result;
845+
}
846+
847+
private static Type GetTypeUncached( string typeName )
836848
{
837849
try
838850
{
@@ -847,6 +859,19 @@ public static Type GetType( string typeName )
847859
if( type != null )
848860
return type;
849861

862+
// Also try UnityEngine's facade assembly, which covers other split engine modules
863+
try
864+
{
865+
#if UNITY_EDITOR || !NETFX_CORE
866+
type = Assembly.Load( "UnityEngine" ).GetType( "UnityEngine." + typeName );
867+
#else
868+
type = Assembly.Load( new AssemblyName( "UnityEngine" ) ).GetType( "UnityEngine." + typeName );
869+
#endif
870+
if( type != null )
871+
return type;
872+
}
873+
catch { }
874+
850875
// Search all assemblies for type
851876
Type nameMatchingType = null;
852877
foreach (Assembly assembly in GetAllAssemblies() ?? Array.Empty<Assembly>())

0 commit comments

Comments
 (0)