简体   繁体   English

Unity Inspector 绘制不同名称的 arrays

[英]Unity Inspector draw arrays with different names

It's possible to draw a serialized array in Inspector with custom name from it's property ("name")?可以在 Inspector 中使用其属性(“名称”)中的自定义名称绘制序列化数组吗? (that will still have the expand triangle) (仍然会有扩展三角形)

So instead of所以而不是

-> Element 0 -> 元素 0

-> Element 1 -> 元素 1

it will be这将是

-> Persons -> 人

-> Cars -> 汽车

having the classes like this:有这样的课程:

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

PS I'm going through each element with GetArrayElementAtIndex and draw individually PS 我正在使用 GetArrayElementAtIndex 遍历每个元素并单独绘制

Found it:找到了:

For each item in GetArrayElementAtIndex draw it with:对于 GetArrayElementAtIndex 中的每个项目,使用:

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

where the "New Title" can be a property of current SerializedProperty which ca be got with property.stringValue其中“新标题”可以是当前 SerializedProperty 的属性,可以通过 property.stringValue 获得

example:例子:

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