So I’m having some trouble with the resolutions options in my game, Unity for some reason shows a bunch of weird refresh rates if I have all the “Screen.resolutions;” available. To fix that I decided to detect if they are different from 60,120 and 144hz refresh rates, if so they are excluded from the options.
Everything fine until that point, but as we reduce the options of resolutions, I would have to assign each resolution an Index and check for that index when setting the resolution, I have no idea how to do that.
What I have for now:
List<string> options = new List<string>();
int currentResIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
resIndex++; //The idea here is to add an Index to every resolution, even the unused ones, so we can skip them in the function that sets the resolution.
//But I know that all this is doing for now is getting the total number of resolutions(in int form), and not assigning an Index for each of them. Idk how to do that
string option = resolutions<em>.width + " x " + resolutions_.height + " " + resolutions*.refreshRate +"Hz";*_</em>
if (resolutions.refreshRate == 59 || resolutions_.refreshRate == 119 || resolutions*.refreshRate == 144) {*
options.Add(option);_
}
if (resolutions.width == Screen.currentResolution.width && resolutions_.height == Screen.currentResolution.height && resolutions*.refreshRate == Screen.currentResolution.refreshRate)
{
currentResIndex = i;
}
}*_
resDropdown.AddOptions(options);
}
///(…)
public void SetResolution(int thisResIndex) {
thisResIndex = resIndex; //Here we would retrieve the assigned index for the resolution and set the resolution according to it.
Resolution resolution = resolutions[thisResIndex];
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
print(resolution.width + resolution.height);
}