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
2
Question by Steven-Walker · Sep 20, 2011 at 11:58 PM · editorresolution

Detect resolution selected in Editor Game view?

Is there a way to know what resolution option is selected in the Game view, either during play or edit mode within the editor? I have some code that attempts to detect different iOS resolutions, which works great on the devices, but doesn't works so well in the editor when the game view resolution is not set exactly. It would be helpful if I could get the name of the resolution selected, such as "iPad Wide (1024x768)", or whatever.

Comment
Add comment · Show 4
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 Waz · Sep 21, 2011 at 03:50 AM 1
Share

Are you saying that Screen.width and Screen.height are not correct when running in the Editor?

avatar image Steven-Walker · Sep 21, 2011 at 05:48 AM 0
Share

Screen.width/height are fine. The problem is that sometimes I may have "iPad Wide (4:3)" (or some other option) selected so the actual size is not exactly 1024x768. If I knew the name of the selection, then my script could better guess the intended resolution when the game view is an arbitrary size. This isn't a big deal, just wondering if there's more information on the view I can access for a more intelligent script.

avatar image syclamoth · Sep 21, 2011 at 08:59 AM 0
Share

What about Screen.Resolution?

avatar image Steven-Walker · Sep 21, 2011 at 04:30 PM 0
Share

Thanks for the idea, but the Screen.currentResolution stores the entire screen size. It doesn't really help me deter$$anonymous$$e the game window setting.

2 Replies

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

Answer by Steven-Walker · Sep 21, 2011 at 04:46 PM

I found a simple solution by calculating the aspect ratio instead of looking at the width and height directly. If I assume that iPhone resolution is always 2:3 or 3:2, then I can reasonably detect whether the game view is set to iPhone. Thanks for everyone else's input.

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

Answer by Simon Says · Jul 04, 2014 at 09:23 PM

A good question, but the answer seems a bit lacking. I thought I would elaborate on what finally works for me.

I can't detect what option is selected, but I can reliably detect current GameView resolution (therefore its aspect ratio) and its changes.

1) GameView resolution can be queried at any time by asking the main camera for Camera.pixelWidth and Camera.pixelHeight, while resetting its viewport rectangle (Camera.rect) to full size. Screen.width/height in editor are not actually fine; they return the size of the currently focused EditorWindow.

2) Any MonoBehaviour can listen to GameView resolution changes if set to [ExecuteInEditMode]. OnGUI() then reports the new resolution that can be compared against the old one you need to remember. Note that the resolution is not yet updated in Update().

This is true for Unity 4.5.

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Editor crashing when editing scripts referenced from GameObjects 1 Answer

The Script Equivilent of dragging a hierarchy of meshes over a preexisting prefab? 0 Answers

Tracking down causes of Editor errors. 1 Answer

Paint on object in editor and return as texture. 1 Answer

Scripting a "Unity Editor"-like object transformation control 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