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 NickWu · Feb 27, 2016 at 09:32 AM · inspectorcustom editorcustom-inspectorscrollbar

Scrollbar in Inspector

I was working on some custom editor scripts and I ran into this little thing that bothers me a lot.

In the screenshots, TargetObject is drawn with EditorGUILayout.PropertyField(), which behave just like the built-in inspector's variables.

The other variable SelectValue is drawn by the combination of BeginHorizontal, PrefixLabel, Popup, EndHorizontal.

As you can see, the offset between the label and control is different depending on whether the vertical scrollbar is present or not.

One possible workaround is to modify the EditorGUIUtility.labelWidth so all controls in the custom editor can share a unified offset, but they're still behaving differently from other built-in variables..

I know this is a minor problem, but it's bugging me a lot...

So my question is, is there a way to get whether the vertical scrollbar is visible or not so that I can modify the drawing rect to properly align them when the scrollbar is present?

alt text

alt text

scroll0.png (19.1 kB)
scroll1.png (10.5 kB)
Comment
Add comment · Show 1
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 Nimbuster · Dec 18, 2016 at 08:26 AM 0
Share

Just curious if you ever found a solution to this? The problem is EditorGUILayout.PrefixLabel; it doesn't seem to follow the same auto-layout as other fields, but I'm not sure if that's intended or a bug.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by igor84 · Feb 28, 2017 at 07:33 AM

The catch is that builtin methods like PropertyField() reserve only one big rect from the layout and then subdivide it manually for label and content, while calling PrefixLabel and then Popup requests two rects from layout and so they don't always turn out the same. In your case you should just call a version of Popup method that takes a label as parameter and skip calling BeginHorizontal and PrefixLabel. It will then execute the same manual steps for subdividing one rect and you should get the same alignment.

If on the other hand you are working with some custom components and you want to get the same look and behavior you would have to do something like this:

 var rect = EditorGUILayout.GetControlRect(true, 16f);
 rect = EditorGUI.PrefixLabel(rect, 0, ReusableGuiContent);
 rect.width = 30f;
 GUI.Toggle(rect, GUIUtility.GetControlID(FocusType.Keyboard), value1, content1, EditorStyles.miniButtonLeft);
 rect.x += rect.width;
 GUI.Toggle(rect, GUIUtility.GetControlID(FocusType.Keyboard), value2, content2, EditorStyles.miniButtonLeft);
 rect.x += rect.width;
 GUI.Toggle(rect, GUIUtility.GetControlID(FocusType.Keyboard), value3, content3, EditorStyles.miniButtonLeft);

This will get you a three push button control with proper alignment like in the attached screenshot. alt text


alignment.png (2.7 kB)
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

37 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

Related Questions

How to assign a rigidbody in custom inspector? 1 Answer

Can not you change the default GUI style of EditorGUI in OnInspectorGUI? 1 Answer

Questions Regarding Images in Custom Inspector/Editor 1 Answer

Make a custom inspector that shows a group of variables in form of list 2 Answers

How can i get SerializedProperty from UnityEvent which in List. Sorry for my Eng. 2 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