• 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
Question by joergipoergi · May 22, 2018 at 09:41 PM · canvasui imagescaling

Wrpping my head around canvas,Wraping my head around Canvas placement

Hi

I'm having difficulties wrapping my head around this one:

I'm trying to get the following layout:

alt text

Where the red triangles are buttons and should always preserve aspect ratio, that is they should always be right-angled triangles.

In between the triangles, i want a list of buttons, so its not just a fancy border, it's a UI element.

So basically the list of buttons on the sides should be exactly as wide, as the list of buttons are high on top and bottom.

However, using canvas allows only to have proportional heights and width, to screen height and with. So changing the aspect ratio would yield something like this: alt text

See how the corners don't match up anymore with the triangle tips?

What's more, the triangles themselves should obviously scale up and down, depending on screen resolution.

So Question:

How can I achieve a layout, where the height of the rows, matches the width of the column, but keeping that number variable, according to screen size.

Any help appreciated.

layout-01.jpg (58.2 kB)
layout-02.jpg (54.2 kB)
Comment

People who like this

0 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by joergipoergi · May 24, 2018 at 02:09 PM

Ok, so i found no easy answer. what I ended up doing is the following:

The Panels containing the buttons on the side, as well as the triangles, get scaled naturally using RectTransform.

The Panels on top and bottom I have to scale myself, using the following code:

 private void Rescale(){
 
         ratio = parentRect.rect.width / parentRect.rect.height;
 
         if (bottom) rect.anchorMax = new Vector2 (rect.anchorMax.x, ratio * offsetX);
         if (top) rect.anchorMin = new Vector2 (rect.anchorMin.x, 1-ratio * offsetX);
 
         rect.offsetMin = new Vector2(0f, 0f);
         rect.offsetMax = new Vector2(0f, 0f);
     }
 
     void Update(){
         var newRatio = parentRect.rect.width / parentRect.rect.height;
         if (newRatio != ratio) {
             Rescale ();
             ratio = newRatio;
         }
     }

It's not the best solution, as it has some problems. First, It doesn't seem to be fully accurate. Looking very closely, the lines are sometimes a little off.

Setting the canvas-scaler to use only width or height helps a little.

Second, the triangles stop resizing at some point. It's right-angle triangles, so their ration is 2:1. If the Screen exceeds this ratio, the scaling of the triangle becomes somewhat unpredictable. I tried to limit my Rescale() function to max on a ration of 2:1 but it didn't really help, because the scaling doesn't just stop at that ratio. Maybe someone can still give me a hint, on how unity scales objects. So far this solution works for me.

regards.

Comment

People who like this

0 Show 0 · 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

Answer by spilat12 · May 22, 2018 at 11:28 PM

Try changing the UI Scale Mode of your Canvas Scaler to "Scale With Screen Size" and see if that helps you achieve the desired effect, like so: alt text


scale-with-screen.png (40.6 kB)
Comment

People who like this

0 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 joergipoergi · May 23, 2018 at 05:22 AM 0
Share

Thanks for the answer.

It is set to scale with screen.

It also doesn't help, to restrict scaling to either width or height, because always, the other is affected as well.

The Problem is, that the height of the buttons area, is not only defined by the device height, but also by the device width.

i.e. the the triangles size is defined by both, the height AND the width of the device. The area of the buttons is always only defined by either the width OR the height, but should actually just be defined by the scale of the triangles.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

90 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

Related Questions

Image on UI doesn't stretch when objects it's on is stretched. 0 Answers

Canvas, instantiate and adjust size of image to fit parent 0 Answers

UI not scaling correctly with HUD Image Background 0 Answers

Converting to "Rect Transform" permanently deleted part of my project 0 Answers

Pixel Perfection unity UI 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