调整目录结构

This commit is contained in:
2025-08-29 09:11:08 +08:00
parent efb64ce7bc
commit 1fff9db9ca
351 changed files with 304 additions and 215 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c12ca701ad9f433d9e6e7eaf04f507d0
timeCreated: 1748570535

View File

@@ -0,0 +1,6 @@
namespace NBF.Setting
{
public abstract class ControllerOption : OptionBase
{
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 75e11d5298cd48718d39a3e2af82472f
timeCreated: 1749634909

View File

@@ -0,0 +1,18 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public abstract class GamepadOption : InputOption
{
protected override bool IsBindingContains(InputBinding binding)
{
var path = binding.path;
if (path.Contains("<Gamepad>"))
{
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 49041e6a08b744038368d7010acf61ea
timeCreated: 1750408186

View File

@@ -0,0 +1,12 @@
using System.Collections.Generic;
using NBF.Setting;
namespace NBF
{
public interface ISettings
{
List<OptionBase> GetOptionsByTab(string group);
IEnumerable<string> GetAllTabs();
T GetSettingOption<T>() where T : OptionBase;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d2cb28b8c7664cc28fe0b0a0a4516704
timeCreated: 1748678126

View File

@@ -0,0 +1,96 @@
using UnityEngine;
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public abstract class InputOption : OptionBase
{
private int _bindingIndex = 0;
public abstract InputAction InputAction { get; }
public int BindingIndex => _bindingIndex;
protected override int DefaultValue => 0;
/// <summary>
/// 保存的值
/// </summary>
protected string InputSaveValue;
public override bool HaveNotApple()
{
return !InputAction.SaveBindingOverridesAsJson().Equals(InputSaveValue);
}
public override void Apply()
{
// 保存绑定
InputSaveValue = InputAction.SaveBindingOverridesAsJson();
PlayerPrefs.SetString(SaveKey, InputSaveValue);
OnApply();
}
public override void Load()
{
for (int i = 0; i < InputAction.bindings.Count; i++)
{
var binding = InputAction.bindings[i];
if (IsBindingContains(binding))
{
_bindingIndex = i;
break;
}
}
var value = PlayerPrefs.GetString(SaveKey, string.Empty);
InputSaveValue = value;
if (!string.IsNullOrEmpty(InputSaveValue))
{
InputAction.LoadBindingOverridesFromJson(InputSaveValue);
}
}
public override void Reset()
{
if (InputAction.bindings[BindingIndex].isComposite)
{
// It's a composite. Remove overrides from part bindings.
for (var i = BindingIndex + 1;
i < InputAction.bindings.Count && InputAction.bindings[i].isPartOfComposite;
++i)
InputAction.RemoveBindingOverride(i);
}
else
{
InputAction.RemoveBindingOverride(BindingIndex);
}
}
public override void Cancel()
{
if (!string.IsNullOrEmpty(InputSaveValue))
{
InputAction.LoadBindingOverridesFromJson(InputSaveValue);
}
else
{
Reset();
}
}
public override string GetDisplayString()
{
if (InputAction != null)
{
return InputAction.GetBindingDisplayString(BindingIndex);
}
return base.GetDisplayString();
}
protected virtual bool IsBindingContains(InputBinding binding)
{
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0df4bee5d9b54ada8be3757d7fe02e30
timeCreated: 1749634814

View File

@@ -0,0 +1,18 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public abstract class KeyBoardOption : InputOption
{
protected override bool IsBindingContains(InputBinding binding)
{
var path = binding.path;
if (path.Contains("<Keyboard>") || path.Contains("<Mouse>"))
{
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 509d2fb0106b42b79854cca29707207d
timeCreated: 1749634771

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace NBF.Setting
{
public interface IMultiOption : IOptionBase
{
List<string> GetOptionNames();
}
public abstract class MultiOption<T> : OptionBase, IMultiOption
{
protected OptionTable<T> OptionTable = new OptionTable<T>();
protected void AddOption(string name, T value)
{
OptionTable.Add(name, value);
}
public List<string> GetOptionNames() => OptionTable.GetNames();
protected void SelectOption(T value, int defaultIndex = 0)
{
SetValue(TryGetIndex(value, out var index) ? index : defaultIndex);
}
protected void SelectOption(Predicate<T> predicate, int defaultIndex = 0)
{
SetValue(TryGetIndex(predicate, out var index) ? index : defaultIndex);
}
protected bool TryGetIndex(T option, out int index)
{
return TryGetIndex(entry => entry.Equals(option), out index);
}
protected bool TryGetIndex(Predicate<T> predicate, out int index)
{
index = -1;
var entries = OptionTable.GetValues();
for (var i = 0; i < entries.Count; i++)
{
if (!predicate(entries[i])) continue;
index = i;
return true;
}
return false;
}
public T GetSelectedOption() => OptionTable.GetValue(Value);
public override string GetDisplayString()
{
return OptionTable.GetName(Value);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5b25650e359243468131db1f9b951ae7
timeCreated: 1748571045

View File

@@ -0,0 +1,115 @@
using UnityEngine;
namespace NBF.Setting
{
public interface IOptionBase
{
string Name { get; }
void Initialize(ISettings root);
void Apply();
int GetValue();
void SetValue(int index);
bool HaveNotApple();
ISettings Root { get; }
string GetDisplayString();
}
public abstract class OptionBase : IOptionBase
{
protected string SaveKey => $"Setting_{Group}_{Name}";
public abstract string Name { get; }
/// <summary>
/// 所在组
/// </summary>
public abstract string Group { get; }
/// <summary>
/// 所在分切页
/// </summary>
public abstract string Tab { get; }
/// <summary>
/// 默认值
/// </summary>
protected abstract int DefaultValue { get; }
/// <summary>
/// 当前的值
/// </summary>
protected int Value;
/// <summary>
/// 保存的值
/// </summary>
protected int SaveValue;
public virtual bool HaveNotApple()
{
return !Value.Equals(SaveValue);
}
public ISettings Root { get; private set; }
public void Initialize(ISettings root)
{
Root = root;
Load();
OnInitialize();
Apply();
}
/// <summary>
/// 加载用户的设置
/// </summary>
public virtual void Load()
{
var value = PlayerPrefs.GetInt(SaveKey, DefaultValue);
Value = value;
SaveValue = value;
}
public virtual void Apply()
{
PlayerPrefs.SetInt(SaveKey, Value);
SaveValue = Value;
OnApply();
}
public virtual void Reset()
{
Value = DefaultValue;
}
public virtual void Cancel()
{
}
public virtual string GetDisplayString()
{
return GetValue().ToString();
}
public virtual int GetValue()
{
return Value;
}
public virtual void SetValue(int value)
{
Value = value;
}
protected virtual void OnInitialize()
{
}
protected abstract void OnApply();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dd2d6f346b1145debf370bc3ac71bd7e
timeCreated: 1748570612

View File

@@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Linq;
namespace NBF.Setting
{
public class OptionTable<T>
{
public struct OptionEntry
{
public string Name;
public T Value;
public OptionEntry(string name, T value)
{
this.Name = name;
this.Value = value;
}
}
List<OptionEntry> entries = new List<OptionEntry>();
public void Add(string name, T value)
{
entries.Add(new OptionEntry(name, value));
}
public List<string> GetNames() => entries.Select(x => x.Name).ToList();
public List<T> GetValues() => entries.Select(x => x.Value).ToList();
public T GetValue(int index)
{
if (entries == null) return default;
if (index < 0 || index >= entries.Count) return default;
return entries[index].Value;
}
public string GetName(int index)
{
if (entries == null) return string.Empty;
if (index < 0 || index >= entries.Count) return string.Empty;
return entries[index].Name;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a7241b5524db446eb4f73ae3a8d7b0ec
timeCreated: 1748571519

View File

@@ -0,0 +1,33 @@
using System;
using System.Globalization;
namespace NBF.Setting
{
/// <summary>
/// 范围设置
/// </summary>
public abstract class RangeOption : OptionBase
{
public abstract int MinValue { get; }
public abstract int MaxValue { get; }
public virtual int ShowRate => 0;
public override void SetValue(int value)
{
if (value > MaxValue) value = MaxValue;
else if (value < MinValue) value = MinValue;
Value = value;
}
public override string GetDisplayString()
{
if (ShowRate > 0)
{
return Math.Round(GetValue() / (ShowRate * 1f), 1).ToString(CultureInfo.InvariantCulture);
}
return base.GetDisplayString();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3531567c76fc48d5939644966fe22057
timeCreated: 1748572844

View File

@@ -0,0 +1,15 @@
namespace NBF.Setting
{
public abstract class ToggleOption : MultiOption<bool>
{
protected override void OnInitialize()
{
AddOption("Off", false);
AddOption("On", true);
SelectOption(DefaultValue == 1);
}
public bool IsEnabled() => GetSelectedOption();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dbcf52430d8b483497f040fe7cbcfa62
timeCreated: 1748572278

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b3f3e6458ad24086b8838b3750453007
timeCreated: 1748585143

View File

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

View File

@@ -0,0 +1,41 @@
using System;
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;
public override string Tab => SettingsDef.Tab.Graphic;
protected override int DefaultValue => (int)AnisotropicFiltering.Enable;
protected override void OnInitialize()
{
var enumValues = Enum.GetValues(typeof(AnisotropicFiltering));
foreach (var value in enumValues)
{
AddOption(value.ToString(), (AnisotropicFiltering)value);
}
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
//全局各向异性纹理过滤模式
QualitySettings.anisotropicFiltering = GetSelectedOption();
}
}
}
}

View File

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

View File

@@ -0,0 +1,27 @@
using UnityEngine;
namespace NBF.Setting
{
[Sort(1)]
public class FullScreenModeSetting : MultiOption<FullScreenMode>
{
public override string Name => "FullScreenMode";
public override string Group => SettingsDef.Group.Graphic;
public override string Tab => SettingsDef.Tab.Graphic;
protected override int DefaultValue => (int)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);
}
protected override void OnApply()
{
// Screen.fullScreenMode = GetSelectedOption();
// Debug.Log($"FullScreenMode: {Screen.fullScreenMode} value: {GetSelectedOption()}");
}
}
}

View File

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

View File

@@ -0,0 +1,59 @@
using System;
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;
public override string Tab => SettingsDef.Tab.Graphic;
protected override int DefaultValue => (int)AnisotropicLevelEnum.x4;
protected override void OnInitialize()
{
var enumValues = Enum.GetValues(typeof(AnisotropicLevelEnum));
foreach (var value in enumValues)
{
AddOption(value.ToString(), (AnisotropicLevelEnum)value);
}
}
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);
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,46 @@
using System;
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;
public override string Tab => SettingsDef.Tab.Graphic;
protected override int DefaultValue => (int)MsaaSampleEnum.Off;
protected override void OnInitialize()
{
var enumValues = Enum.GetValues(typeof(MsaaSampleEnum));
foreach (var value in enumValues)
{
AddOption(value.ToString(), (MsaaSampleEnum)value);
}
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
//抗锯齿等级
URPAsset.msaaSampleCount = (int)GetSelectedOption();
URPAsset.supportsHDR = true;
}
}
}
}

View File

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

View File

@@ -0,0 +1,34 @@
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;
public override string Tab => SettingsDef.Tab.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();
}
protected override void OnApply()
{
QualitySettings.SetQualityLevel(GetSelectedOption());
}
}
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,64 @@
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);
}
}
}
}

View File

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

View File

@@ -0,0 +1,45 @@
using System;
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 int DefaultValue => (int)TextureQualityEnum.FullRes;
public override string Tab => SettingsDef.Tab.Graphic;
protected override void OnInitialize()
{
var enumValues = Enum.GetValues(typeof(TextureQualityEnum));
foreach (var value in enumValues)
{
AddOption(value.ToString(), (TextureQualityEnum)value);
}
}
protected override void OnApply()
{
// 获取当前URP Asset
UniversalRenderPipelineAsset URPAsset =
QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as
UniversalRenderPipelineAsset;
if (URPAsset)
{
//纹理质量
QualitySettings.globalTextureMipmapLimit = (int)GetSelectedOption();
}
}
}
}

View File

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

View File

@@ -0,0 +1,23 @@
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;
public override string Tab => SettingsDef.Tab.Graphic;
protected override int DefaultValue => 0;
protected override void OnApply()
{
//垂直同步
QualitySettings.vSyncCount = GetSelectedOption() ? 1 : 0;
}
}
}

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f72256d425749e3a05fd57c209d057d
timeCreated: 1749539093

View File

@@ -0,0 +1,17 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public class InputAddBobSetting : KeyBoardOption
{
public override string Name => "InputAddBob";
public override string Group => SettingsDef.Group.Keyboard;
public override string Tab => SettingsDef.Tab.Keyboard;
public override InputAction InputAction => InputManager.PlayerInputControl.Player.AddBob;
protected override void OnApply()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 673bfd453717403998342a57e58b9b3a
timeCreated: 1749634714

View File

@@ -0,0 +1,19 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public class InputChatSetting : KeyBoardOption
{
private int _defaultKey;
public override string Name => "InputChat";
public override string Group => SettingsDef.Group.Keyboard;
public override string Tab => SettingsDef.Tab.Keyboard;
public override InputAction InputAction => InputManager.PlayerInputControl.Player.Chat;
protected override void OnApply()
{
// PlayerInputControl.PlayerActions
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a63f66ee0a384cf0a163c33dfa2f3c36
timeCreated: 1750308320

View File

@@ -0,0 +1,18 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public class InputHelpSetting : KeyBoardOption
{
public override string Name => "InputHelp";
public override string Group => SettingsDef.Group.Keyboard;
public override string Tab => SettingsDef.Tab.Keyboard;
public override InputAction InputAction => InputManager.PlayerInputControl.Player.Help;
protected override void OnApply()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b77e15344964a9ab0b1ecafcad3d03d
timeCreated: 1750308298

View File

@@ -0,0 +1,17 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public class InputSubBobSetting : KeyBoardOption
{
public override string Name => "InputSubBob";
public override string Group => SettingsDef.Group.Keyboard;
public override string Tab => SettingsDef.Tab.Keyboard;
public override InputAction InputAction => InputManager.PlayerInputControl.Player.SubBob;
protected override void OnApply()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ea72a2c910474d5ca4e96d2c881797d8
timeCreated: 1750307386

View File

@@ -0,0 +1,17 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public class InputToBagSetting : KeyBoardOption
{
public override string Name => "InputToBag";
public override string Group => SettingsDef.Group.Keyboard;
public override string Tab => SettingsDef.Tab.Keyboard;
public override InputAction InputAction => InputManager.PlayerInputControl.Player.ToBag;
protected override void OnApply()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 906eac0772874939a5223e1115d5dfe0
timeCreated: 1750308244

View File

@@ -0,0 +1,19 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public class InputUseTelescopeSetting : KeyBoardOption
{
public override string Name => "InputUseTelescope";
public override string Group => SettingsDef.Group.Keyboard;
public override string Tab => SettingsDef.Tab.Keyboard;
public override InputAction InputAction => InputManager.PlayerInputControl.Player.UseTelescope;
protected override void OnApply()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 24089404fdb7424284ecafcd23d1537f
timeCreated: 1750308215

View File

@@ -0,0 +1,18 @@
using UnityEngine.InputSystem;
namespace NBF.Setting
{
public class InputUseTorchSetting : KeyBoardOption
{
public override string Name => "InputUseTorch";
public override string Group => SettingsDef.Group.Keyboard;
public override string Tab => SettingsDef.Tab.Keyboard;
public override InputAction InputAction => InputManager.PlayerInputControl.Player.UseTorch;
protected override void OnApply()
{
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 12a79769a6534afa8212293adfa1e48a
timeCreated: 1750307422

View File

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

View File

@@ -0,0 +1,48 @@
using NBC;
using UnityEngine;
namespace NBF.Setting
{
[Sort(100)]
public class LanguageSetting : MultiOption<int>
{
private int _defaultLanguage;
public override string Name => "Language";
public override string Group => SettingsDef.Group.Language;
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
protected override int DefaultValue => (int)_defaultLanguage;
protected override void OnInitialize()
{
var list = LanguageConst.LanguageList;
var systemLanguage = Application.systemLanguage;
var systemIndex = list.FindIndex(t => t.Language == systemLanguage);
if (systemIndex < 0)
{
systemIndex = 0;
}
_defaultLanguage = (int)Lan.Inst.GetCurrentLanguage();
for (int i = 0; i < list.Count; i++)
{
var lang = list[i];
AddOption(lang.Name, i);
}
_defaultLanguage = systemIndex;
var current = GetValue();
if (current < 0 || current >= LanguageConst.LanguageList.Count)
{
SetValue(_defaultLanguage);
}
}
protected override void OnApply()
{
var lang = LanguageConst.LanguageList[GetValue()];
Lan.Inst.UseLanguage(lang.Language);
}
}
}

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab9087f7f0a74aaa8a8824e2ec55657d
timeCreated: 1749537412

View File

@@ -0,0 +1,26 @@
using NBC;
namespace NBF.Setting
{
[Sort(3)]
public class AmbientVolumeSetting : RangeOption
{
public override string Name => "AmbientVolume";
public override string Group => SettingsDef.Group.Sound;
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
public override int MinValue => 0;
public override int MaxValue => 100;
protected override int DefaultValue => 100;
protected override void OnInitialize()
{
// SetValue(10);
}
protected override void OnApply()
{
SoundManager.Inst.SetVolume(AudioChannelType.Ambient, GetValue() / 100f);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e841f4c4a4954318b67235033e58576b
timeCreated: 1749537896

View File

@@ -0,0 +1,26 @@
using NBC;
namespace NBF.Setting
{
[Sort(1)]
public class MasterVolumeSetting : RangeOption
{
public override string Name => "MasterVolume";
public override string Group => SettingsDef.Group.Sound;
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
public override int MinValue => 0;
public override int MaxValue => 100;
protected override int DefaultValue => 100;
protected override void OnInitialize()
{
// SetValue(10);
}
protected override void OnApply()
{
SoundManager.Inst.SetMasterVolume(GetValue() / 100f);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0e2fca480fb44b0a8d38fd15d2ef1413
timeCreated: 1749537486

View File

@@ -0,0 +1,26 @@
using NBC;
namespace NBF.Setting
{
[Sort(2)]
public class PlayerVolumeSetting : RangeOption
{
public override string Name => "PlayerVolume";
public override string Group => SettingsDef.Group.Sound;
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
public override int MinValue => 0;
public override int MaxValue => 100;
protected override int DefaultValue => 100;
protected override void OnInitialize()
{
// SetValue(10);
}
protected override void OnApply()
{
SoundManager.Inst.SetVolume(AudioChannelType.Player, GetValue() / 100f);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3f421f4166fe4bd3a31c78f5a8e47364
timeCreated: 1749537942

View File

@@ -0,0 +1,26 @@
using NBC;
namespace NBF.Setting
{
[Sort(4)]
public class UIVolumeSetting : RangeOption
{
public override string Name => "UIVolume";
public override string Group => SettingsDef.Group.Sound;
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
public override int MinValue => 0;
public override int MaxValue => 100;
protected override int DefaultValue => 100;
protected override void OnInitialize()
{
// SetValue(10);
}
protected override void OnApply()
{
SoundManager.Inst.SetVolume(AudioChannelType.UI, GetValue() / 100f);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0a63098af5bd4b36929f75a58e2a5159
timeCreated: 1749537834

View File

@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NBF.Setting;
namespace NBF
{
public class Settings : MonoService<Settings>, ISettings
{
private readonly Dictionary<string, List<OptionBase>> _dictionary = new Dictionary<string, List<OptionBase>>();
protected override void OnAwake()
{
List<OptionBase> list = new List<OptionBase>();
var options = Reflection.GetAllNonAbstractDerivedTypes<OptionBase>();
foreach (var option in options)
{
var settingOption = Activator.CreateInstance(option);
if (settingOption is OptionBase optionSetting)
{
list.Add(optionSetting);
optionSetting.Initialize(this);
}
}
list.SortBySortAttribute();
AddRangeToTab(list);
}
public void LoadAllSettings()
{
foreach (var list in _dictionary.Values)
{
foreach (var option in list)
{
option.Load();
}
}
}
/// <summary>
/// 是否有未保存的设置
/// </summary>
public bool HaveNotAppleSettings()
{
return _dictionary.Values.SelectMany(list => list).Any(option => option.HaveNotApple());
}
#region
public T GetSettingOption<T>() where T : OptionBase
{
foreach (var option in _dictionary.Values.SelectMany(options => options))
{
if (option is T optionSetting)
{
return optionSetting;
}
}
return null;
}
/// <summary>
/// 获取指定 Tab 的所有 OptionBase
/// </summary>
public List<OptionBase> GetOptionsByTab(string group)
{
if (string.IsNullOrEmpty(group))
{
throw new ArgumentException("Tab name cannot be null or empty.");
}
return _dictionary.TryGetValue(group, out var options) ? options : new List<OptionBase>();
}
/// <summary>
/// 获取所有 Tab 名字列表
/// </summary>
public IEnumerable<string> GetAllTabs()
{
return _dictionary.Keys;
}
/// <summary>
/// 将 OptionBase 按 Tab 分类存入字典
/// </summary>
private void AddToTab(OptionBase option)
{
if (option == null) return;
if (string.IsNullOrEmpty(option.Tab)) return;
// 如果字典中没有该 Tab则新建一个 List 并加入字典
if (!_dictionary.ContainsKey(option.Tab))
{
_dictionary[option.Tab] = new List<OptionBase>();
}
// 将 Option 添加到对应的 Tab List 中
_dictionary[option.Tab].Add(option);
}
/// <summary>
/// 批量添加 OptionBase 到字典
/// </summary>
private void AddRangeToTab(IEnumerable<OptionBase> options)
{
if (options == null) return;
foreach (var option in options)
{
AddToTab(option);
}
}
#endregion
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ae00ae2fd4474db3af9dc52692900f94
timeCreated: 1748489275

View File

@@ -0,0 +1,22 @@
namespace NBF
{
public static class SettingsDef
{
public static class Group
{
public const string Graphic = "Graphic";
public const string Keyboard = "Keyboard";
public const string Controller = "Controller";
public const string Language = "Language";
public const string Sound = "Sound";
}
public static class Tab
{
public const string Graphic = "Graphic";
public const string Keyboard = "Keyboard";
public const string Controller = "Controller";
public const string SoundAndLanguage = "SoundAndLanguage";
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 071c8f83b867467e9a4af17e3d474ab0
timeCreated: 1748585459