【问题标题】:Unity Inspector draw arrays with different namesUnity Inspector 绘制具有不同名称的数组
【发布时间】:2020-10-24 15:30:32
【问题描述】:

是否可以在 Inspector 中使用其属性(“名称”)中的自定义名称绘制序列化数组? (仍然会有展开三角形)

所以不是

-> 元素 0

-> 元素 1

会的

-> 人

-> 汽车

有这样的类:

[Serializable]
public class Group {
   public string name;
   public Vector3 someVec;
}
public List <Group> m_Groups; // Drawing groups in the inspector

附:我正在使用 GetArrayElementAtIndex 遍历每个元素并单独绘制

【问题讨论】:

    标签: c# unity3d inspector


    【解决方案1】:

    找到了:

    为 GetArrayElementAtIndex 中的每个项目绘制它:

    EditorGUILayout.PropertyField(item, new GUIContent() { text = "New Title" });

    “新标题”可以是当前 SerializedProperty 的一个属性,可以通过 property.stringValue 获得

    示例:

    for (int i = 0; i < list.arraySize; i++)
    {
        SerializedProperty group = list.GetArrayElementAtIndex(i);
        SerializedProperty name = group.FindPropertyRelative("name");
        EditorGUILayout.PropertyField(group, new GUIContent() { text = name.stringValue });
        // Draw the subproperties...
    }
    

    【讨论】:

      猜你喜欢
      • 2018-11-26
      • 2022-01-08
      • 2015-08-18
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多