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 dxmachina · Jan 20, 2016 at 01:53 AM · guicanvasuser interface

How to resize UI panel based on visibility of children?

How would I go about scaling the size of a UI panel based on the visibility of it's child-components? For instance, if I have a panel of buttons and I want to size it down when some buttons are not available?

Thanks!

Comment
Add comment · Show 2
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 incorrect · Jan 20, 2016 at 01:53 AM 0
Share

Why not set UI Scale $$anonymous$$ode of Canvas Scaler to Scale with Screen Size?

avatar image dxmachina incorrect · Jan 20, 2016 at 01:55 AM 0
Share

Because (unless I'm misunderstanding) that wouldn't accomplish the goal... to vertically resize a panel based on the number of buttons it contains (IE - to size to the visible content dynamically).

1 Reply

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

Answer by SterlingSoftworks · Jan 20, 2016 at 05:58 AM

alt text

I'm assuming this is what you are going after correct? (ignore the yellowish/brown that's just the background, the pale white is a panel and the full white are buttons)

This took some fiddling with the GUI system but I've got your solution!

First, create a Panel on your canvas and make it what ever size you need/want.

Then you're going to add two components to this panel. Through the "Add Component" button you're going to make your way to Layout -> Horizontal, Vertical, or Grid Layout Group (whatever suits your needs). You can mess with the cell size, spacing and etc to again, suit your needs.

Then you'll need to add the Content Size Fitter component also found in the Layout section. Set the Horizontal and Vertical fits to "Preferred Size".

NOW, add however many buttons to this panel as your heart desires. :D

The panel will re-size to fit the amount of ACTIVE child buttons.


unity-button-resize.png (2.5 kB)
Comment
Add comment · Show 3 · 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 dxmachina · Jan 20, 2016 at 06:06 AM 0
Share

Fantastic... thank you. I was fiddling with those exactly, but had yet to get it all working.

The grid layout also looks fantastic since you can use the constraints to do horizontal + vertical with a fixed column/row if desired.

Thanks again.

avatar image SterlingSoftworks dxmachina · Jan 20, 2016 at 06:10 AM 0
Share

Good, I'm glad you were at least trying to get something to work by exploring the the components ins$$anonymous$$d of co$$anonymous$$g straight here xD

I don't have much experience with GUI and this will definitely be stored in my head for later use as I've never done this before. So thank YOU for asking it hah

It's great isn't it?? $$anonymous$$akes putting together menus SO much easier and looking much cleaner. Wish I knew that when I made my first game!

avatar image incorrect SterlingSoftworks · Jan 20, 2016 at 06:16 AM 0
Share

It's awesome. There was a similar functionality in nGUI and I was really missing it in Unity 4.6. Well done!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why use different Canvas Render Modes 0 Answers

UI buttons become unselectable on scene change 2 Answers

How do I create an Image of certain size in the middle of the screen with stretching border images 0 Answers

Text object can't be searched for with GameObject.Find 3 Answers

How to make button stay the same size on all screens? 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