Hey, to do this, you need to have a custom property drawer for your name class, and be sure the name class is marked as serializable.
Here’s the code for your MonoBehaviour and Name class (changed a little) :
[System.Serializable]
public class Name : System.Object
{
public string firstName, lastName;
}
using UnityEngine;
public class NameList : MonoBehaviour
{
public Name[] names;
}
And there’s the code of the property drawer, which must be inside a folder named ‘Editor’ :
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(Name))]
public class NameDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Using BeginProperty / EndProperty on the parent property means that
// prefab override logic works on the entire property.
EditorGUI.BeginProperty(position, label, property);
// Calculate rects
Rect firstNameRect = new Rect(position.x, position.y, position.width / 2 - 10, position.height);
Rect lastNameRect = new Rect(position.x + position.width / 2, position.y, position.width / 2 - 10, position.height);
// Draw fields - passs GUIContent.none to each so they are drawn without labels
EditorGUI.PropertyField(firstNameRect, property.FindPropertyRelative("firstName"), GUIContent.none);
EditorGUI.PropertyField(lastNameRect, property.FindPropertyRelative("lastName"), GUIContent.none);
EditorGUI.EndProperty();
}
}
The only problem there is that, if you have a name alone in a monoBehaviour, you won’t see the variable name, which can be problematic, but you can change it.