| | 1 | | using System.Collections.Generic; |
| | 2 | | using MainScripts.DCL.Controllers.SettingsDesktop; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace MainScripts.DCL.Controllers.HUD.SettingsPanelHUDDesktop.Scripts |
| | 6 | | { |
| | 7 | | public static class ScreenResolutionUtils |
| | 8 | | { |
| | 9 | | private static Resolution[] resolutions; |
| | 10 | |
|
| | 11 | | // this offset was made for the 0 index to be Full HD instead of MAX |
| 0 | 12 | | public static int DefaultIndex { get; private set; } |
| 0 | 13 | | public static IReadOnlyList<Resolution> Resolutions => resolutions ??= GetResolutions(); |
| | 14 | |
|
| | 15 | | private static Resolution[] GetResolutions() |
| | 16 | | { |
| 0 | 17 | | Resolution[] resolutions = Screen.resolutions; |
| 0 | 18 | | UpdateDefaultIndex(resolutions); |
| 0 | 19 | | return resolutions; |
| | 20 | | } |
| | 21 | |
|
| | 22 | | private static void UpdateDefaultIndex(Resolution[] resolutions) |
| | 23 | | { |
| 0 | 24 | | int resolutionsLength = resolutions.Length; |
| | 25 | |
|
| 0 | 26 | | for (int i = resolutionsLength - 1; i >= 0; i--) |
| | 27 | | { |
| 0 | 28 | | if (resolutions[i].width > 1920) continue; |
| | 29 | |
|
| 0 | 30 | | DefaultIndex = resolutionsLength - 1 - i; |
| | 31 | |
|
| 0 | 32 | | break; |
| | 33 | | } |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | public static void Apply(DisplaySettings displaySettings) |
| | 37 | | { |
| 0 | 38 | | var fullscreenMode = displaySettings.GetFullScreenMode(); |
| | 39 | |
|
| 0 | 40 | | var resolution = GetResolution(displaySettings); |
| 0 | 41 | | Screen.SetResolution(resolution.width, resolution.height, fullscreenMode, resolution.refreshRate); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | // Resolution list goes from the smallest to the biggest, our index is inverted for usage reasons so 0 is the bi |
| | 45 | | private static Resolution GetResolution(DisplaySettings displaySettings) |
| | 46 | | { |
| 0 | 47 | | int resolutionsCount = Resolutions.Count; |
| 0 | 48 | | int settingsIndex = displaySettings.resolutionSizeIndex; |
| 0 | 49 | | if (settingsIndex < 0) settingsIndex = DefaultIndex; |
| 0 | 50 | | return Resolutions[resolutionsCount - 1 - settingsIndex]; |
| | 51 | | } |
| | 52 | | } |
| | 53 | | } |