Custom UnityEngine.UI button inspector
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?
Answer by Adam-Mechtley · Feb 21, 2017 at 01:18 PM
Hi! Please see my answer here. Your custom editor needs to subclass ButtonEditor, not Editor.
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!
$$anonymous$$y guess is you had inherited ButtonEditor, but called DrawDefaultInspector() ins$$anonymous$$d of base.OnInspectorGUI() (as in the thread I linked).