检视面板中多态类型显示空白问题求助
检视面板多态类型字段显示空白问题
开发中遇到Unity检视面板(Inspector)里多态类型显示空白的问题,涉事代码量较大已上传至GitHub。具体现象:
- 展开
NamePart字段时,主字段名称变更,下拉框与字段间、字段后出现空行,但NamePart的子字段完全不显示; FamilyNames字段显示正常。
已检查属性抽屉(Property Drawer)配置及字段序列化,未发现明显问题,但仍无法定位成因和修复方案。以下是相关代码片段:
名称生成器属性抽屉代码
protected override void DrawProperty ( Rect position, SerializedProperty property, GUIContent label, bool isPolymorphic ) { EditorGUI.BeginProperty ( position, label, property ); Rect pos = new ( position.x, position.y, position.width, EditorGUI.GetPropertyHeight ( property.FindPropertyRelative ( "m_Feminine" ) ) ); EditorGUI.PropertyField ( pos, property.FindPropertyRelative ( "m_Feminine" )); pos.y += pos.height + EditorGUIUtility.standardVerticalSpacing; pos.height = EditorGUI.GetPropertyHeight ( property.FindPropertyRelative ( "m_Masculine" ) ); EditorGUI.PropertyField ( pos, property.FindPropertyRelative ( "m_Masculine" )); pos.y += pos.height + EditorGUIUtility.standardVerticalSpacing; pos.height = EditorGUI.GetPropertyHeight ( property.FindPropertyRelative ( "m_Neutral" ) ); EditorGUI.PropertyField ( pos, property.FindPropertyRelative ( "m_Neutral" )); pos.y += pos.height + EditorGUIUtility.standardVerticalSpacing; pos.height = EditorGUI.GetPropertyHeight ( property.FindPropertyRelative ( "m_FamilyNames" ) ); EditorGUI.PropertyField ( pos, property.FindPropertyRelative ( "m_FamilyNames" ) ); EditorGUI.EndProperty (); }
多态属性抽屉代码
public sealed override void OnGUI ( Rect position, SerializedProperty property, GUIContent label ) { // ... if (reference != null && propertyHeight > 0) { property.isExpanded = EditorGUI.Foldout ( labelRect, property.isExpanded, property.displayName, true ); } else { EditorGUI.LabelField ( labelRect, label ); } }
内容的提问来源于stack exchange,提问作者RWolfe
相关产品推荐
相关产品推荐

