private void Awake()
    {
        var comparer = new ResolutionEqualityComparer();
        var current  = display.GetInitializedScreenSize();

        _resolutions = Screen.resolutions
                       .Where(x => x.width % 16 == 0 && x.height % 9 == 0)
                       .Where(x => x.width > minWidth)
                       .Distinct(comparer)
                       .Reverse()
                       .ToArray();

        dropdownMenu.options.Clear();
        for (var i = 0; i < _resolutions.Length; i++)
        {
            var valString = ResToString(_resolutions[i]);
            dropdownMenu.options.Add(new TMP_Dropdown.OptionData(valString));
            if (comparer.Equals(_resolutions[i], current))
            {
                dropdownMenu.SetValueWithoutNotify(i);
                Debug.Log($"Matching Resolution Option is {i}");
            }
        }
        dropdownMenu.RefreshShownValue();
        dropdownMenu.onValueChanged.AddListener(SetResolution);
    }
Exemple #2
0
    private void Awake()
    {
        var comparer = new ResolutionEqualityComparer();

        display.InitWithoutChanging();
        _resolutions = Screen.resolutions
                       .Where(x => x.width % screenRatio.x == 0 && x.height % screenRatio.y == 0)
                       .Where(x => x.width > minScreenWidth)
                       .Distinct(comparer)
                       .Reverse()
                       .ToArray();
        dropdownMenu.onValueChanged.AddListener(SetResolution);
        dropdownMenu.options.Clear();
        var current = display.CurrentScreenSize;

        for (var i = 0; i < _resolutions.Length; i++)
        {
            var valString = ResToString(_resolutions[i]);
            dropdownMenu.options.Add(new TMP_Dropdown.OptionData(valString));
            if (comparer.Equals(_resolutions[i], current))
            {
                dropdownMenu.value = i;
                Log.Info($"Matching Resolution Option is {i}");
            }
        }

        dropdownMenu.RefreshShownValue();
    }