< Summary

Class:MainScripts.DCL.Controllers.HUD.SettingsPanelHUDDesktop.Scripts.ScreenResolutionUtils
Assembly:SettingsPanelHUDDesktop
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUDDesktop/Scripts/ScreenResolutionUtils.cs
Covered lines:0
Uncovered lines:19
Coverable lines:19
Total lines:53
Line coverage:0% (0 of 19)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GetResolutions()0%2100%
UpdateDefaultIndex(...)0%12300%
Apply(...)0%2100%
GetResolution(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUDDesktop/Scripts/ScreenResolutionUtils.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using MainScripts.DCL.Controllers.SettingsDesktop;
 3using UnityEngine;
 4
 5namespace 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
 012        public static int DefaultIndex { get; private set; }
 013        public static IReadOnlyList<Resolution> Resolutions => resolutions ??= GetResolutions();
 14
 15        private static Resolution[] GetResolutions()
 16        {
 017            Resolution[] resolutions = Screen.resolutions;
 018            UpdateDefaultIndex(resolutions);
 019            return resolutions;
 20        }
 21
 22        private static void UpdateDefaultIndex(Resolution[] resolutions)
 23        {
 024            int resolutionsLength = resolutions.Length;
 25
 026            for (int i = resolutionsLength - 1; i >= 0; i--)
 27            {
 028                if (resolutions[i].width > 1920) continue;
 29
 030                DefaultIndex = resolutionsLength - 1 - i;
 31
 032                break;
 33            }
 034        }
 35
 36        public static void Apply(DisplaySettings displaySettings)
 37        {
 038            var fullscreenMode = displaySettings.GetFullScreenMode();
 39
 040            var resolution = GetResolution(displaySettings);
 041            Screen.SetResolution(resolution.width, resolution.height, fullscreenMode, resolution.refreshRate);
 042        }
 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        {
 047            int resolutionsCount = Resolutions.Count;
 048            int settingsIndex = displaySettings.resolutionSizeIndex;
 049            if (settingsIndex < 0) settingsIndex = DefaultIndex;
 050            return Resolutions[resolutionsCount - 1 - settingsIndex];
 51        }
 52    }
 53}