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 e-bonneville · Apr 05, 2011 at 06:59 PM · resolutionindependent

Making an object resolution-independent

I'm working on a GUI that doesn't use Untiy's GUI system. Instead, it's composed of objects rendered by a second camera. How do I make these objects resolution independent? I gave it a shot and came up with this code:

static public Vector3 GUIPosition(float x, float y) { GameObject GUICamObject = GameObject.FindWithTag("GUICam"); Camera GUICamera = GUICamObject.GetComponent<Camera>();

 Vector3 pos = GUICamera.ViewportToWorldPoint(new Vector3((x)/100,-(y-100)/100,9));
 return pos;

}

static public void Element(GameObject button, float x, float y) { Vector3 buttonPosition = GUIPosition(x, y); button.transform.position = buttonPosition; }

But it doesn't do the trick; on higher resolutions, object positions tend to distort anyways. I'm obviously going about it wrong; what's the "right" way to make an object resolution independent?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jesse Anders · Apr 05, 2011 at 10:47 PM

Assuming the UI camera's projection is orthographic, you can make the orthographic size a fixed value. This gives you the height of the 'UI area'; the width can then be derived from the height and the aspect ratio.

Setting aside aspect ratio for the moment, since you can set the size of the orthographic projection yourself, there shouldn't be any issues with resolution independence as far as that goes. For example, say the orthographic size is 50, meaning that the height of the projection is 100. A UI element that's 25 units tall will then take up a quarter of the screen's heights regardless of resolution. This doesn't give you pixel-for-pixel graphics of course, but it does give you resolution independence.

In practice, aspect ratio complicates things of course, in that you may still have to do some dynamic positioning based on the width of the projection. But, that problem is more or less unavoidable regardless of what approach you take, I think.

Comment
Add comment · Show 2 · 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 e-bonneville · Apr 05, 2011 at 11:54 PM 0
Share

Right, I've already managed to set the size of the orthographic projection. $$anonymous$$y problem now is the dynamic positioning you mentioned; that's what the above code does, and it works at lower resolutions. However, at higher resolutions, objects tend to slide off the sides of the screen; could it be something with the way I handle the width/x position ratio?

avatar image Jesse Anders · Apr 06, 2011 at 01:05 AM 0
Share

What's the code intended to do exactly? For example, what are the 100's for? (Also, I don't see any reference to the aspect ratio there, which might have something to do with it.)

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

No one has followed this question yet.

Related Questions

Android Resolutions Independent 1 Answer

State object error when implementing Matrix4x4.TRS solution to set resolution independence 1 Answer

camera view independent of resolution 1 Answer

any good read about independent gui for android devices 1 Answer

How Resolution Independence is Working 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