Skip to content

Commit

Permalink
Default to median supported resolution (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
12joan authored Jan 14, 2025
1 parent a2522f1 commit 071c6d3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Assets/src/ResolutionData.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class ResolutionData {
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -43,4 +44,19 @@ public static void Apply() {
Screen.SetResolution(Width, Height, Fullscreen);
#endif
}

private static Resolution DefaultResolution() {
List<Resolution> 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];
}
}

0 comments on commit 071c6d3

Please sign in to comment.