I created an extension of the build-in Button class works great except
I cannot see the variables from the extension class in inspector - only in Debug mode.
Any Idea how to see those fields?
I solved it by not extending the Button class which is already extended.
instead of extending the classes Selectable, IPointerClickHandler, ISubmitHandler
And copy code from Button.cs class to my custom class ButtonExtended
public class ButtonExtended : Selectable, IPointerClickHandler, ISubmitHandler
[Serializable]
/// <summary>
/// Function definition for a button click event.
/// </summary>
public class ButtonClickedEvent : UnityEvent {}
// Event delegates triggered on click.
[FormerlySerializedAs("onClick")]
[SerializeField]
private ButtonClickedEvent m_OnClick = new ButtonClickedEvent();
...
You can extend the Button class just fine. However the Button class comes with its own custom editor that is marked to be used by inherited classes as well. So it of course does not cover your new variables. However you can extend the ButtonEditor yourself and make a new one in a similar fashion and just add your fields at the end.
Extending the Button class has several advantages. Any other code that interacts with UI buttons would still work. While your custom button class does do the same things, it’s not the same class and can not be treated as such. Just as an example my WaitForUIButtons yield instructions for use in a coroutine would still work with an extended class, but not with your custom class. I’ve made this for this old question.