64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using NBC;
|
|
using UnityEngine;
|
|
|
|
namespace NBF.Setting
|
|
{
|
|
/// <summary>
|
|
/// 分辨率设置
|
|
/// </summary>
|
|
[Sort(2)]
|
|
public class ResolutionSetting : MultiOption<Resolution>
|
|
{
|
|
private int _defaultResolution;
|
|
public override string Name => "Resolution";
|
|
public override string Group => SettingsDef.Group.Graphic;
|
|
protected override int DefaultValue => _defaultResolution;
|
|
public override string Tab => SettingsDef.Tab.Graphic;
|
|
|
|
protected override void OnInitialize()
|
|
{
|
|
var supportedResolutions = Screen.resolutions
|
|
.GroupBy(r => $"{r.width}x{r.height}") // 按宽高分组
|
|
.Select(g => g.OrderByDescending(r => r.refreshRateRatio).First())
|
|
.ToArray();
|
|
foreach (var resolution in supportedResolutions)
|
|
{
|
|
if (resolution.width < 720 || resolution.height < 720) continue;
|
|
AddOption($"{resolution.width}x{resolution.height}", resolution);
|
|
Log.Info($"Resolution {resolution.width}x{resolution.height}");
|
|
}
|
|
|
|
TryGetIndex(t =>
|
|
t.width == Screen.currentResolution.width && t.height == Screen.currentResolution.height,
|
|
out _defaultResolution);
|
|
|
|
if (_defaultResolution < 0)
|
|
{
|
|
_defaultResolution = 0;
|
|
}
|
|
}
|
|
|
|
protected override void OnApply()
|
|
{
|
|
var resolution = GetSelectedOption();
|
|
Log.Info($"Screen.fullScreenMode {Screen.fullScreenMode}");
|
|
var mode = FullScreenMode.ExclusiveFullScreen;
|
|
var screenMode = Root.GetSettingOption<FullScreenModeSetting>();
|
|
if (screenMode != null)
|
|
{
|
|
mode = screenMode.GetSelectedOption();
|
|
}
|
|
|
|
if (mode == FullScreenMode.ExclusiveFullScreen)
|
|
{
|
|
Screen.SetResolution(Screen.currentResolution.width, Screen.currentResolution.height, mode);
|
|
}
|
|
else
|
|
{
|
|
Screen.SetResolution(resolution.width, resolution.height, mode);
|
|
}
|
|
}
|
|
}
|
|
} |