When i don't display the Resolution dialog box How pick the correct ratio ?

Hi,

I would like to know how do you build your project to get everytime square pixels ?

I don’t want to display the Resolution dialog box, I’ll send my project to a lot of people and I don’t know their monitor ratio.
How can I do to launch an exe which detect the monitor ratio and choose the right resolution ?

I tried to launch an 16/10 resolution on a 4/3 monitor and that’s awful (try it) that’s exactly what I don’t want to append.

If you have ideas please, help me it’s kind of urgent…

Cheers

BooBi

WEll, you’ll have to check if Screen.width : Screen.height = 16 : 9 or 4:3 and so on. The problem is that I couldn’t get it to work.My approach was to divide the Screen width by the screen height and than comprare if they divide like one of the ratios, but the division was always equal to one, no matter what ( I know, that screen resolutions are integer) so I gave up. I should try to do it again and I’ll write back if I manage to do it.

This is what I figured out to sort resolutions, I am also asuming that my user base will have at least 1024*768
(as its the windows default settings and I wanted a 3d objects menu for my game what gave problems with to low resolutions)

function Awake()
{
	resolutions = Screen.resolutions;	
}


... and in my gui:
	// RESOLUTIONS
				GUI.Label (Rect (100, 150 , 180, 20), "Availeble display resolutions: " );
				// Widescreen
				GUI.Label (Rect (150, 170 , 100, 30), "Widescreen: " );
				GUILayout.BeginArea (Rect (150,210,100,600));
					for (var res in resolutions) 
					{
						if(res.width /16 == (res.height/10 || res.height/9 )  res.width >= 1024)
						{
							resDimensions = res.width.ToString() + "x" + res.height.ToString();
							//if (GUILayout.Button(resDimensions, GUILayout.Width (100)))
							if (GUILayout.Button(resDimensions))
							{
								selectedWidthRes 	= res.width;
								selectedHeightRes	= res.height; 
							}
						}
					}
				GUILayout.EndArea();
				
				// 4 x 3 resolution
				GUI.Label (Rect (350, 170 , 100, 30), "4 x 3: " );
				GUILayout.BeginArea (Rect (350,210,100,600));
					for (var res in resolutions) 
					{
						if(res.width/4 == (res.height/3)  res.width >= 1024)
						{
							resDimensions = res.width.ToString() + "x" + res.height.ToString();
							if (GUILayout.Button(resDimensions))
							{
								selectedWidthRes 	= res.width;
								selectedHeightRes	= res.height; 
							}
						}
					}
				GUILayout.EndArea();
				
				// no standard resolution.
				GUI.Label (Rect (550, 170 , 100, 30), "Other: " );
				GUILayout.BeginArea (Rect (550,210,100,600));
					for (var res in resolutions) 
					{
						if((res.width /16 != (res.height/10 || res.height/9)  (res.width/4 != (res.height/3)))  res.width >= 1024)
						{
							resDimensions = res.width.ToString() + "x" + res.height.ToString();
							if (GUILayout.Button(resDimensions))
							{
								selectedWidthRes 	= res.width;
								selectedHeightRes	= res.height; 
							}
						}
					}
				GUILayout.EndArea();

The tabs are a bit large on the forum, so probably copy paste this so its more readable :wink:

selectedWithRes and selectedHeightRes are used for a location in the vgui where I display the current resolution setting.
and with a save button the resolution is updated:

Screen.SetResolution (selectedWidthRes, selectedHeightRes, fullScreenTog);

I make the game detect if its the first time launch, and show a setup screen where the players can set their name, quality and resolution, and save it into player prefs.
To see if its a first time launch I check if the player perfs exist.

I would also like to know if its possible to detect the desktop resolution, so I can match it in the game.

Wow nice, a belgian too :smile:

I’ve finally found the way to create my autorescale system by using:

  • and using a 4k*4k output resolution like this it automatically choose the best resolution with the ratio of the monitor.
  • very simple equations for my buttons positions (like this I can easily add or remove buttons).
  • using a matrix to set the ratio from the ratio that I use for the initial viewer (in illustrator)
  • and at the start I check the ratio and choose the right numbers for my bottom toolbar button, top toolbar,… and it automatically use the equation to position the button at the right place without any strecht

I add to prepare the 3 ratio (16/10 16/9 and 4/3) in illustrator (in fact only the 16/9 and the 4/3 because 16/10 and 16/10 needs just the bottom toolbar a little lower…).

I’ll check your code this weekend. thank’s

Where are u come from ?