3 using System.Collections.Generic;
7 namespace HKI.Core.UI.Settings
12 [RequireComponent(typeof(TMP_Dropdown))]
19 TMP_Dropdown dropdown = null;
21 List<IntWidthHeight> resolutions =
new List<IntWidthHeight>();
26 dropdown = GetComponent<TMP_Dropdown>();
32 if(Resolution != null)
34 Resolution[] res = Screen.resolutions;
35 for (
int i = 0; i < res.Length; i++)
37 if(resolutions.FindIndex(x => x.Width == res[i].width && x.Height == res[i].height) < 0)
38 resolutions.Add(
new IntWidthHeight() { Width = res[i].width, Height = res[i].height });
41 List<TMP_Dropdown.OptionData> list =
new List<TMP_Dropdown.OptionData>();
42 int currentResolutionIndex = 0;
43 Resolution currentResolution = Screen.currentResolution;
44 for(
int i = 0; i < resolutions.Count; i++)
46 list.Add(
new TMP_Dropdown.OptionData(resolutions[i].Width.ToString() +
" x " + resolutions[i].Height.ToString()));
48 if (resolutions[i].Width == currentResolution.width && resolutions[i].Height == currentResolution.height)
49 currentResolutionIndex = i;
52 dropdown.ClearOptions();
53 dropdown.AddOptions(list);
55 dropdown.value = currentResolutionIndex;
58 Debug.LogError(
"(UIResolutionDropdown) Resolution value is null!");
64 if(Resolution != null)
65 Resolution.
SetValue = resolutions[dropdown.value];
70 Resolution[] res = Screen.resolutions;
71 for (
int i = 0; i < res.Length; i++)
73 if (resolutions.FindIndex(x => x.Width == res[i].width && x.Height == res[i].height) < 0)
74 resolutions.Add(
new IntWidthHeight() { Width = res[i].width, Height = res[i].height });
77 List<TMP_Dropdown.OptionData> list =
new List<TMP_Dropdown.OptionData>();
78 int currentResolutionIndex = 0;
79 Resolution currentResolution = Screen.currentResolution;
80 for (
int i = 0; i < resolutions.Count; i++)
82 list.Add(
new TMP_Dropdown.OptionData(resolutions[i].Width.ToString() +
" x " + resolutions[i].Height.ToString()));
84 if (resolutions[i].Width == currentResolution.width && resolutions[i].Height == currentResolution.height)
85 currentResolutionIndex = i;
88 dropdown.ClearOptions();
89 dropdown.AddOptions(list);
91 dropdown.value = currentResolutionIndex;
This is a data type that combines a int width and a int height value into one value. This can be used for storing resolution information.
void SetResolutionToDropdownValue()
This MonoBehaviour fills and handles a dropdown (TMP_Dropdown) with resolution settings.
Implementation of a IntegerWidthHeight value as a HKIVar via HKIVarGeneric.