设置相关功能脚本呢

This commit is contained in:
bob
2025-05-30 17:49:12 +08:00
parent e9ad74b3ea
commit dea58270fa
62 changed files with 1164 additions and 476 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fc7b116a771640d58d650ff79698f301
timeCreated: 1748589438

View File

@@ -0,0 +1,38 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace NBF.Setting
{
/// <summary>
/// 全局各向异性纹理过滤模式
/// </summary>
[Sort(7)]
public class AnisotropicModeSetting : MultiOption<AnisotropicFiltering>
{
public override string Name => "AnisotropicMode";
public override string Group => SettingsDef.Group.Graphic;
protected override AnisotropicFiltering DefaultValue => AnisotropicFiltering.Enable;
protected override void OnInitialize()
{
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
//全局各向异性纹理过滤模式
QualitySettings.anisotropicFiltering = GetSelectedOption();
}
}
protected override void OnReset()
{
SelectOption(DefaultValue);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b96e677183324f5d8d01e786a828c0db
timeCreated: 1748590207

View File

@@ -0,0 +1,31 @@
using UnityEngine;
namespace NBF.Setting
{
[Sort(1)]
public class FullScreenModeSetting : MultiOption<FullScreenMode>
{
public override string Name => "FullScreenMode";
public override string Group => SettingsDef.Group.Graphic;
protected override FullScreenMode DefaultValue => FullScreenMode.ExclusiveFullScreen;
protected override void OnInitialize()
{
AddOption(nameof(FullScreenMode.ExclusiveFullScreen), FullScreenMode.ExclusiveFullScreen);
AddOption(nameof(FullScreenMode.Windowed), FullScreenMode.Windowed);
AddOption(nameof(FullScreenMode.FullScreenWindow), FullScreenMode.FullScreenWindow);
AddOption(nameof(FullScreenMode.MaximizedWindow), FullScreenMode.MaximizedWindow);
SelectOption(DefaultValue);
}
protected override void OnApply()
{
Screen.fullScreenMode = GetSelectedOption();
}
protected override void OnReset()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3a6386dea2d44f3fb004905e688b97d5
timeCreated: 1748588770

View File

@@ -0,0 +1,57 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace NBF.Setting
{
public enum AnisotropicLevelEnum
{
Off = -1,
x2 = 2,
x4 = 4,
x8 = 8,
x16 = 16
}
/// <summary>
/// 全局各向异性过滤限制
/// </summary>
[Sort(8)]
public class GlobalAnisotropicFilteringLimitsSetting : MultiOption<AnisotropicLevelEnum>
{
public override string Name => "GlobalAnisotropicFilteringLimits";
public override string Group => SettingsDef.Group.Graphic;
protected override AnisotropicLevelEnum DefaultValue => AnisotropicLevelEnum.x4;
protected override void OnInitialize()
{
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
var current = QualitySettings.anisotropicFiltering;
var level = GetSelectedOption();
if (current == AnisotropicFiltering.Disable ||
current == AnisotropicFiltering.Enable)
{
Texture.SetGlobalAnisotropicFilteringLimits(-1, -1);
}
else if (current == AnisotropicFiltering.ForceEnable)
{
Texture.SetGlobalAnisotropicFilteringLimits((int)level, (int)level);
}
}
}
protected override void OnReset()
{
SelectOption(DefaultValue);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6937878e8f61426687c62e26252e9258
timeCreated: 1748590403

View File

@@ -0,0 +1,43 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace NBF.Setting
{
public enum MsaaSampleEnum
{
Off = 1,
x2 = 2,
x4 = 4,
x8 = 8
}
[Sort(6)]
public class MsaaSampleSetting : MultiOption<MsaaSampleEnum>
{
public override string Name => "MsaaSample";
public override string Group => SettingsDef.Group.Graphic;
protected override MsaaSampleEnum DefaultValue => MsaaSampleEnum.Off;
protected override void OnInitialize()
{
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
//抗锯齿等级
URPAsset.msaaSampleCount = (int)GetSelectedOption();
URPAsset.supportsHDR = true;
}
}
protected override void OnReset()
{
SelectOption(DefaultValue);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ae51922900c9429cb0de97b473a3429e
timeCreated: 1748589774

View File

@@ -0,0 +1,39 @@
using UnityEngine;
namespace NBF.Setting
{
/// <summary>
/// 画质设置
/// </summary>
[Sort(3)]
public class QualityLevelSetting : MultiOption<int>
{
private int _defaultQualityLevel;
public override string Name => "QualityLevel";
public override string Group => SettingsDef.Group.Graphic;
protected override int DefaultValue => _defaultQualityLevel;
protected override void OnInitialize()
{
var names = QualitySettings.names;
for (int i = 0; i < names.Length; i++)
{
AddOption(names[i], i);
}
_defaultQualityLevel = QualitySettings.GetQualityLevel();
SetIndex(QualitySettings.GetQualityLevel());
}
protected override void OnApply()
{
QualitySettings.SetQualityLevel(GetSelectedOption());
}
protected override void OnReset()
{
SetIndex(_defaultQualityLevel);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 470180f8a41b4856bf3318bc60f2abf1
timeCreated: 1748588124

View File

@@ -0,0 +1,37 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace NBF.Setting
{
[Sort(5)]
public class RenderScaleSetting : RangeOptionFloat
{
public override string Name => "RenderScale";
public override string Group => SettingsDef.Group.Graphic;
public override float MinValue => 0.1f;
public override float MaxValue => 2f;
protected override void OnInitialize()
{
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
//渲染比例
URPAsset.renderScale = GetValue();
}
}
protected override void OnReset()
{
SetValue(1);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e54edac5d4fe4dbda2da5bce433482dc
timeCreated: 1748589449

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 08fa420645764519a7a960565464a708
timeCreated: 1748586208

View File

@@ -0,0 +1,43 @@
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace NBF.Setting
{
public enum TextureQualityEnum
{
FullRes = 0,
HalfRes = 1,
QuarterRes = 2,
EighthRes = 3
}
[Sort(9)]
public class TextureQualitySetting : MultiOption<TextureQualityEnum>
{
public override string Name => "TextureQuality";
public override string Group => SettingsDef.Group.Graphic;
protected override TextureQualityEnum DefaultValue => TextureQualityEnum.FullRes;
protected override void OnInitialize()
{
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
//纹理质量
QualitySettings.globalTextureMipmapLimit = (int)GetSelectedOption();
}
}
protected override void OnReset()
{
SelectOption(DefaultValue);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d7ca1e2468b24b6285be9176ae024864
timeCreated: 1748590058

View File

@@ -0,0 +1,28 @@
using UnityEngine;
namespace NBF.Setting
{
/// <summary>
/// 垂直同步
/// </summary>
[Sort(4)]
public class VSyncSetting : ToggleOption
{
public override string Name => "VSync";
public override string Group => SettingsDef.Group.Graphic;
protected override bool DefaultValue => false;
protected override void OnApply()
{
//垂直同步
QualitySettings.vSyncCount = GetSelectedOption() ? 1 : 0;
}
protected override void OnReset()
{
SelectOption(DefaultValue);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 00628a08aaac416796a4018119e77cc6
timeCreated: 1748585191

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3ca3dc82471a404ea2346559f1e86f12
timeCreated: 1748590614

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 03ec1dd2a17344dcb27d9f06c7dbbc34
timeCreated: 1748590602

View File

@@ -0,0 +1,38 @@
using NBC;
using UnityEngine;
namespace NBF.Setting
{
public enum SettingLanguage
{
English = 10,
French = 14,
Japanese = 22,
Korean = 23,
Russian = 30,
ChineseSimplified = 40,
ChineseTraditional = 41,
}
[Sort(100)]
public class LanguageSetting : MultiOption<SettingLanguage>
{
private SettingLanguage _defaultLanguage;
public override string Name => "Language";
public override string Group => SettingsDef.Group.SoundAndLanguage;
protected override SettingLanguage DefaultValue => _defaultLanguage;
protected override void OnInitialize()
{
_defaultLanguage = (SettingLanguage)Application.systemLanguage;
}
protected override void OnApply()
{
}
protected override void OnReset()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6eb19d962e5644ada69dca074c6e720a
timeCreated: 1748592356