1

I have implemented a button on my own, which inherits from UnityEngine.UI.Button, and it has its own custom inspector.

public class TwoStateButton : Button
{
    ...
}

[CustomEditor(typeof(TwoStateButton))]
public class TwoStateButtonEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
    }

    ...
}

I have an issue where the behaviour of the Transition mode settings in the Button inspector is not working properly for my class TwoStateButton as long as I have a custom editor.

The Button inspector looks like this, and so does the TwoStateButton inspector if I delete or comment out the custom editor class.

But my custom inspector looks like this, despite me not making any changes to the inspector.

So basically, the behaviour with what fields are visible changes depending on the Transition mode is lost, and all settings are always shown.

I have tried exchanging base.OnInspectorGUI(); with DrawDefaultInspector(); but it had no effect. I have tried importing the UnityEditor.UI library and making my TwoStateButtonEditor inherit from ButtonEditor instead of Editor, but it had no effect.

Is there a way to make a custom editor, but still keep the Transition mode settings behaviour?

2 Answers 2

1

The reason your editor doesn't look like Button's editor is because you are creating a new custom editor rather than extending from the custom Button editor. If you did that, you would get the behavior you want. You can also copy Button's custom editor and change it for your needs.

Button Editor extends from Selectable Editor

Sign up to request clarification or add additional context in comments.

2 Comments

I did try that before, and as described, that had no effect. But I must have done something wrong, because that did now solve my problem. Thank you!
What I did wrong was most probably that I inherited ButtonEditor, but called DrawDefaultInspector() instead of base.OnInspectorGUI(), if anyone has that problem.
0

you can do that by checking the Transition mode in the OnInspectorGui method.

something like:

[CustomEditor(typeof(TwoStateButton))]
public class TwoStateButtonEditor : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        switch(target.transitionMode)
        {
            case Automatic:
                //Automatic code
                [...]
                break;
            case ColorTint:
                //Color Tint code
                [...]
                break;
            default:
                break;
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.