Custom Editor for interfaces

Hi guys
I’ve problem with custom editor for enemies.
In IEnemy interface I have two methods: “Attack” and “Die”.
So I made IEnemyEditor script and on the top I wrote this:[CustomEditor(typeof(IEnemy), true)].
In IEnemyEditor i’d like to have two buttons called “Attack Player” and “Die”, which execute before mentioned methods Attack.
I’ve few enemies which inherits from IEnemy interface and when i click on object with that enemy script it should show these two buttons, but it don’t.
Do you have any ideas how to fix that ?
.
IEnemy:

public interface IEnemy
{
    void Attack();
    void Die();
}

.
IEnemyEditor:

[CustomEditor(typeof(IEnemy), true)]
public class IEnemyEditor : Editor
{
    private IEnemy enemy;

    public override void OnInspectorGUI()
    {
        if (!Application.isPlaying)
            return;

        if (enemy == null)
            enemy = (IEnemy) target;
        
        DrawInGameOptions();
    }

    private void DrawInGameOptions()
    {
        EditorGUILayout.LabelField("In Game Options", EditorStyles.centeredGreyMiniLabel);
        
        if (GUILayout.Button("Attack Player"))
            enemy.Attack();
        
        if (GUILayout.Button("Die"))
            enemy.Die();
    }
}

.
Enemy (Spider):

public class Spider : MonoBehaviour, IEnemy
{
    public void Attack()
    {

    }

    public void Die()
    {

    }
}

You should not be able to build a custom inspector for classes that do not inherit from MonoBehaviour.
Your interfaces and your spider class do not inherit from MonoBehaviour, and there for are not considered a ‘Component’. That means they should never show in the inspector. That is why you cannot customize it.



Text From Link:

When you create a script in Unity, by default it inherits from MonoBehaviour, and therefore is a Component which can be placed on a game object. When placed on a game object, the Inspector displays a default interface for viewing and editing all public variables that can be shown - such as integers, floats, strings, Vector3’s, etc
.

I’ve encountered a simillar issue, but I don’t think it has a nice, clean solution. The way I usually solve this issue is to create a common, abstract base class for some classes of same type (in your code sample it would be something like “NPC class” or “BaseEnemy class”) and then check for interface in a common editor class.

Drawback is that this might violate composition over inheritance principle.

I was able to accomplish this by creating an empty MonoBehaviour (no interface) which is targeted by the Editor Extension. Then I auto-assign that empty script to every GameObject that I want my button on, by having the RequireComponent annotation on a base MonoBehaviour which all of my interface implementers inherit from.

It’s a workaround that requires a couple extra steps, but it works very well. And then I just call target.GetComponent() within my button code to perform whatever action I need.