diff --git a/Assets/src/ResolutionData.cs b/Assets/src/ResolutionData.cs index 91c48f56..2f9c05ba 100644 --- a/Assets/src/ResolutionData.cs +++ b/Assets/src/ResolutionData.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityEngine; public class ResolutionData { @@ -10,7 +11,7 @@ public static int Width { } get { - return (int)ConfigData.Current.Fetch("resolution-width", orSetEqualTo: (int)(Display.main.renderingWidth * 0.75f)); + return (int)ConfigData.Current.Fetch("resolution-width", orSetEqualTo: DefaultResolution().width); } } @@ -20,7 +21,7 @@ public static int Height { } get { - return (int)ConfigData.Current.Fetch("resolution-height", orSetEqualTo: (int)(Display.main.renderingHeight * 0.75f)); + return (int)ConfigData.Current.Fetch("resolution-height", orSetEqualTo: DefaultResolution().height); } } @@ -43,4 +44,19 @@ public static void Apply() { Screen.SetResolution(Width, Height, Fullscreen); #endif } + + private static Resolution DefaultResolution() { + List validResolutions = Screen.resolutions.Where(resolution => + resolution.width <= Display.main.systemWidth && + resolution.height <= Display.main.systemHeight + ).ToList(); + + // Should never happen + if (validResolutions.Count == 0) { + return Screen.resolutions[0]; + } + + // Default to the median supported resolution + return validResolutions[validResolutions.Count / 2]; + } }