@@ -29,20 +29,19 @@ public TypePopupCache (AdvancedTypePopup typePopup,AdvancedDropdownState state)
2929 readonly Dictionary < string , GUIContent > m_TypeNameCaches = new Dictionary < string , GUIContent > ( ) ;
3030
3131 SerializedProperty m_TargetProperty ;
32-
32+
3333 public override void OnGUI ( Rect position , SerializedProperty property , GUIContent label ) {
3434 EditorGUI . BeginProperty ( position , label , property ) ;
3535
3636 if ( property . propertyType == SerializedPropertyType . ManagedReference ) {
37- TypePopupCache popup = GetTypePopup ( property ) ;
38-
3937 // Draw the subclass selector popup.
4038 Rect popupPosition = new Rect ( position ) ;
4139 popupPosition . width -= EditorGUIUtility . labelWidth ;
4240 popupPosition . x += EditorGUIUtility . labelWidth ;
4341 popupPosition . height = EditorGUIUtility . singleLineHeight ;
4442
4543 if ( EditorGUI . DropdownButton ( popupPosition , GetTypeName ( property ) , FocusType . Keyboard ) ) {
44+ TypePopupCache popup = GetTypePopup ( property ) ;
4645 m_TargetProperty = property ;
4746 popup . TypePopup . Show ( popupPosition ) ;
4847 }
@@ -57,10 +56,13 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
5756 }
5857
5958 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 ;
6261
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 ) ;
6466 var popup = new AdvancedTypePopup (
6567 TypeCache . GetTypesDerivedFrom ( baseType ) . Where ( p =>
6668 ( p . IsPublic || p . IsNestedPublic ) &&
@@ -79,20 +81,23 @@ TypePopupCache GetTypePopup (SerializedProperty property) {
7981 m_TargetProperty . serializedObject . ApplyModifiedProperties ( ) ;
8082 } ;
8183
82- m_TypePopups . Add ( property . managedReferenceFieldTypename , new TypePopupCache ( popup , state ) ) ;
84+ m_TypePopups . Add ( managedReferenceFieldTypename , new TypePopupCache ( popup , state ) ) ;
8385 }
8486 return result ;
8587 }
8688
8789 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 ) ) {
8994 return k_NullDisplayName ;
9095 }
91- if ( m_TypeNameCaches . TryGetValue ( property . managedReferenceFullTypename , out GUIContent cachedTypeName ) ) {
96+ if ( m_TypeNameCaches . TryGetValue ( managedReferenceFullTypename , out GUIContent cachedTypeName ) ) {
9297 return cachedTypeName ;
9398 }
9499
95- Type type = property . GetManagedReferenceType ( ) ;
100+ Type type = ManagedReferenceUtility . GetType ( managedReferenceFullTypename ) ;
96101 string typeName = null ;
97102
98103 AddTypeMenuAttribute typeMenu = TypeMenuUtility . GetAttribute ( type ) ;
@@ -108,7 +113,7 @@ GUIContent GetTypeName (SerializedProperty property) {
108113 }
109114
110115 GUIContent result = new GUIContent ( typeName ) ;
111- m_TypeNameCaches . Add ( property . managedReferenceFullTypename , result ) ;
116+ m_TypeNameCaches . Add ( managedReferenceFullTypename , result ) ;
112117 return result ;
113118 }
114119
0 commit comments