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

[feature request] EditorButton directly on methods #28

Open
cspotcode opened this issue Nov 24, 2021 · 3 comments
Open

[feature request] EditorButton directly on methods #28

cspotcode opened this issue Nov 24, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@cspotcode
Copy link

The EditorButton example shows placing a button before a field by annotating the field.
https://github.com/arimger/Unity-Editor-Toolbox#toolboxdecoratorattributes

Is there any way to place an attribute directly on a method? Similar to https://dbrizov.github.io/na-docs/attributes/drawer_attributes/button.html

I checked the code for these solutions. They appear to use reflection in their CustomEditor(typeof(Object)... implementations to query for all annotated methods.

@arimger
Copy link
Owner

arimger commented Nov 24, 2021

Unfortunately not yet.

I wanted to avoid using non-field attributes to keep everything consistent, and I liked that the current approach gives a great possibility to place Buttons directly in the desired area. A similar case refers to Foldout(Group) functionality, this can't be implemented without treating the target object as a whole, not only single, independent properties.

I have a few ideas on how to achieve it in a pretty neat way but can't promise when this will be implemented.

Thank you for the request :)

@arimger arimger added the enhancement New feature or request label Nov 24, 2021
@cspotcode
Copy link
Author

True, the other solutions only support buttons at the top and bottom of the inspector, not in the middle.

When you need a "dummy" field to put decorators on, what do you use? Just an int and accept that the class will take a tiny bit more memory to store that useless int?

@arimger
Copy link
Owner

arimger commented Nov 24, 2021

To be honest, I never had such a problem. If this particular component/ScriptableObject has non-serialized instance fields probably I would make something like this:

[SerializeField, Hide]
[EditorButton(nameof(MyMethod))]
private int myField;

I agree it takes a little bit of memory and in fact, it's redundant, additionally, it may be misleading for other programmers.
I think the best option is to implement a custom Editor. I know this package is created to avoid custom Editors but unfortunately, there is no clean way to do this right now.

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

No branches or pull requests

2 participants