Add option to set default buttonstyle for methods with parameters
The default buttonstyle currently is CompactBox, according to the docs, but I don’t really like the look of that one, so I often add ButtonStyle.FoldoutButton to my Button attributes. But now my code is full with [Button(ButtonStyle.FoldoutButton)]
instead of a cleaner [Button]
. It would be great if there was a global preference setting to set the default, like the many options under the general tab of the odin preferences.
Comments (7)
-
-
reporter That’s a good suggestion, I didn’t know about those. But when I try your code it gives me a compile error: Button is valid on Method declarations only.
-
I think this should work from version 3.0.6.0 and up so if you’re below that, that might be the problem.
-
reporter I am on version 3.0.5.0 so that explains it.
-
In that case, if you want/need to stay at 3.0.5.0 you could also make use of Odin’s attribute processors which should be available starting with version 2.0.0.0.
They require a bit more boilerplate code though:using Sirenix.OdinInspector; using Sirenix.OdinInspector.Editor; using System; using System.Collections.Generic; using System.Reflection; public class FoldoutButtonAttribute : Attribute { } public class FoldoutButtonAttributeProcessor : OdinAttributeProcessor { public override bool CanProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member) { return member.GetCustomAttribute<FoldoutButtonAttribute>() != null; } public override void ProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member, List<Attribute> attributes) { attributes.Add(new ButtonAttribute(ButtonStyle.FoldoutButton)); } }
Ultimately, I think that expanding the preferences window to have more Configurability for cases like this would be a good step to improve readability by removing extra boilerplate code, but this will probably be a long process. In the meantime, using one of the 2 provided alternative ways should help bridge that time.
-
reporter I updated to the latest version, so the first way works now. But it’s nice that there are more options!
This issue is solved for me. So you can mark it as resolved, unless you want to keep it open as a reminder to add the configurability later. Thanks for your help!
-
- changed status to resolved
- Log in to comment
You could use Odin’s composite attributes feature which makes this sort of specialized attribute usage very easy.