Search Unity

Unity Resolution Duplicated

Discussion in 'Scripting' started by kardok, Jan 14, 2022.

  1. kardok

    kardok

    Joined:
    Mar 11, 2018
    Posts:
    46
    Code (CSharp):
    1. List<string> options = new List<string>();
    2.         resolutions = Screen.resolutions;
    3.         int currentResolutionIndex = 0;
    4.  
    5.         for (int i = 0; i < resolutions.Length; i++)
    6.         {
    7.             string option = resolutions[i].width + " x " +
    8.                      resolutions[i].height;
    9.             options.Add(option);
    10.             if (resolutions[i].width == Screen.currentResolution.width
    11.                   && resolutions[i].height == Screen.currentResolution.height)
    12.                 currentResolutionIndex = i;
    13.         }
    14.         resolutionDropdown.AddOptions(options);
    15.         resolutionDropdown.RefreshShownValue();
    16.         if (PlayerPrefs.GetFloat("ÇözünürlükX") == 0)
    17.         {
    18.             resolutionDropdown.value = options.Count;
    19.         }
    20.         else
    21.         {
    22.             resolutionDropdown.value = options.IndexOf(PlayerPrefs.GetFloat("ÇözünürlükX") +" x "+ PlayerPrefs.GetFloat("ÇözünürlükY"));
    23.         }
    With this code i am getting resolutions but they are coming by duplicated values. Like there is 2 1920*1080. I looked at many thread at Unity. They didn't worked for me. How can i fix this?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,726
    They're probably different refresh rates. Check that field.

    Also, this:

    You should consider centralizing to avoid typos. It should also be an integer, not a float.

    Here's an example of simple persistent loading/saving values using PlayerPrefs:

    https://gist.github.com/kurtdekker/01da815d2dfd336a925ae38019c3a163

    Useful for a relatively small number of simple values.
     
    kardok likes this.
  3. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    227
    yeah its because there are different refresh rates. If you dont want duplicate resolution size, you can do this:
    Code (CSharp):
    1. resolutions = Screen.resolutions.Where(resolution => resolution.refreshRate == 60).ToArray();
     
    kardok likes this.
  4. kardok

    kardok

    Joined:
    Mar 11, 2018
    Posts:
    46
    Thank you, it worked.
     
  5. Pixitales

    Pixitales

    Joined:
    Oct 24, 2018
    Posts:
    227
    Np, it grabs only screen resolutions that are refresh rate of 60, but you can change that value if u would like.
     
    kardok likes this.