- Home /
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.
Are you saying that Screen.width
and Screen.height
are not correct when running in the Editor?
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.
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.
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.
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.
Your answer
Follow this Question
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