Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
2
Question by Aftech · May 07, 2014 at 02:19 AM · custom-inspectorproperty drawerproperty fields

EditorGUI PrefixLabel for multiple property fields.

Hello,

For my current project I've defined a very simple IntVector2 class.

Until now I've been using an also pretty simple custom inspector to draw its two properties, each on a separate line.

But now with even more custom inspector coolness, the script's inspector is getting crowded.

I've been following Jasper Flick's awesome tutorial to try and get them on a single line.

I did get the properties to display on a single line, but then, it's not really following the inspector's original behavior:

  • When selecting the prefix label of a Vector2, the first field for X is not selected.. but in my case, it does get selected/focused. the tutorial above does not have this issue, and i think it's because the first property is a Vector3 drawn using the EditorGUI.PropertyField, thus using Unity's own property drawer.
  • Also, it's only when the first property has changed that the prefix label gets to be bold.. In my case it means that if the Y property of my IntVector2 is modified, the prefix label is not displayed in bold.

    and the same behavior can be observed when importing Jasper Flick's demo package, if the color property is changed,
    then the prefix label is not bold.

    So my questions would be:

  • How can I tell a prefix label to not select the next control ?
  • Is there a way to get a prefix label so support multiple call to EditorGUI.PropertyField ? so it would be bold if any of the property fields have changed ?
  • At the end of Jasper's tutorial, he mentions that "Unity version 4.3 and above have some editor bugs".. could this the case here?
  • I've asked google and searched here for a while before posting my own question..

    maybe I'm not asking the right question?

    Screenshot for issue #1 (weird selection):

    alt text

    Screenshot for issue #2 (bolding behavior):

    alt text

    I'm using Unity Free 4.3.4f1

    and here is the code of my IntVector2 PropertyDrawer's OnGUI method ( heavily based on Jasper Flick's tutorial)

     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
     {
         label = EditorGUI.BeginProperty(position, label, property);
     
             
         var contentPosition = EditorGUI.PrefixLabel(position, label);
             
         EditorGUIUtility.labelWidth = 14f;
         contentPosition.width /= 2f;
            
         EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative(@"x"));
     
         contentPosition.x += contentPosition.width;
             
         EditorGUI.PropertyField(contentPosition, property.FindPropertyRelative(@"y"));
             
         EditorGUI.EndProperty();
     }
    
    
    

    I'll end this with a big thank you for your time reading all this, and to Jasper Flick for his tutorial :)

    prefixlabelselection.png (5.0 kB)
    prefixlabelbold.png (6.7 kB)
    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 scanzy · Apr 21, 2017 at 02:19 AM

    Hey, I found some solutions:


    1) How can I tell a prefix label to not select the next control ?

    from the docs (https://docs.unity3d.com/ScriptReference/PropertyDrawer.html)

     Rect content = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), label);
    

    This would not let you select the label (it won't become blue if you click it)


    2) Is there a way to get a prefix label so it would be bold if any of the property fields have changed ?

    from the docs: (https://docs.unity3d.com/ScriptReference/EditorGUI.BeginProperty.html)

    BeginProperty and EndProperty automatically handle default labels, bold font for prefab overrides, revert to prefab right click menu, and setting showMixedValue to true if the values of the property are different when multi-object editing.

    So we only need to use:

     label = EditorGUI.BeginProperty(rect, label, property);
    
     //prefix label here
     //fields here
     
     EditorGUI.EndProperty();
    

    You already implemented this in your code, I think this is working now because they fixed bugs.


    Sometimes the docs can hide some small details that can be got only reading a lot of times, sometimes we just need to wait for bugs to be fixed... I hope they could share some source code with the community so we could have the possibility to better understand all this and work better.

    Comment
    Add comment · 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

    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

    21 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

    Related Questions

    Losing Class References 0 Answers

    Showing the editors of list elements 0 Answers

    Saving changes to mixed CustomInspector 1 Answer

    How to choose the transform tool from script ? 4 Answers

    Custom editor: How to initialise a new array element? 1 Answer


    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