设置相关功能脚本呢
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
/// <summary>
|
||||
/// 分辨率设置
|
||||
/// </summary>
|
||||
[Sort(2)]
|
||||
public class ResolutionSetting : MultiOption<Resolution>
|
||||
{
|
||||
private Resolution _defaultResolution;
|
||||
public override string Name => "Resolution";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
protected override Resolution DefaultValue => _defaultResolution;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
_defaultResolution = Screen.currentResolution;
|
||||
var supportedResolutions = Screen.resolutions;
|
||||
|
||||
foreach (var resolution in supportedResolutions)
|
||||
{
|
||||
if (resolution.width < 720 || resolution.height < 720) continue;
|
||||
AddOption($"{resolution.width}x{resolution.height}", resolution);
|
||||
}
|
||||
|
||||
SelectOption(r => AreEqual(r, Screen.currentResolution), defaultIndex: 0);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
var resolution = GetSelectedOption();
|
||||
|
||||
switch (Screen.fullScreenMode)
|
||||
{
|
||||
case FullScreenMode.ExclusiveFullScreen:
|
||||
Screen.SetResolution(Screen.width, Screen.width, FullScreenMode.ExclusiveFullScreen);
|
||||
break;
|
||||
case FullScreenMode.FullScreenWindow:
|
||||
Screen.SetResolution(resolution.width, resolution.height, FullScreenMode.FullScreenWindow);
|
||||
break;
|
||||
case FullScreenMode.MaximizedWindow:
|
||||
Screen.SetResolution(resolution.width, resolution.height, FullScreenMode.MaximizedWindow);
|
||||
break;
|
||||
case FullScreenMode.Windowed:
|
||||
Screen.SetResolution(resolution.width, resolution.height, FullScreenMode.Windowed);
|
||||
break;
|
||||
default:
|
||||
Screen.SetResolution(Screen.width, Screen.width, FullScreenMode.ExclusiveFullScreen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnReset()
|
||||
{
|
||||
SelectOption(r => AreEqual(r, Screen.currentResolution), defaultIndex: 0);
|
||||
}
|
||||
|
||||
|
||||
bool AreEqual(Resolution a, Resolution b)
|
||||
{
|
||||
return a.width == b.width && a.height == b.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user