@@ -13,9 +13,8 @@ public class ReferencePickerAttributeDrawer : ToolboxSelfPropertyDrawer<Referenc
1313 private readonly TypeField typeField = new TypeField ( new TypeConstraintReference ( null ) ) ;
1414
1515
16- private void CreateTypeProperty ( SerializedProperty property )
16+ private void CreateTypeProperty ( SerializedProperty property , Type parentType )
1717 {
18- property . GetFieldInfo ( out Type propertyType ) ;
1918 TypeUtilities . TryGetTypeFromManagedReferenceFullTypeName ( property . managedReferenceFullTypename , out var currentType ) ;
2019 var position = EditorGUILayout . GetControlRect ( false , EditorGUIUtility . singleLineHeight ) ;
2120 position = EditorGUI . IndentedRect ( position ) ;
@@ -44,7 +43,7 @@ private void CreateTypeProperty(SerializedProperty property)
4443 {
4544 ToolboxEditorLog . LogWarning ( "Invalid attempt to update disposed property." ) ;
4645 }
47- } , currentType , propertyType ) ;
46+ } , currentType , parentType ) ;
4847 }
4948
5049 private void UpdateTypeProperty ( SerializedProperty property , Type referenceType )
@@ -55,6 +54,24 @@ private void UpdateTypeProperty(SerializedProperty property, Type referenceType)
5554 property . serializedObject . ApplyModifiedProperties ( ) ;
5655 }
5756
57+ private Type GetParentType ( SerializedProperty property , ReferencePickerAttribute attribute )
58+ {
59+ property . GetFieldInfo ( out Type propertyType ) ;
60+ var candidateType = attribute . ParentType ;
61+ if ( candidateType != null )
62+ {
63+ if ( propertyType . IsAssignableFrom ( candidateType ) )
64+ {
65+ return candidateType ;
66+ }
67+
68+ ToolboxEditorLog . AttributeUsageWarning ( attribute , property ,
69+ $ "Provided { nameof ( attribute . ParentType ) } ({ candidateType } ) cannot be used because it's not assignable from: '{ propertyType } '") ;
70+ }
71+
72+ return propertyType ;
73+ }
74+
5875
5976 protected override void OnGuiSafe ( SerializedProperty property , GUIContent label , ReferencePickerAttribute attribute )
6077 {
@@ -66,7 +83,8 @@ protected override void OnGuiSafe(SerializedProperty property, GUIContent label,
6683 }
6784
6885 EditorGUI . indentLevel ++ ;
69- CreateTypeProperty ( property ) ;
86+ var parentType = GetParentType ( property , attribute ) ;
87+ CreateTypeProperty ( property , parentType ) ;
7088 ToolboxEditorGui . DrawPropertyChildren ( property ) ;
7189 EditorGUI . indentLevel -- ;
7290 }
0 commit comments