Custom inspector for simple class

I have a class that extends monobehaviou like this:

public class NameList : MonoBehaviour {
       public Name[] list;
       //start, update, etc...
}

and I want NameList’s inspector to show the Name array beautifully. This is what Name looks like:

public class Name {
       public string first_name, last_name;
       //constructor definition
}

I’d like the Inspector to be something like this (similar to arrays, but with 2 text fields showing the strings):

first_name        last_name
[ Ronald     ]    [ Donald     ]
[ Mickey     ]    [ DaRat      ]
...

How can I do it? I tried to use UnityEditor namespace and everything but after lots of tries I deleted because of errors.

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.

Here’s a good tutorial about this : Unity - Manual: Property Drawers