How can I override the default inspector editor with my own?

Hello everybody.
I try to create a custom editor, which should replace the old one (from unity). My target is to allow the programmer to define the design of the editor just with attributes at the properties in the script.

For that I want to override the default inspector editor, so that my new one is always used.

My question:
How can I achieve that my editor is used for default?
I don’t want to use:

[CustomEditor(typeof(MyClass))]

Because then I would need to create a copy of this editor script for each script…

Greetings
Chillersanim

Not sure if this feature existed when this question was asked, but the CustomEditor attribute also takes a second boolean paramater to allow your editor to be applied to child classes too.

If you wanted to add something to every editor you could in fact use:

[CustomEditor(typeof(MonoBehaviour), true)]

If all of your scripts derive from the same base class, you can put the code in a custom inspector for the base class. Then each subclass can just inherit this.

For example, say you have these scripts:

public class NPC : MonoBehaviour {
    public string title;
}

public class Friend : NPC {
}

public class Neutral: NPC {
}

public class Enemy : NPC {
    public bool aggressive;
}

Then you could have these custom inspector classes:

[CustomEditor(typeof(NPC))] 
public class NPCEditor : Editor {

    public override void OnInspectorGUI() {
        title = EditorGUILayout.TextField("Title", title);
    }

}

[CustomEditor(typeof(Friend))]
public class FriendEditor : NPCEditor {}

[CustomEditor(typeof(Neutral))]
public class NeutralEditor : NPCEditor {}

[CustomEditor(typeof(Enemy))]
public class EnemyEditor : NPCEditor {

    public override void OnInspectorGUI() {
        base.OnInspectorGUI();
        // Add another property to inspector:
        aggressive = EditorGUILayout.Toggle("Aggressive", aggressive);
    }

}

You might actually be interested in Property Drawers. They help to customize the inspector window based on attributes on your public properties.