- Home /
how don't show some screen resolutions in my dropdown?
Hello I have script that shows available screen resolutions in my dropdown. It works.
Resolution[] resolution = Screen.resolutions;
res = resolution.Distinct().ToArray();
strRes = new string[res.Length];
for (int i = 0; i < res.Length; i++)
{
strRes[i] = res[i].width.ToString() + "x" + res[i].height.ToString() + " @ " + res[i].refreshRate.ToString() + "Hz";
}
rDropdown.ClearOptions();
rDropdown.AddOptions(strRes.ToList());
rDropdown.RefreshShownValue();
But I would like to remove some unusable screen resolutions that has height < 720. If I use if (res[i].height >= 720)
befor strRes[i] = res[i].width.ToString() + "x" + res[i].height.ToString() + " @ " + res[i].refreshRate.ToString() + "Hz";
than I really can see only resolutions with height =>720. My problem is that in dropdown all resolutions with height <720 make empty space now. Any ideas how one can get rid off those empty gaps? PS Sorry for my poor English:)
Answer by Klarzahs · Oct 13, 2020 at 09:34 AM
Hi @DYV,
Your problem is here strRes = new string[res.Length];
, where you create a fixed length array according to the numbers of resolutions. If you skip then e.g. resolution nr 2, you still have an empty string at this position, ergo your empty gaps in the dropdown.
As you are casting your array to a list anyway, why not directly use a List (see here)? You can then use your if statement from above, only filling in actual resolutions
Your answer
Follow this Question
Related Questions
List of bools assigned to each Gameobject in List/Array 0 Answers
Reading all data in the list with duplicate data inside 1 Answer
Array elements are empty in the inspector? 1 Answer
Simple optimization question on array vs hardcoding. 1 Answer
How can I check if an array slot of empty game objects is empty? 1 Answer