@@ -11,7 +11,7 @@ namespace Toolbox.Editor.Drawers
1111 [ CustomPropertyDrawer ( typeof ( SerializedType ) ) ]
1212 public sealed class SerializedTypeDrawer : PropertyDrawerBase
1313 {
14- private static readonly TypeConstraintStandard sharedConstraint = new TypeConstraintStandard ( ) ;
14+ private static readonly TypeConstraintContext sharedConstraint = new TypeConstraintStandard ( ) ;
1515 private static readonly TypeAppearanceContext sharedAppearance = new TypeAppearanceContext ( sharedConstraint , TypeGrouping . None , true ) ;
1616 private static readonly TypeField typeField = new TypeField ( sharedConstraint , sharedAppearance ) ;
1717
@@ -51,9 +51,12 @@ private TypeConstraintAttribute GetDefaultConstraint()
5151 private void UpdateConstraint ( TypeConstraintAttribute attribute )
5252 {
5353 sharedConstraint . ApplyTarget ( attribute . AssemblyType ) ;
54- sharedConstraint . AllowAbstract = attribute . AllowAbstract ;
55- sharedConstraint . AllowObsolete = attribute . AllowObsolete ;
56- sharedConstraint . Settings = attribute . TypeSettings ;
54+ if ( sharedConstraint is TypeConstraintStandard constraint )
55+ {
56+ constraint . AllowAbstract = attribute . AllowAbstract ;
57+ constraint . AllowObsolete = attribute . AllowObsolete ;
58+ constraint . Settings = attribute . TypeSettings ;
59+ }
5760 }
5861
5962 private void UpdateAppearance ( TypeConstraintAttribute attribute )
@@ -69,8 +72,6 @@ protected override float GetPropertyHeightSafe(SerializedProperty property, GUIC
6972
7073 protected override void OnGUISafe ( Rect position , SerializedProperty property , GUIContent label )
7174 {
72- var referenceProperty = property . FindPropertyRelative ( "typeReference" ) ;
73-
7475 label = EditorGUI . BeginProperty ( position , label , property ) ;
7576 label = property . name != "data" ? label : GUIContent . none ;
7677 position = EditorGUI . PrefixLabel ( position , label ) ;
@@ -79,14 +80,22 @@ protected override void OnGUISafe(Rect position, SerializedProperty property, GU
7980 var addSearchField = validAttribute . AddTextSearchField ;
8081 UpdateConstraint ( validAttribute ) ;
8182 UpdateAppearance ( validAttribute ) ;
82- typeField . OnSelect = ( type ) =>
83- {
84- referenceProperty . serializedObject . Update ( ) ;
85- referenceProperty . stringValue = SerializedType . GetReferenceValue ( type ) ;
86- referenceProperty . serializedObject . ApplyModifiedProperties ( ) ;
87- } ;
83+
84+ var referenceProperty = property . FindPropertyRelative ( "typeReference" ) ;
8885 var activeType = SerializedType . GetReferenceType ( referenceProperty . stringValue ) ;
89- typeField . OnGui ( position , addSearchField , activeType ) ;
86+ typeField . OnGui ( position , addSearchField , ( type ) =>
87+ {
88+ try
89+ {
90+ referenceProperty . serializedObject . Update ( ) ;
91+ referenceProperty . stringValue = SerializedType . GetReferenceValue ( type ) ;
92+ referenceProperty . serializedObject . ApplyModifiedProperties ( ) ;
93+ }
94+ catch ( Exception e ) when ( e is ArgumentNullException || e is NullReferenceException )
95+ {
96+ ToolboxEditorLog . LogWarning ( "Invalid attempt to update disposed property." ) ;
97+ }
98+ } , activeType ) ;
9099
91100 EditorGUI . EndProperty ( ) ;
92101 }
0 commit comments