Button editor inheritance

Rather simple question I cannot for the life of me find the answer to. I am trying to make a button where you can hold down the button to sell multiple (for an in-game shop). I have found out that I should be using UnityEditor.UI.ButtonEditor to inherit from and I found this on this post here: Subclassing Button, public variable won't show up in the inspector - Questions & Answers - Unity Discussions. I have also checked the documentation and I cant figure out what is wrong.

I am aware there are 3 posts about this from 2017 on Unity Answers but the answer does not work for me. In case it would matter I am on version 2019.1.0f1.

using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[RequireComponent(typeof(Image))]
public class HeldButton : Button
{
    [SerializeField] private UnityEvent _onHold;
}

#if UNITY_EDITOR
[CustomEditor(typeof(HeldButton))]
public class HelldButtonEditor : //WHAT GOES HERE
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        GUILayout.Label("string");
    }
}
#endif

ButtonEditor goes there.

Hmm it doesnt seem to allow me to put that in there sadly… But I did find out it does work when it is in a separate file.

Correct. Unity requires that Editor and MonoBehaviour classes are in their own files with a matching file name.

1 Like

I must have had that wrong than. Thx for the help, I assumed it was something simple but didnt see the exact cause.