- Home /
Is it possible to draw more than one property attribute on a field?
So I'm writing a full set of property drawers when I noticed that if I use more than one attribute on a field, only the last attribute will get drawn.
I want both the comment and the foldout to appear. Is multiple attributes drawing supported? - If so, any idea how to achieve it?
I'm not looking for work-arounds, I could easily write a ShowTransformWithComment
Thanks.
Could you post your AtttributeEditor scripts? I would get a better idea of what's going on
Answer by vexe · Jun 05, 2014 at 11:29 AM
Turns out it is possible. I'm not sure if it was previously there in Unity 4.3 but I just found out about the order property that's in PropertyAttribute
. So now you can composite/decorate attributes like:
[Comment("This is a comment"), order = 0]
[ShowTransform, order = 1]
public Transform t;
Just make sure the order makes sense.
Also worth mentioning that Unity changed the way they deal with properties internally. They now have a PropertyHandler
from which PropertyDrawer
and PropertyDecorator
inherit from. I'm happy Unity did something right and implemented composition.
Nice thanks for that, also didn't know that DecoratorDrawer exist. $$anonymous$$inor corrections:
[Comment("This is a comment", order = 0)]
[ShowTransform(order = 1)]
and name of the class DecoratorDrawer
. Yet this still doesn't allow me to add multiple PropertyDrawer
s to one field? Sooo close
It seems to work well with DecoratorDrawer, but is there a method to make it work with PropertyDrawer?
I've made a drawer for $$anonymous$$atrix4x4 to draw it in a 4x4 float fields, and I've a [ReadOnly] drawer to make fields read-only;
When I add a [ReadOnly] on a $$anonymous$$atrix4x4 field, the readonly works, but the custom & native $$anonymous$$atrix4x4 drawers both malfunction.
I ran into the same problem with you. I got a simple class with 2 field, use custom property drawer, and a custom attribute to disable a field if there is no match required-component. Did anyone solved this problem?
Your answer
Follow this Question
Related Questions
Losing Class References 0 Answers
Property Drawer and Inheritance 0 Answers
Custom property drawer for generic 0 Answers
ScriptableObject PropertyDrawer ArgumentOutOfRange Exception 0 Answers