Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ContextMenu] to inspector button #51

Open
fight4dream opened this issue Oct 25, 2019 · 2 comments
Open

[ContextMenu] to inspector button #51

fight4dream opened this issue Oct 25, 2019 · 2 comments

Comments

@fight4dream
Copy link

fight4dream commented Oct 25, 2019

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
Copy link
Member

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
Copy link
Contributor

bddckr commented Nov 10, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants