This is a twofold question:
I have set a preferred resolution (1024x768; windowed) for my PC standalone build. But I allow the player to change the resolution via an ingame options menu. The problem is, that the window doesn't stay centered when the resolution is set to 1600 wide (my monitor's resolution is 1600x1200). It is shifted to the left, partway on my secondary monitor. Is there anything I can do to prevent that?
(addition: can I make it that the preferred resolution is changed, so that the standalone player starts with the new resolution instead of the resolution I set in the player settings? I tried PlayerSettings.default..., but it throws an error when I try to compile: Unknown Identifier: 'PlayerSettings'. Is it possible that this feature is only editable with C#?)
The player can also change from windowed to full screen. But when the current resolution doesn't match the aspect ratio of the screen, the game appears stretched. Can I fix that? Maybe add black bars at the top and bottom (or left/right on a widescreen monitor with 4:3 resolution)
Answer by syclamoth
·
May 10, 2012 at 01:51 PM
1: The size of the screen is defined from one of the corners, so if it's windowed there's not really much Unity can do to fix that (considering that window placement is up to your desktop environment of choice).
The actual preferred setting is stored in 'PlayerPrefs'- you can access it just like any pref you would set otherwise. I'm afraid I don't know exactly what you need to change in order to modify the screen setup on Windows, but I do know that on MacOS it is stored in a string named 'NSWindow Frame ScreenSetup'. This makes things kind of difficult- the values are numeric, but stored as a series of numbers separated by spaces.
I would just override the automatic screen res setting when you load the game. If you store the custom resolution as two integers in PlayerPrefs, you should be able to simply disregard the one at startup. This isn't a good solution, but I can't really see a better one without more clear information about exactly how the quality dialogue stores its settings.
'PlayerSettings' is an editor class, so you can't compile it without importing the 'UnityEditor' namespace. This means you won't be able to use it in your finished build, either- since it won't compile. In any case, 'PlayerSettings' is the class for modifying the properties of the executable that will be built when you press the 'Build' button- not the settings for the player itself. You are probably thinking of 'PlayerPrefs'.
2: In the player settings (the ones discussed just before), there is a dropdown labelled 'Supported Aspect Ratios'. Simply drop this down, and only select the aspect ratios that your game should support. This may or may not actually do what you want it to- if it instead simply limits you to screens of a specific aspect ratio (instead of implementing letterboxing etc.), you should come up with some kind of system that detects if it would be a problem, and doesn't let you pick those resolutions.
I do override the resolution on startup (via PlayerPrefs), but I hoped there was a way to make the game start in the correct resolution. The way it is now, the Unity Splash Screen is displayed in 1024x768 windowed and the game then switches to whatever resolution the player set it to last time. With a 1600 wide window it is again shifted to the left each time the game starts.
There are actually two sets of variables stored in the registry: the array index I use with PlayerPrefs and the actual current resolution. The game still starts with the default resolution and then switches to the one stored in the registry.
Limiting the resolutions does work, but only for the given aspect ratio; if I limit it to 4:3, it looks right on 4:3 monitors, regardless of the resolution chosen, but it is then always stretched on widescreen monitors.
I suspected that might be the case. Well, I'm afraid you're probably out of luck- there is no API in the script reference for modifying the values that are set up in the startup dialogue, and no functionality for letterboxing....
Aspect ratio is incorrect after forcing windowed mode with CMD+F and then back to fullscreen
1
Answer
Scaling particles across different aspect ratios
0
Answers
Mac Retina Support Standalone OSX
0
Answers
Standalone fullscreen-fixed size
0
Answers
How do i create an options menu?
3
Answers