Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 arisonu123 · Aug 05, 2017 at 01:25 AM · guieditor-scriptingpropertydrawerattribute

Issue with property drawer control position in inspector

I am creating a custom property drawer. I want the label for my property , but instead of drawing the control for my property I want to draw a popup with string choices. Now this is all fine and is drawn sorta right. Now my problem is whenever I resize the inspector the width of my popup will change and my x is changing. Now they should be changing like the rest of the controls do, but they are changing wrong. They are becoming too wide and moving too far to the left, while the label stays in the proper spot. Anyone know how to fix it so it stays the right width and x position? I want it the same as the enums variables below it.

Here is my code:

         [CustomPropertyDrawer(typeof(StringVerEnum))]
         public class StringVerEnumDrawer : PropertyDrawer
         {
 
             string[] options = { "Item1", "Item2", "Item3", "Item4", "Item5™" };           
   
             public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
             {
                 int choice = property.enumValueIndex;
                 GUIContent LabelText= new GUIContent("My Label","My tooltip");
                 EditorGUI.PrefixLabel(position, LabelText);
                 var PopupPosition = new Rect(position.x + (position.x/0.1f), position.y , position.width -(position.width/3f) , position.height);
                 EditorGUI.BeginChangeCheck();
                 choice = EditorGUI.Popup(PopupPosition, choice, options);
                 if (EditorGUI.EndChangeCheck())
                 {
                   property.enumValueIndex = choice;

                 }
             }
         }

StringVerEnum is an attribute that I am using for the variable/property that is using this property drawer, incase that somehow matters. Now it is also entirely possible my position change values are just wrong, I'm not entirely sure. I do know when I use position it is the rect for the label and the control. It would be nice if there was someway to get the rect for just the label and just the control to try to make sure that everything is in the right place , but haven't been able to find anything in the docs that does that. Any help with getting my control/popup to always be in the right position is greatly appreciated.

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
Best Answer

Answer by arisonu123 · Aug 06, 2017 at 07:43 PM

So I found the answer. There is an overload of the popup function that allows me to pass the position with a label. This function appears to automatically calculate the space between the label and the control and puts the label in front of the control in the proper spot. New code:

 [CustomPropertyDrawer(typeof(StringVerEnum))]
   public class StringVerEnumDrawer : PropertyDrawer
 {
  GUIContent[] options = { new GUIContent("Item1"), new GUIContent("Item2"), new GUIContent("Item3"), new GUIContent("ItemTest"), new GUIContent("Item5™")};
 
  public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  {
      int choice = property.enumValueIndex;
      GUIContent LabelText = new GUIContent("My Label", "My tooltip");   
      EditorGUI.BeginChangeCheck();
      choice = EditorGUI.Popup(position,LabelText,choice,options);
      if (EditorGUI.EndChangeCheck())
      {
           property.enumValueIndex = choice;
      }
   }
 }



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

120 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

Related Questions

Drawing Order of DecoratorDrawer doesn't work? 1 Answer

Why PropertyDrawers shared same values? 2 Answers

PropertyDrawer let's dissapear my INT 0 Answers

How to prevent overlap when using nested arrays in CustomPropertyDrawers? 1 Answer

Unity won't even let me draw my interface property drawer? WTF?!?! Y U No support interfaces???? 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