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 /
avatar image
2
Question by Chiroptera · Aug 21, 2014 at 11:04 PM · editorwindowscrollview

EditorWindow ScrollView Not Working

I am programming my first EditorWindow and I am having a hard time working with the documentations. Especially the Scrollview. I learned from testing that I have to do "beginscrollview" before "beginhorizontal" for it to work. But at that time I had placeholder strings for the list of textures I wanted to display. But since I inserted the for-loop for the textures in the horizontal-space, the scrollbar doesn't show up anymore. Is it because I mix GUI with GUILayout? Or because of the Texture-Rects?

(With placeholder-textures for now, but) it should look like this:

alt text

The Code:

 void OnGUI()
     {
         GUILayout.Label("Object", EditorStyles.boldLabel);
         scrollPos = EditorGUILayout.BeginScrollView(scrollPos, true); //Scrollable things starting from here
         EditorGUILayout.BeginHorizontal(); //Multiple Objects in line horizontal
     
         for(int j = 0; j < prefabList.Count; j++) //List of Objects
         {
             Texture curIcon = prefabList[j].prefabIcon as Texture; //Icon of Object from List
             EditorGUI.DrawPreviewTexture(new Rect(100*j+20,0,70,70), curIcon); //Draw that icon as a texture in the Window
         }
 
         EditorGUILayout.EndHorizontal(); //everything else not in line
         EditorGUILayout.EndScrollView(); //everything else not scrollable
 }


What am I doing wrong? (Also, if I want to be able to click on the icons to select the corresponding object to be instantiated how would I do that? I have the Object together with the Icon in a list, that should be no problem, but what about the hovering over and clicking an icon thing? Maybe I just can't think straight right now...)

Thanks in advance.

scrollviewhelp.jpg (35.8 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 LukaKotar · Aug 23, 2015 at 01:34 AM 1
Share

Did you figure this out? I'm having the same issue.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Feb 17, 2016 at 02:54 AM

Like LukaKotar said any kind of Layout group only works with layout elements. Otherwise the layout group doesn't get any information how big the content area has to be.

Since you just need a rect of size 70 x 70 for each element all you have to do is using GetRect(70, 70) inside your loop:

      for(int j = 0; j < prefabList.Count; j++)
      {
          Rect rect = GUILayoutUtility.GetRect(70, 70);
          Texture curIcon = prefabList[j].prefabIcon as Texture;
          EditorGUI.DrawPreviewTexture(rect, curIcon);
      }

GetRect is the most important method when it comes to the layout system. Almost all layout element functions are internally calling some overload of GetRect to reserve a rectangle and then just call the non layout element function with that rect.

Note: GetRect will return an empty rect during the "Layout" event and the actual layouted rect during any other event.

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
avatar image
0

Answer by LukaKotar · Feb 16, 2016 at 09:21 PM

The scrollbar only seems to work with EditorGUILayout elements. A somewhat nasty workaround is to create empty space with EditorGUILayout.Space() as many times as needed per loop iteration, so that the scrollbar appears. Space() takes up 10 pixels.

Something like this worked for me:

 scrollPos = EditorGUILayout.ScrollView(scrollPos, GUILayout.Width(x), GUILayout.Height(y));
 EditorGUILayout.BeginHorizontal();
 
 for( ... ; ... ; ... ){
     // Your GUI code here
     for(int x = 0; x < 10; x++){
         // Loop through as many times as needed
         EditorGUILayout.Space();
     }
 }
 
 EditorGUILayout.EndHorizontal();
 EditorGUILayout.EndScrollView()

Additionally, I also used GUILayout.BeginArea() before the scroll view to restrict what's being scrolled.

It's not an ideal solution since you are limited to multiples of 10. But still, I rather be able to scroll too far than not at all.

Comment
Add comment · Show 1 · 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 18, 2016 at 12:52 PM 0
Share

btw ins$$anonymous$$d of "EditorGUILayout.Space" you should simply use GUILayout.Space. It allows you to specify how many pixels it should reserve in the layout. Though GetRect is the more correct approach. You might be interested in my GUI crash course

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Infinite scrollview 0 Answers

Find out default inspector height 1 Answer

How do you use EditorGUILayout.TextArea with EditorGUILayout.ScrollViewScope? 1 Answer

Editor GUI ScrollView Actual Scrollbar Not Showing Up?? 1 Answer

Select Element in ScrollView of EditorWindow 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