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 /
  • Help Room /
avatar image
0
Question by modernator24 · Sep 15, 2018 at 01:00 PM · uipanel

Dynamic width panel

I have some issue with my UI when I change screen's width.

alt text

I have two panels, which named Left Panel and Right Panel. Each has top left/right pivot point.

Above screenshot was captured with 1280x800 size of width, and I'm using UI Scale Mode as Scale with Screen Size and reference resolution value is 1280x800, and Screen Match Mode set to Expand.

alt text

So it works well with 1280x800, however with lower resolution, I have some empty spaces between left and right panels:

alt text

What I want is keep Left panel has same width, but only changes the width of the right panel.

Unfortunately I can't find any related informations, and I tried to adjust the size by script directly but it wasn't worked as expected.

To explain what is that mean, I got the size of left panel and Screen.width, and subtracted screen from Left Panel's width.

It works in same resolution(1280x800), however in lower resolution(1024x600), it was totally wrong.

Left Panel has almost 400 width, so in this case, Right Panel should be has 880(not include spaces between panel).

So in 1024x600 resolution, it must be near by 620 (1024 - 400 = 624), and calculation was correct but results of Right Panel too small short.

To make fit Right Panel, I had to set to width almost 800, and I don't know what's going on. Just adding 400 + 800 already exceeds 1024.

I think I have to do something like dynamic resizing, to automatically resize it's width or height, but I don't get it how to work with static sized element(Left Panel).

Can anyone give me some advice to how to work my UI respond dynamically with static UI element?

Or, what did I wrong in manually setting the width of the Right Panel by script, why the panel was too short?

Any advice will very appreciate it.

1.png (79.9 kB)
k-1509.png (25.2 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 eses · Sep 15, 2018 at 01:11 PM 0
Share

Hi @modernator24

If you don't want to just make your right side panel anchor so that it fills the remaining space from left panels right edge, you could try something like the code below. Use Canvas Scaler, with Scale With Screen Size Scale mode. Then $$anonymous$$atch slider: 0. Panel is your right side panel, panelRef is your left side panel. Here height of stretched right side panel is just screen height. Note. I also moved right side panel's pivot to where it's anchor is.

 var w = (scaler.referenceResolution.x) -  (panelRef.rect.width);
 var h = canvasRt.rect.height;
 panel.sizeDelta = new Vector2(w, h);


This way you could keep your both anchors in "flower" shape, left panel anchor in upper left corner of canvas, and right side panel's anchor in upper right corner of canvas.

1 Reply

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

Answer by nathanlink169 · Sep 15, 2018 at 04:25 PM

The way that I would do it is to set up both panels to have a parent. This parent should have an horizontal layout group. The horizontal layout group should have both sets of "Child Force Expand" turned off, and the "Child Controls Size Width" turned on ("Child Controls Size Height" can be turned on or off, up to you)

On both panels, I would put a Layout Element. The left panel should have both a Min Width and a Prefered Width of 400 (or whatever you would like). The right panel should have a Flexible Width of 1.

This means that the Left Panel should take up only 400, and the right panel will take up the rest of the space. In order to change the spacing between or around, you can change the Padding and Spacing in the parents Horizontal Layout Group.

alt text


untitled.png (20.8 kB)
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 modernator24 · Sep 17, 2018 at 10:03 AM 0
Share

Thanks dude, this works perfectly!

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

212 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 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

Activate and deactivate panels with buttons 3 Answers

Move UI panel on and off screen, scripted without animation 0 Answers

How to enable a panel after collision 1 Answer

I want to Automatically resize/snap buttons to my panel but it isnt working 0 Answers

Screen Format Question (Panels) 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