Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by IpuBlue · Feb 23, 2021 at 02:23 PM · guiinspectorpropertydrawerattribute

Drawing Order of DecoratorDrawer doesn't work?

Hi! I have a question about drawing order of Decorator drawer.

I've created custom PropertyAttribute and DecoratorDrawer.

DecoratorDrawer has "order" property that is used for drawing order when there are multiple DecoratorDrawer in the same field.

However, it doesn't seem to work. When there are two DecoratorDrawer "Header" and "Customed Attribute" and set them order properly, but Header priority is always highest. (Same problem is occurred "Header" and "Space")

Sample code is below.

 public class URLAttribute : PropertyAttribute
 {
     public string m_text = string.Empty;
     public string m_url = string.Empty;
 
     public URLAttribute(string text, string url)
     {
         m_text = text;
         m_url = url;
     }
 }
 
 [CustomPropertyDrawer(typeof(URLAttribute))]
 public class PropertyDrawerURL : DecoratorDrawer
 {
     Texture m_icon = EditorGUIUtility.IconContent("_Help").image;
 
     public override void OnGUI(Rect position)
     {
         URLAttribute attr = (URLAttribute)attribute;
 
         GUIStyle style = new GUIStyle(EditorStyles.miniButton);
         style.imagePosition = ImagePosition.ImageLeft;
         style.fixedWidth = 128;
         style.fixedHeight = 24;
         style.richText = true;
         string text = attr.m_text;
         text = $"<color=#80ffffff>{text}</color>";
         GUIContent content = new GUIContent(text, m_icon, attr.m_url);
         if (GUI.Button(position, content, style))
         {
             Application.OpenURL(attr.m_url);
         }
     }
 }
 
 public class Test : MonoBehaviour
 {
     [URL("Open help", "https://xxxxxxx", order = 0)] 
     [Header("Category0", order = 1)]
     [SerializeField]
     GameObject m_object = null;

     // some code
 }

Please teach me how to solve this problem. And I'm sorry that I'm not good at English.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Feb 23, 2021 at 04:41 PM

I just copied your example into my test project and it works just as it should. Though your fixed height of 24 is more than the designated line height that is used by Unity by default (which is 16 afaik). Therefore the button may overlap with other things below it. So you may want to include the GetHeight method to specify how much height your drawer needs:

 public override float GetHeight()
 {
     return 24f;
 }

With that I get those results:

decorator drawer image

The first one has the header with a lower order value, the second one has our own URL attribute with the lower order. As you can see it works just as it should.


Note that the header attribute automatically adds some padding above. Since a header is supposed to create a new section it adds some spacing above to seperate it from what comes before. That's why in the second case there's more space between our button and the header.


So the result is: I can't really reproduce your issue. I tested this in Unity "2020.2.3f1".


decoratordrawerresult.png (7.5 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Feb 23, 2021 at 04:57 PM 0
Share

Note if you want to get rid of that spacing I mentioned, you may want to create a combined "Header with help URL" decorator. That way you could even move the help button to the right and keep the header text on the left side. This may be more convenient. in some cases. The drawer could be flexible enough to ignore the header title if it's empty and behave differently.

avatar image IpuBlue · Feb 24, 2021 at 05:47 AM 0
Share

@Bunny83 Thank you for your reply!! I think the way you pointed out about height is correct. And GetHeight() method works properly.

But order property of AttributeProperty doesn't work. Always the result is same as first screenshot you attached.

I guess the deference between yours and $$anonymous$$e is caused by Unity version. I use Unity "2019.4.16f1".

Now, I belong to the project using Unity "2019.4.16f1". And it is difficult to upgrade the version. So I'll not use multiple DecoderDrawer in same field until our team upgrade new Unity version...

I really appreciate your good useful advice!! Thank you.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

196 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I implement Draggable Properties with custom Labels in Editor or PropertyDrawer? 1 Answer

Issue with property drawer control position in inspector 1 Answer

Component OnAwake or OnEnable with PropertyAttribute 1 Answer

How to draw a field with both decorator and property drawer? 0 Answers

Multiple attributes 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges