簡體   English   中英

Unity Inspector 繪制不同名稱的 arrays

[英]Unity Inspector draw arrays with different names

可以在 Inspector 中使用其屬性(“名稱”)中的自定義名稱繪制序列化數組嗎? (仍然會有擴展三角形)

所以而不是

-> 元素 0

-> 元素 1

這將是

-> 人

-> 汽車

有這樣的課程:

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

PS 我正在使用 GetArrayElementAtIndex 遍歷每個元素並單獨繪制

找到了:

對於 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...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM