简体   繁体   中英

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")? (that will still have the expand triangle)

So instead of

-> Element 0

-> Element 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

Found it:

For each item in GetArrayElementAtIndex draw it with:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM