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
1
Question by tomekkie2 · Dec 14, 2014 at 09:19 PM · uiscrollview4.6scrollbar

4.6 UI - how to make a dynamic scrollbar?

How do you make in new 4.6 UI a scrollbar to appear only when the content size is greater than the ScrollView size?

Comment
Add comment · Show 5
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 Mmmpies · Dec 14, 2014 at 10:10 PM 0
Share

I guess you have dynamic content in your scroll view. I've been trying to figure out how to add prefab panels to a scroll area for weeks.

The answer bit: Well I guess you could check the size of the parent and if the child is greater then enable the scrollbar.

The question bit: If you can give me an example of how to successfully add new GUI prefab panels with child objects to a scrollrect and not have weird aspect ratio issues or the panel not scrolling I'd be eternally grateful (realistically a few weeks of grateful!) :¬)

I know, I know I shouldn't ask a question in an answer, but my answer did have an answer. If you can answer my problem just let me know and I i'll ask the question so others can benefit form it.

avatar image tomekkie2 · Dec 14, 2014 at 10:40 PM 0
Share

I am just trying to find if there is a way to substitute OnGUI with the new 4.6 UI in dynamic menus, scrollareas and so on. Looks like the Legacy OnGUI is still indispensable when it comes to dynamic layouts and scrollareas.

avatar image Mmmpies · Dec 14, 2014 at 10:52 PM 0
Share

No I don't think it is. OnGUI is so wasteful, lots of people have found solutions but it's early days for the new UI.

What's a shame is I had DFGUI and it worked similar to the new GUI but prefabs worked so much better.

When I upgraded to 4.6 the menus I had with DF were suddenly tiny so I took the route of going with the new UI.

avatar image Kiwasi · Dec 15, 2014 at 01:43 AM 0
Share

This sounds interesting. I might tackle it in a YouTube video at some point. $$anonymous$$y general approach would be to use SetActive to enable and disable scroll bars. You should be able to compare the bounds of the RectTransforms directly to get the size.

For adding prefabs to an existing UI panel you can't go past the layout elements.

avatar image tomekkie2 · Dec 15, 2014 at 06:02 AM 0
Share

You might be right, @Bored$$anonymous$$ormon, but since in OnGUI.ScrollView this was just happening automatically, I expected the same to be happening in UI. Or just a checkbox for the scrollbar to dissapear when the content size is less than the ScrollView size. But looks like that requires some extra scripting.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Mmmpies · Dec 17, 2014 at 11:41 AM

Various way's to do this it's up to you but not difficult to script.

If you're scrollbar is likely to be dynamically then add a CanvasGroup and

if (myScrollbar.size == 1) { myScrollbar.GetComponent<CanvasGroup>().alpha = 0; myScrollbat.GetComponent<CanvasGroup>().interactable = false; myScrollbar.GetComponent<CanvasGroup>().blocksRaycast= false; }

Of course you can setActive as well or make that gameObject enabled = false so it's up to you for the approach. And you'll need an else to switch it on if not == 1.

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 tomekkie2 · Dec 17, 2014 at 01:10 PM 0
Share

Thanks. Seems like there is a lot to learn about the new UI system. The old OnGUI still seems more straightforward to me and easier to start.

avatar image
1

Answer by Darklighte · Dec 23, 2014 at 07:22 PM

The previous answer has the correct approach as far as I can tell. The reason for checking the scroll bar height, instead of the content rect against your scrollview rect, like you would naturally think to do has to deal with the order of execution in the RebuildLayout method, unless you aren't using any autolayout componenents and are calculating it on your own.

I recommend however that instead of adding a canvas group component, unless you'd like to have a non interact-able but visible scrollbar, would just be to get the images of the scrollbar and handle and set their enable to false. This will accomplish the same thing without an extra component.

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 Mmmpies · Dec 23, 2014 at 07:59 PM 0
Share

I used the canvasGroup because I had issues with the scrollBar not picking up new values if it's not enabled. $$anonymous$$ind you that was on one of the beta releases so might not be an issue now.

There are still issues with the == 1 approach, In testing an identical menu can have a size == 1 or .98 or even lower.

So I've setup a tab menu for spells, you can have all spells, contact spells, range or self. When I click on the tabstrip button the menu is dynamically built for the same list.

One of the tabs is very close to fitting on the screen with only a small overlap in the scrollPanel but it can build and == 1 then I click another tab and back on this one and it == .97, back off and back on and it == .98.

Early days for the new UI, I still like it but it needs work.

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

29 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

Related Questions

Scrollbar touch sensitivity 0 Answers

Why is my scrollbar not working? 4 Answers

How to disable ScrollView dragging 4 Answers

Smooth scroll snap? 3 Answers

Scroll Rect Min/Max Size 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