@@ -22,9 +22,11 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
22
22
23
23
const int k_MaxTypePopupLineCount = 13 ;
24
24
static readonly Type k_UnityObjectType = typeof ( UnityEngine . Object ) ;
25
+ static readonly GUIContent k_NullDisplayName = new GUIContent ( TypeMenuUtility . k_NullDisplayName ) ;
25
26
static readonly GUIContent k_IsNotManagedReferenceLabel = new GUIContent ( "The property type is not manage reference." ) ;
26
27
27
28
readonly Dictionary < string , TypePopupCache > m_TypePopups = new Dictionary < string , TypePopupCache > ( ) ;
29
+ readonly Dictionary < string , GUIContent > m_TypeNameCaches = new Dictionary < string , GUIContent > ( ) ;
28
30
29
31
SerializedProperty m_TargetProperty ;
30
32
@@ -40,7 +42,7 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
40
42
popupPosition . x += EditorGUIUtility . labelWidth ;
41
43
popupPosition . height = EditorGUIUtility . singleLineHeight ;
42
44
43
- if ( EditorGUI . DropdownButton ( popupPosition , new GUIContent ( GetTypeName ( property ) ) , FocusType . Keyboard ) ) {
45
+ if ( EditorGUI . DropdownButton ( popupPosition , GetTypeName ( property ) , FocusType . Keyboard ) ) {
44
46
m_TargetProperty = property ;
45
47
popup . TypePopup . Show ( popupPosition ) ;
46
48
}
@@ -60,17 +62,14 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
60
62
61
63
Type baseType = property . GetManagedReferenceFieldType ( ) ;
62
64
var popup = new AdvancedTypePopup (
63
- AppDomain . CurrentDomain . GetAssemblies ( )
64
- . SelectMany ( assembly => assembly . GetTypes ( ) )
65
- . Where ( p =>
66
- p . IsClass &&
67
- ( p . IsPublic || p . IsNestedPublic ) &&
68
- ! p . IsAbstract &&
69
- ! p . IsGenericType &&
70
- baseType . IsAssignableFrom ( p ) &&
71
- ! k_UnityObjectType . IsAssignableFrom ( p ) &&
72
- Attribute . IsDefined ( p , typeof ( SerializableAttribute ) )
73
- ) ,
65
+ TypeCache . GetTypesDerivedFrom ( baseType ) . Where ( p =>
66
+ p . IsClass &&
67
+ ( p . IsPublic || p . IsNestedPublic ) &&
68
+ ! p . IsAbstract &&
69
+ ! p . IsGenericType &&
70
+ ! k_UnityObjectType . IsAssignableFrom ( p ) &&
71
+ Attribute . IsDefined ( p , typeof ( SerializableAttribute ) )
72
+ ) ,
74
73
k_MaxTypePopupLineCount ,
75
74
state
76
75
) ;
@@ -86,22 +85,32 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
86
85
return result ;
87
86
}
88
87
89
- static string GetTypeName ( SerializedProperty property ) {
88
+ GUIContent GetTypeName ( SerializedProperty property ) {
90
89
if ( string . IsNullOrEmpty ( property . managedReferenceFullTypename ) ) {
91
- return TypeMenuUtility . k_NullDisplayName ;
90
+ return k_NullDisplayName ;
91
+ }
92
+ if ( m_TypeNameCaches . TryGetValue ( property . managedReferenceFullTypename , out GUIContent cachedTypeName ) ) {
93
+ return cachedTypeName ;
92
94
}
93
95
94
96
Type type = property . GetManagedReferenceType ( ) ;
97
+ string typeName = null ;
95
98
96
99
AddTypeMenuAttribute typeMenu = TypeMenuUtility . GetAttribute ( type ) ;
97
100
if ( typeMenu != null ) {
98
- string typeName = typeMenu . GetTypeNameWithoutPath ( ) ;
101
+ typeName = typeMenu . GetTypeNameWithoutPath ( ) ;
99
102
if ( ! string . IsNullOrWhiteSpace ( typeName ) ) {
100
- return ObjectNames . NicifyVariableName ( typeName ) ;
103
+ typeName = ObjectNames . NicifyVariableName ( typeName ) ;
101
104
}
102
105
}
103
106
104
- return ObjectNames . NicifyVariableName ( type . Name ) ;
107
+ if ( string . IsNullOrWhiteSpace ( typeName ) ) {
108
+ typeName = ObjectNames . NicifyVariableName ( type . Name ) ;
109
+ }
110
+
111
+ GUIContent result = new GUIContent ( typeName ) ;
112
+ m_TypeNameCaches . Add ( property . managedReferenceFullTypename , result ) ;
113
+ return result ;
105
114
}
106
115
107
116
public override float GetPropertyHeight ( SerializedProperty property , GUIContent label ) {
0 commit comments