gasgiant / Markup-Attributes

A Unity Editor extension for customizing inspector layout with attributes.
MIT License
289 stars 11 forks source link

[REQUEST] Put MarkedUpField-attribute on class instead of field? #6

Closed Whyser closed 2 years ago

Whyser commented 2 years ago

Hey, first of all, amazing lib @gasgiant !

I'm wondering if you could add "MarkedUpClass" (like MarkedUpField but for classes)? This is so that the same class be reused in multiple places without having to specify the MarkedUpField-attribute every time - as this would cause issues for co-developers not knowing that MarkedUpField has to be added (and exactly which parameters are needed). Something like this:

[MarkedUpClass]
public class TestClass
{
    public string message = "hello world";
}

I've implemented it and it works, but I think you could implement it a bit prettier than my first attempt. :P

You could also implement it quite easily if you just changed MarkedUpFieldAttribute to allow targeting classes/structs and after that change one line of code:

var markedUp = fieldInfo.GetCustomAttribute<MarkedUpFieldAttribute>(); would become:

 var markedUp = fieldInfo.FieldType.GetCustomAttribute<MarkedUpFieldAttribute>(true); //here we look class-level attributes
if(markedUp == null) //if that is null, we instead look at field-level attributes
   markedUp = fieldInfo.GetCustomAttribute<MarkedUpFieldAttribute>();
gasgiant commented 2 years ago

Hi! I think it's a good idea. Honestly, not sure why I didn't do it this way in the first place. I'll implement this next time I have bit of free time.

gasgiant commented 2 years ago

Added MarkedUpType in 0.5.0.