You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

检视面板中多态类型显示空白问题求助

检视面板多态类型字段显示空白问题

开发中遇到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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 16:47:05