@@ -29,20 +29,19 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
29
29
readonly Dictionary < string , GUIContent > m_TypeNameCaches = new Dictionary < string , GUIContent > ( ) ;
30
30
31
31
SerializedProperty m_TargetProperty ;
32
-
32
+
33
33
public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label ) {
34
34
EditorGUI . BeginProperty ( position , label , property ) ;
35
35
36
36
if ( property . propertyType == SerializedPropertyType . ManagedReference ) {
37
- TypePopupCache popup = GetTypePopup ( property ) ;
38
-
39
37
// Draw the subclass selector popup.
40
38
Rect popupPosition = new Rect ( position ) ;
41
39
popupPosition . width -= EditorGUIUtility . labelWidth ;
42
40
popupPosition . x += EditorGUIUtility . labelWidth ;
43
41
popupPosition . height = EditorGUIUtility . singleLineHeight ;
44
42
45
43
if ( EditorGUI . DropdownButton ( popupPosition , GetTypeName ( property ) , FocusType . Keyboard ) ) {
44
+ TypePopupCache popup = GetTypePopup ( property ) ;
46
45
m_TargetProperty = property ;
47
46
popup . TypePopup . Show ( popupPosition ) ;
48
47
}
@@ -57,10 +56,13 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
57
56
}
58
57
59
58
TypePopupCache GetTypePopup ( SerializedProperty property ) {
60
- if ( ! m_TypePopups . TryGetValue ( property . managedReferenceFieldTypename , out TypePopupCache result ) ) {
61
- var state = new AdvancedDropdownState ( ) ;
59
+ // Cache this string. This property internally call Assembly.GetName, which result in a large allocation.
60
+ string managedReferenceFieldTypename = property . managedReferenceFieldTypename ;
62
61
63
- Type baseType = property . GetManagedReferenceFieldType ( ) ;
62
+ if ( ! m_TypePopups . TryGetValue ( managedReferenceFieldTypename , out TypePopupCache result ) ) {
63
+ var state = new AdvancedDropdownState ( ) ;
64
+
65
+ Type baseType = ManagedReferenceUtility . GetType ( managedReferenceFieldTypename ) ;
64
66
var popup = new AdvancedTypePopup (
65
67
TypeCache . GetTypesDerivedFrom ( baseType ) . Where ( p =>
66
68
( p . IsPublic || p . IsNestedPublic ) &&
@@ -79,20 +81,23 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
79
81
m_TargetProperty . serializedObject . ApplyModifiedProperties ( ) ;
80
82
} ;
81
83
82
- m_TypePopups . Add ( property . managedReferenceFieldTypename , new TypePopupCache ( popup , state ) ) ;
84
+ m_TypePopups . Add ( managedReferenceFieldTypename , new TypePopupCache ( popup , state ) ) ;
83
85
}
84
86
return result ;
85
87
}
86
88
87
89
GUIContent GetTypeName ( SerializedProperty property ) {
88
- if ( string . IsNullOrEmpty ( property . managedReferenceFullTypename ) ) {
90
+ // Cache this string.
91
+ string managedReferenceFullTypename = property . managedReferenceFullTypename ;
92
+
93
+ if ( string . IsNullOrEmpty ( managedReferenceFullTypename ) ) {
89
94
return k_NullDisplayName ;
90
95
}
91
- if ( m_TypeNameCaches . TryGetValue ( property . managedReferenceFullTypename , out GUIContent cachedTypeName ) ) {
96
+ if ( m_TypeNameCaches . TryGetValue ( managedReferenceFullTypename , out GUIContent cachedTypeName ) ) {
92
97
return cachedTypeName ;
93
98
}
94
99
95
- Type type = property . GetManagedReferenceType ( ) ;
100
+ Type type = ManagedReferenceUtility . GetType ( managedReferenceFullTypename ) ;
96
101
string typeName = null ;
97
102
98
103
AddTypeMenuAttribute typeMenu = TypeMenuUtility . GetAttribute ( type ) ;
@@ -108,7 +113,7 @@ GUIContent GetTypeName (SerializedProperty property) {
108
113
}
109
114
110
115
GUIContent result = new GUIContent ( typeName ) ;
111
- m_TypeNameCaches . Add ( property . managedReferenceFullTypename , result ) ;
116
+ m_TypeNameCaches . Add ( managedReferenceFullTypename , result ) ;
112
117
return result ;
113
118
}
114
119
0 commit comments