ExtendRealityLtd / Malimbe

[Obsolete - No longer maintained] A collection of tools to simplify writing public API components for the Unity software.
MIT License
51 stars 11 forks source link

[ContextMenu] to inspector button #51

Open fight4dream opened 5 years ago

fight4dream commented 5 years ago

Feature request

draw a button for method decorated with [ContextMenu]

Example

The following would draw a button with face text “Do transform”. When pressed it will call DoTransform(). If its validating method returns false, the button is greyed out and not interactable.

[ContextMenu(“Do transform”)]
public void DoTransform()
{
    // ...
}

[ContextMenu(“Do transform”, validate: true)]
private bool IsPlaying()
{
    return Application.isPlaying;
}
thestonefox commented 5 years ago

I don't like this idea. I feel it is peppering the scripts with unnecessary helpers.

Perhaps there's some other clever way of doing this though? some sort of editor script that you whack a monobehaviour onto, it uses reflection to show all public void methods and gives you a button for each one?

bddckr commented 5 years ago

Yeah that should be possibly via reflection. And I agree, it should be done via another script, one that is editor-only. This will ensure the concerns are separated more easily and by implementing it generically via reflection one allows anything to be called. If there's the need to restrict the methods or offer the predicate feature shown off in the original post, then I'd say it might be possible still - but I'd do so by writing an editor script that is specifically for the type I'm adjusting.