Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Scripting' started by BooBi, Nov 5, 2010.

  1. BooBi

    BooBi

    Joined:
    Jan 18, 2010
    Posts:
    534
    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
     
  2. Metal Head

    Metal Head

    Joined:
    Aug 14, 2010
    Posts:
    411
    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.
     
  3. Bluestrike

    Bluestrike

    Joined:
    Sep 26, 2009
    Posts:
    256
    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)

    Code (csharp):
    1.  
    2. function Awake()
    3. {
    4.     resolutions = Screen.resolutions;  
    5. }
    6.  
    7.  
    8. ... and in my gui:
    9.     // RESOLUTIONS
    10.                 GUI.Label (Rect (100, 150 , 180, 20), "Availeble display resolutions: " );
    11.                 // Widescreen
    12.                 GUI.Label (Rect (150, 170 , 100, 30), "Widescreen: " );
    13.                 GUILayout.BeginArea (Rect (150,210,100,600));
    14.                     for (var res in resolutions)
    15.                     {
    16.                         if(res.width /16 == (res.height/10 || res.height/9 )  res.width >= 1024)
    17.                         {
    18.                             resDimensions = res.width.ToString() + "x" + res.height.ToString();
    19.                             //if (GUILayout.Button(resDimensions, GUILayout.Width (100)))
    20.                             if (GUILayout.Button(resDimensions))
    21.                             {
    22.                                 selectedWidthRes    = res.width;
    23.                                 selectedHeightRes   = res.height;
    24.                             }
    25.                         }
    26.                     }
    27.                 GUILayout.EndArea();
    28.                
    29.                 // 4 x 3 resolution
    30.                 GUI.Label (Rect (350, 170 , 100, 30), "4 x 3: " );
    31.                 GUILayout.BeginArea (Rect (350,210,100,600));
    32.                     for (var res in resolutions)
    33.                     {
    34.                         if(res.width/4 == (res.height/3)  res.width >= 1024)
    35.                         {
    36.                             resDimensions = res.width.ToString() + "x" + res.height.ToString();
    37.                             if (GUILayout.Button(resDimensions))
    38.                             {
    39.                                 selectedWidthRes    = res.width;
    40.                                 selectedHeightRes   = res.height;
    41.                             }
    42.                         }
    43.                     }
    44.                 GUILayout.EndArea();
    45.                
    46.                 // no standard resolution.
    47.                 GUI.Label (Rect (550, 170 , 100, 30), "Other: " );
    48.                 GUILayout.BeginArea (Rect (550,210,100,600));
    49.                     for (var res in resolutions)
    50.                     {
    51.                         if((res.width /16 != (res.height/10 || res.height/9)  (res.width/4 != (res.height/3)))  res.width >= 1024)
    52.                         {
    53.                             resDimensions = res.width.ToString() + "x" + res.height.ToString();
    54.                             if (GUILayout.Button(resDimensions))
    55.                             {
    56.                                 selectedWidthRes    = res.width;
    57.                                 selectedHeightRes   = res.height;
    58.                             }
    59.                         }
    60.                     }
    61.                 GUILayout.EndArea();
    The tabs are a bit large on the forum, so probably copy paste this so its more readable ;)

    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:
    Code (csharp):
    1. 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.
     
    Last edited: Dec 2, 2010
  4. BooBi

    BooBi

    Joined:
    Jan 18, 2010
    Posts:
    534
    Wow nice, a belgian too :D

    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 ?
     
    Last edited: Dec 2, 2010