diff --git a/Assets/Resources/Fgui/Main/Main_fui.bytes b/Assets/Resources/Fgui/Main/Main_fui.bytes index bc8a5c019..aba22cfe0 100644 Binary files a/Assets/Resources/Fgui/Main/Main_fui.bytes and b/Assets/Resources/Fgui/Main/Main_fui.bytes differ diff --git a/Assets/Scripts/Common/Attrobites/Attributes.cs b/Assets/Scripts/Common/Attrobites/Attributes.cs index 3b70a1325..74d54fa3f 100644 --- a/Assets/Scripts/Common/Attrobites/Attributes.cs +++ b/Assets/Scripts/Common/Attrobites/Attributes.cs @@ -2,12 +2,10 @@ namespace NBF { - public abstract class BaseAttribute : Attribute { - } - + [AttributeUsage(AttributeTargets.Field)] public class InputIconAttribute : BaseAttribute { @@ -48,4 +46,15 @@ namespace NBF Description = description; } } + + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, AllowMultiple = true)] + public class SortAttribute : BaseAttribute + { + public int Sort; + + public SortAttribute(int sort) + { + Sort = sort; + } + } } \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base.meta b/Assets/Scripts/Common/Services/Settings/Base.meta new file mode 100644 index 000000000..8b759ef04 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c12ca701ad9f433d9e6e7eaf04f507d0 +timeCreated: 1748570535 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs b/Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs new file mode 100644 index 000000000..8398a6464 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; + +namespace NBF.Setting +{ + public interface IMultiOption : IOptionBase + { + List GetOptionNames(); + int GetIndex(); + void SetIndex(int index); + string GetName(); + } + + public abstract class MultiOption : OptionBase, IMultiOption + { + private int _index; + + protected OptionTable OptionTable = new OptionTable(); + + /// + /// 默认值 + /// + protected abstract T DefaultValue { get; } + + protected override void OnLoad() + { + + } + + protected void AddOption(string name, T value) + { + OptionTable.Add(name, value); + } + + public List GetOptionNames() => OptionTable.GetNames(); + + public string GetName() + { + return OptionTable.GetName(_index); + } + + public int GetIndex() + { + return _index; + } + + public void SetIndex(int index) + { + _index = index; + } + + protected void SelectOption(T value, int defaultIndex = 0) + { + SetIndex(TryGetIndex(value, out var index) ? index : defaultIndex); + } + + protected void SelectOption(Predicate predicate, int defaultIndex = 0) + { + SetIndex(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 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(_index); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs.meta b/Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs.meta new file mode 100644 index 000000000..0d34e1153 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5b25650e359243468131db1f9b951ae7 +timeCreated: 1748571045 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs b/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs new file mode 100644 index 000000000..bba156c27 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs @@ -0,0 +1,49 @@ +namespace NBF.Setting +{ + public interface IOptionBase + { + string Name { get; } + void Initialize(); + void Apply(); + } + + public abstract class OptionBase : IOptionBase + { + protected string SaveKey => $"Setting_{Group}_{Name}"; + + public abstract string Name { get; } + + /// + /// 所在组 + /// + public abstract string Group { get; } + + public void Initialize() + { + OnInitialize(); + Load(); + } + + /// + /// 加载用户的设置 + /// + public void Load() + { + OnLoad(); + } + + public void Apply() + { + OnApply(); + } + + protected abstract void OnInitialize(); + + + protected abstract void OnApply(); + + protected abstract void OnReset(); + + protected abstract void OnLoad(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs.meta b/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs.meta new file mode 100644 index 000000000..18ed6a0fa --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dd2d6f346b1145debf370bc3ac71bd7e +timeCreated: 1748570612 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs b/Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs new file mode 100644 index 000000000..880d94497 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs @@ -0,0 +1,34 @@ +using System.Collections.Generic; +using System.Linq; + +namespace NBF.Setting +{ + public class OptionTable + { + public struct OptionEntry + { + public string Name; + public T Value; + + public OptionEntry(string name, T value) + { + this.Name = name; + this.Value = value; + } + } + + List entries = new List(); + + public void Add(string name, T value) + { + entries.Add(new OptionEntry(name, value)); + } + + public List GetNames() => entries.Select(x => x.Name).ToList(); + public List GetValues() => entries.Select(x => x.Value).ToList(); + + public T GetValue(int index) => entries[index].Value; + + public string GetName(int index) => entries != null ? entries[index].Name : string.Empty; + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs.meta b/Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs.meta new file mode 100644 index 000000000..bf20a039b --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a7241b5524db446eb4f73ae3a8d7b0ec +timeCreated: 1748571519 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs b/Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs new file mode 100644 index 000000000..ff1d05eb7 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs @@ -0,0 +1,55 @@ +namespace NBF.Setting +{ + /// + /// 范围设置 + /// + public abstract class RangeOption : OptionBase + { + private int _value; + public abstract int MinValue { get; } + public abstract int MaxValue { get; } + + public int GetValue() + { + return _value; + } + + public void SetValue(int value) + { + if (value > MaxValue) value = MaxValue; + else if (value < MinValue) value = MinValue; + _value = value; + } + + protected override void OnLoad() + { + } + } + + + /// + /// 范围设置 + /// + public abstract class RangeOptionFloat : OptionBase + { + private float _value; + public abstract float MinValue { get; } + public abstract float MaxValue { get; } + + public float GetValue() + { + return _value; + } + + public void SetValue(float value) + { + if (value > MaxValue) value = MaxValue; + else if (value < MinValue) value = MinValue; + _value = value; + } + + protected override void OnLoad() + { + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs.meta b/Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs.meta new file mode 100644 index 000000000..81748a6a1 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3531567c76fc48d5939644966fe22057 +timeCreated: 1748572844 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs b/Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs new file mode 100644 index 000000000..f76907352 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs @@ -0,0 +1,15 @@ +namespace NBF.Setting +{ + public abstract class ToggleOption : MultiOption + { + protected override void OnInitialize() + { + AddOption("Off", false); + AddOption("On", true); + + SelectOption(DefaultValue); + } + + public bool IsEnabled() => GetSelectedOption(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs.meta b/Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs.meta new file mode 100644 index 000000000..b97b9e88b --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: dbcf52430d8b483497f040fe7cbcfa62 +timeCreated: 1748572278 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/GameSettings.cs b/Assets/Scripts/Common/Services/Settings/GameSettings.cs deleted file mode 100644 index ecacfa200..000000000 --- a/Assets/Scripts/Common/Services/Settings/GameSettings.cs +++ /dev/null @@ -1,301 +0,0 @@ -using Newtonsoft.Json; -using UnityEngine; -using UnityEngine.Rendering; -using UnityEngine.Rendering.Universal; - -namespace NBF -{ - public class GameSettings : MonoService - { - public enum QualityEnum - { - Low = 0, - Medium = 1, - High = 2, - Ultra = 3 - } - - public enum VSyncEnum - { - Off = 0, - On = 1, - } - - /// - /// 抗锯齿等级 - /// - public enum AntiAliasLevelEnum - { - Off = 1, - x2 = 2, - x4 = 4, - x8 = 8 - } - - /// - /// 贴图质量 - /// - public enum TextureQualityEnum - { - FullRes = 0, - HalfRes = 1, - QuarterRes = 2, - EighthRes = 3 - } - - public enum AnisotropicLevelEnum - { - Off = -1, - x2 = 2, - x4 = 4, - x8 = 8, - x16 = 16 - } - - public enum ShadowmapResolutionEnum - { - Low = 0, - Medium = 1, - High = 2, - } - - public const string SaveKey = "PlayerGameSetting"; - - [System.Serializable] - public class GameSettingsData - { - /// - /// 质量等级 0 1 2 3 - /// - // [Title("Settings_Title_quality")] [Description("Settings_Description_quality")] - [Title("图像质量")] [Description("图像质量324234图像质量图像质量图像质量图像质量3434")] - public QualityEnum QualityLevel = QualityEnum.High; - - /// - /// 显示分辨率,有任意一个为0,则为全屏 - /// - [Title("Settings_Title_Resolution")] [Description("Settings_Description_Resolution")] - public Vector2Int Resolution = new Vector2Int(0, 0); - - /// - /// 渲染比例 - /// - [Title("Settings_Title_RenderScale")] [Description("Settings_Description_RenderScale")] [Range(0.1f, 2f)] - public float RenderScale = 1f; - - /// - /// 窗口模式 - /// - [Title("Settings_Title_WindowedMode")] [Description("Settings_Description_WindowedMode")] - public FullScreenMode WindowedMode = FullScreenMode.MaximizedWindow; - - /// - /// 垂直同步个数 - /// - [Title("Settings_Title_VSync")] [Description("Settings_Description_VSync")] - public VSyncEnum VSync = VSyncEnum.Off; - - /// - ///抗锯齿等级 - /// - [Title("Settings_Title_AntiAliasLevel")] [Description("Settings_Description_AntiAliasLevel")] - public AntiAliasLevelEnum AntiAliasLevel = AntiAliasLevelEnum.Off; - - /// - /// 纹理质量 - /// - [Title("Settings_Title_TextureQuality")] [Description("Settings_Description_TextureQuality")] - public TextureQualityEnum TextureQuality = TextureQualityEnum.FullRes; - - /// - /// 全局各向异性纹理过滤模式 - /// - [Title("Settings_Title_AnisotropicMode")] [Description("Settings_Description_AnisotropicMode")] - public AnisotropicFiltering AnisotropicMode = AnisotropicFiltering.Enable; - - /// - /// 全局各向异性过滤限制 - /// - [Title("Settings_Description_AnisotropicLevel")] [Description("Settings_Description_AnisotropicLevel")] - public AnisotropicLevelEnum AnisotropicLevel = AnisotropicLevelEnum.x4; - - /// - /// 阴影等级 - /// - [Title("Settings_Description_ShadowmapResolution")] - [Description("Settings_Description_ShadowmapResolution")] - public ShadowmapResolutionEnum ShadowmapResolution = ShadowmapResolutionEnum.High; - } - - /// - /// 默认配置 - /// - private GameSettingsData DefaultSettingsConverted = new GameSettingsData(); - - /// - /// 当前正在调整的配置 - /// - private GameSettingsData CurrentSettings = new GameSettingsData(); - - /// - /// 当前使用配置 - /// - public readonly GameSettingsData UseSettings = new GameSettingsData(); - - protected override void OnAwake() - { - LoadSettings(); - } - - /// - /// 重置 - /// - public void ResetSettings() - { - CurrentSettings.QualityLevel = DefaultSettingsConverted.QualityLevel; - CurrentSettings.Resolution = DefaultSettingsConverted.Resolution; - CurrentSettings.RenderScale = DefaultSettingsConverted.RenderScale; - CurrentSettings.WindowedMode = DefaultSettingsConverted.WindowedMode; - CurrentSettings.VSync = DefaultSettingsConverted.VSync; - CurrentSettings.AntiAliasLevel = DefaultSettingsConverted.AntiAliasLevel; - CurrentSettings.TextureQuality = DefaultSettingsConverted.TextureQuality; - CurrentSettings.AnisotropicMode = DefaultSettingsConverted.AnisotropicMode; - CurrentSettings.AnisotropicLevel = DefaultSettingsConverted.AnisotropicLevel; - CurrentSettings.ShadowmapResolution = DefaultSettingsConverted.ShadowmapResolution; - } - - /// - /// 开始进入设置模式,将当前使用的配置缓存一份 - /// - public void BeginChangeSettings() - { - UseSettings.QualityLevel = CurrentSettings.QualityLevel; - UseSettings.Resolution = CurrentSettings.Resolution; - UseSettings.RenderScale = CurrentSettings.RenderScale; - UseSettings.WindowedMode = CurrentSettings.WindowedMode; - UseSettings.VSync = CurrentSettings.VSync; - UseSettings.AntiAliasLevel = CurrentSettings.AntiAliasLevel; - UseSettings.TextureQuality = CurrentSettings.TextureQuality; - UseSettings.AnisotropicMode = CurrentSettings.AnisotropicMode; - UseSettings.AnisotropicLevel = CurrentSettings.AnisotropicLevel; - UseSettings.ShadowmapResolution = CurrentSettings.ShadowmapResolution; - } - - /// - /// 保存设置 - /// - public void SaveSettings() - { - CurrentSettings.QualityLevel = UseSettings.QualityLevel; - CurrentSettings.Resolution = UseSettings.Resolution; - CurrentSettings.RenderScale = UseSettings.RenderScale; - CurrentSettings.WindowedMode = UseSettings.WindowedMode; - CurrentSettings.VSync = UseSettings.VSync; - CurrentSettings.AntiAliasLevel = UseSettings.AntiAliasLevel; - CurrentSettings.TextureQuality = UseSettings.TextureQuality; - CurrentSettings.AnisotropicMode = UseSettings.AnisotropicMode; - CurrentSettings.AnisotropicLevel = UseSettings.AnisotropicLevel; - CurrentSettings.ShadowmapResolution = UseSettings.ShadowmapResolution; - - - var json = JsonConvert.SerializeObject(CurrentSettings); - PlayerPrefs.SetString(SaveKey, json); - } - - private void LoadSettings() - { - ResetSettings(); - if (PlayerPrefs.HasKey(SaveKey)) - { - var json = PlayerPrefs.GetString(SaveKey, string.Empty); - if (!string.IsNullOrEmpty(json)) - { - var settings = JsonConvert.DeserializeObject(json); - if (settings != null) - { - CurrentSettings.QualityLevel = settings.QualityLevel; - CurrentSettings.Resolution = settings.Resolution; - CurrentSettings.RenderScale = settings.RenderScale; - CurrentSettings.WindowedMode = settings.WindowedMode; - CurrentSettings.VSync = settings.VSync; - CurrentSettings.AntiAliasLevel = settings.AntiAliasLevel; - CurrentSettings.TextureQuality = settings.TextureQuality; - CurrentSettings.AnisotropicMode = settings.AnisotropicMode; - CurrentSettings.AnisotropicLevel = settings.AnisotropicLevel; - CurrentSettings.ShadowmapResolution = settings.ShadowmapResolution; - } - } - } - - if (CurrentSettings.Resolution.x < 1 || CurrentSettings.Resolution.y < 1) - { - CurrentSettings.WindowedMode = FullScreenMode.ExclusiveFullScreen; - CurrentSettings.Resolution = new Vector2Int(Screen.width, Screen.height); - } - - ApplySettings(); - } - - /// - /// 应用设置 - /// - private void ApplySettings() - { - // // 设置当前质量等级 - QualitySettings.SetQualityLevel((int)CurrentSettings.QualityLevel); - - switch (CurrentSettings.WindowedMode) - { - case FullScreenMode.ExclusiveFullScreen: - Screen.SetResolution(Screen.width, Screen.width, FullScreenMode.ExclusiveFullScreen); - break; - case FullScreenMode.FullScreenWindow: - Screen.SetResolution(CurrentSettings.Resolution.x, CurrentSettings.Resolution.y, - FullScreenMode.FullScreenWindow); - break; - case FullScreenMode.MaximizedWindow: - Screen.SetResolution(CurrentSettings.Resolution.x, CurrentSettings.Resolution.y, - FullScreenMode.MaximizedWindow); - break; - case FullScreenMode.Windowed: - Screen.SetResolution(CurrentSettings.Resolution.x, CurrentSettings.Resolution.y, - FullScreenMode.Windowed); - break; - default: - Screen.SetResolution(Screen.width, Screen.width, FullScreenMode.ExclusiveFullScreen); - break; - } - - - // 获取当前URP Asset - UniversalRenderPipelineAsset URPAsset = - QualitySettings.GetRenderPipelineAssetAt(QualitySettings.GetQualityLevel()) as - UniversalRenderPipelineAsset; - if (URPAsset) - { - //渲染比例 - URPAsset.renderScale = CurrentSettings.RenderScale; - //抗锯齿等级 - URPAsset.msaaSampleCount = (int)CurrentSettings.AntiAliasLevel; - URPAsset.supportsHDR = true; - //纹理质量 - QualitySettings.globalTextureMipmapLimit = (int)CurrentSettings.TextureQuality; - - QualitySettings.anisotropicFiltering = CurrentSettings.AnisotropicMode; - if (CurrentSettings.AnisotropicMode == AnisotropicFiltering.Disable || - CurrentSettings.AnisotropicMode == AnisotropicFiltering.Enable) - { - Texture.SetGlobalAnisotropicFilteringLimits(-1, -1); - } - else if (CurrentSettings.AnisotropicMode == AnisotropicFiltering.ForceEnable) - { - Texture.SetGlobalAnisotropicFilteringLimits((int)CurrentSettings.AnisotropicLevel, - (int)CurrentSettings.AnisotropicLevel); - } - - //垂直同步 - QualitySettings.vSyncCount = (int)CurrentSettings.VSync; - } - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options.meta b/Assets/Scripts/Common/Services/Settings/Options.meta new file mode 100644 index 000000000..dd63ea041 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b3f3e6458ad24086b8838b3750453007 +timeCreated: 1748585143 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics.meta new file mode 100644 index 000000000..040c07038 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fc7b116a771640d58d650ff79698f301 +timeCreated: 1748589438 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/AnisotropicModeSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/AnisotropicModeSetting.cs new file mode 100644 index 000000000..7712853ba --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/AnisotropicModeSetting.cs @@ -0,0 +1,38 @@ +using UnityEngine; +using UnityEngine.Rendering.Universal; + +namespace NBF.Setting +{ + /// + /// 全局各向异性纹理过滤模式 + /// + [Sort(7)] + public class AnisotropicModeSetting : MultiOption + { + 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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/AnisotropicModeSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/AnisotropicModeSetting.cs.meta new file mode 100644 index 000000000..42c88760f --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/AnisotropicModeSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b96e677183324f5d8d01e786a828c0db +timeCreated: 1748590207 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/FullScreenModeSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/FullScreenModeSetting.cs new file mode 100644 index 000000000..781351a93 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/FullScreenModeSetting.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +namespace NBF.Setting +{ + [Sort(1)] + public class FullScreenModeSetting : MultiOption + { + 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() + { + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/FullScreenModeSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/FullScreenModeSetting.cs.meta new file mode 100644 index 000000000..b50c95c84 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/FullScreenModeSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3a6386dea2d44f3fb004905e688b97d5 +timeCreated: 1748588770 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/GlobalAnisotropicFilteringLimitsSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/GlobalAnisotropicFilteringLimitsSetting.cs new file mode 100644 index 000000000..cf74b5cfe --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/GlobalAnisotropicFilteringLimitsSetting.cs @@ -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 + } + + + /// + /// 全局各向异性过滤限制 + /// + [Sort(8)] + public class GlobalAnisotropicFilteringLimitsSetting : MultiOption + { + 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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/GlobalAnisotropicFilteringLimitsSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/GlobalAnisotropicFilteringLimitsSetting.cs.meta new file mode 100644 index 000000000..6d0233d27 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/GlobalAnisotropicFilteringLimitsSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6937878e8f61426687c62e26252e9258 +timeCreated: 1748590403 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/MsaaSampleSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/MsaaSampleSetting.cs new file mode 100644 index 000000000..13b5d442e --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/MsaaSampleSetting.cs @@ -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 + { + 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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/MsaaSampleSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/MsaaSampleSetting.cs.meta new file mode 100644 index 000000000..4d683f5f6 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/MsaaSampleSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ae51922900c9429cb0de97b473a3429e +timeCreated: 1748589774 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/QualityLevelSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/QualityLevelSetting.cs new file mode 100644 index 000000000..a6abadd4f --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/QualityLevelSetting.cs @@ -0,0 +1,39 @@ +using UnityEngine; + +namespace NBF.Setting +{ + /// + /// 画质设置 + /// + [Sort(3)] + public class QualityLevelSetting : MultiOption + { + 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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/QualityLevelSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/QualityLevelSetting.cs.meta new file mode 100644 index 000000000..e8f27fe4c --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/QualityLevelSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 470180f8a41b4856bf3318bc60f2abf1 +timeCreated: 1748588124 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/RenderScaleSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/RenderScaleSetting.cs new file mode 100644 index 000000000..aa0a6e72b --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/RenderScaleSetting.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/RenderScaleSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/RenderScaleSetting.cs.meta new file mode 100644 index 000000000..199d52403 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/RenderScaleSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e54edac5d4fe4dbda2da5bce433482dc +timeCreated: 1748589449 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/ResolutionSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/ResolutionSetting.cs new file mode 100644 index 000000000..15585e972 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/ResolutionSetting.cs @@ -0,0 +1,65 @@ +using UnityEngine; + +namespace NBF.Setting +{ + /// + /// 分辨率设置 + /// + [Sort(2)] + public class ResolutionSetting : MultiOption + { + 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; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/ResolutionSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/ResolutionSetting.cs.meta new file mode 100644 index 000000000..91fc65339 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/ResolutionSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 08fa420645764519a7a960565464a708 +timeCreated: 1748586208 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/TextureQualitySetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/TextureQualitySetting.cs new file mode 100644 index 000000000..cbdfe70f9 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/TextureQualitySetting.cs @@ -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 + { + 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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/TextureQualitySetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/TextureQualitySetting.cs.meta new file mode 100644 index 000000000..6d00d60a9 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/TextureQualitySetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d7ca1e2468b24b6285be9176ae024864 +timeCreated: 1748590058 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/VSyncSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/Graphics/VSyncSetting.cs new file mode 100644 index 000000000..43172aebd --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/VSyncSetting.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +namespace NBF.Setting +{ + /// + /// 垂直同步 + /// + [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); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Graphics/VSyncSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/Graphics/VSyncSetting.cs.meta new file mode 100644 index 000000000..06cb14863 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Graphics/VSyncSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 00628a08aaac416796a4018119e77cc6 +timeCreated: 1748585191 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/Input.meta b/Assets/Scripts/Common/Services/Settings/Options/Input.meta new file mode 100644 index 000000000..0b23c58e5 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/Input.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3ca3dc82471a404ea2346559f1e86f12 +timeCreated: 1748590614 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage.meta b/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage.meta new file mode 100644 index 000000000..b43da7a87 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 03ec1dd2a17344dcb27d9f06c7dbbc34 +timeCreated: 1748590602 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage/LanguageSetting.cs b/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage/LanguageSetting.cs new file mode 100644 index 000000000..558333732 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage/LanguageSetting.cs @@ -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 + { + 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() + { + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage/LanguageSetting.cs.meta b/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage/LanguageSetting.cs.meta new file mode 100644 index 000000000..3a6de12a1 --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Options/SoundAndLanguage/LanguageSetting.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6eb19d962e5644ada69dca074c6e720a +timeCreated: 1748592356 \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/Settings.cs b/Assets/Scripts/Common/Services/Settings/Settings.cs new file mode 100644 index 000000000..53203ab0d --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/Settings.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using NBF.Setting; + +namespace NBF +{ + public class Settings : MonoService + { + private readonly Dictionary> _dictionary = new Dictionary>(); + + protected override void OnAwake() + { + List list = new List(); + var options = Reflection.GetAllNonAbstractDerivedTypes(); + foreach (var option in options) + { + var settingOption = Activator.CreateInstance(option); + if (settingOption is OptionBase optionSetting) + { + list.Add(optionSetting); + optionSetting.Initialize(); + } + } + + list.SortBySortAttribute(); + + AddRangeToGroup(list); + } + + public void LoadAllSettings() + { + foreach (var list in _dictionary.Values) + { + foreach (var option in list) + { + option.Load(); + } + } + } + + #region 设置组 + + /// + /// 获取指定 Group 的所有 OptionBase + /// + public List GetOptionsByGroup(string group) + { + if (string.IsNullOrEmpty(group)) + { + throw new ArgumentException("Group name cannot be null or empty."); + } + + return _dictionary.TryGetValue(group, out var options) ? options : new List(); + } + + /// + /// 获取所有 Group 名字列表 + /// + public IEnumerable GetAllGroups() + { + return _dictionary.Keys; + } + + /// + /// 将 OptionBase 按 Group 分类存入字典 + /// + private void AddToGroup(OptionBase option) + { + if (option == null) return; + + if (string.IsNullOrEmpty(option.Group)) return; + + // 如果字典中没有该 Group,则新建一个 List 并加入字典 + if (!_dictionary.ContainsKey(option.Group)) + { + _dictionary[option.Group] = new List(); + } + + // 将 Option 添加到对应的 Group List 中 + _dictionary[option.Group].Add(option); + } + + /// + /// 批量添加 OptionBase 到字典 + /// + private void AddRangeToGroup(IEnumerable options) + { + if (options == null) return; + + foreach (var option in options) + { + AddToGroup(option); + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/GameSettings.cs.meta b/Assets/Scripts/Common/Services/Settings/Settings.cs.meta similarity index 100% rename from Assets/Scripts/Common/Services/Settings/GameSettings.cs.meta rename to Assets/Scripts/Common/Services/Settings/Settings.cs.meta diff --git a/Assets/Scripts/Common/Services/Settings/SettingsDef.cs b/Assets/Scripts/Common/Services/Settings/SettingsDef.cs new file mode 100644 index 000000000..f48ab2fdc --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/SettingsDef.cs @@ -0,0 +1,13 @@ +namespace NBF +{ + public class SettingsDef + { + public class Group + { + public const string Graphic = "Graphic"; + public const string Keyboard = "Keyboard"; + public const string Controller = "Controller"; + public const string SoundAndLanguage = "SoundAndLanguage"; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Common/Services/Settings/SettingsDef.cs.meta b/Assets/Scripts/Common/Services/Settings/SettingsDef.cs.meta new file mode 100644 index 000000000..61be14dae --- /dev/null +++ b/Assets/Scripts/Common/Services/Settings/SettingsDef.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 071c8f83b867467e9a4af17e3d474ab0 +timeCreated: 1748585459 \ No newline at end of file diff --git a/Assets/Scripts/Data/TabListData.cs b/Assets/Scripts/Data/TabListData.cs index 6442c8328..ca2112fdd 100644 --- a/Assets/Scripts/Data/TabListData.cs +++ b/Assets/Scripts/Data/TabListData.cs @@ -10,25 +10,15 @@ namespace NBF public string Icon; } - public class TabSubItemData : TabItemData + public class TabListData : TabItemData + { + } + public class TabSubItemData : TabListData { public List Items = new List(); } - - public class TabListData - { - public TabItemData Tab; - } - - public class TabListSettingData : TabListData - { - /// - /// 设置保存对象 - /// - public object SettingsObject; - } - + /// /// 保护二级子目录的列表 /// @@ -38,8 +28,8 @@ namespace NBF public void AddTestData(int index) { - Tab = new TabItemData(); - Tab.Name = $"标题-{index + 1}"; + Name = $"标题-{index + 1}"; + string[] testIcon = { "Globe", "Granade", "Gun" }; var count1 = Random.Range(5, 10); var count2 = Random.Range(90, 200); diff --git a/Assets/Scripts/Startup/App.cs b/Assets/Scripts/Startup/App.cs index 5621a2767..b6a698f31 100644 --- a/Assets/Scripts/Startup/App.cs +++ b/Assets/Scripts/Startup/App.cs @@ -110,7 +110,7 @@ namespace NBF private void InitService() { AddService(); - AddService(); + AddService(); } #endregion diff --git a/Assets/Scripts/UI/Common/Menu/CommonMenu.cs b/Assets/Scripts/UI/Common/Menu/CommonMenu.cs index 1e5abbf7c..88803b0f9 100644 --- a/Assets/Scripts/UI/Common/Menu/CommonMenu.cs +++ b/Assets/Scripts/UI/Common/Menu/CommonMenu.cs @@ -47,7 +47,7 @@ namespace NBF { var tabData = tabList[i]; var tabItem = List.AddItemFromPool().asButton; - tabItem.title = Lan.Get(tabData.Tab.Name); + tabItem.title = Lan.Get(tabData.Name); listWidth += tabItem.width; if (i > 0) { diff --git a/Assets/Scripts/UI/Home/SettingItem.cs b/Assets/Scripts/UI/Home/SettingItem.cs deleted file mode 100644 index 4c17dad56..000000000 --- a/Assets/Scripts/UI/Home/SettingItem.cs +++ /dev/null @@ -1,38 +0,0 @@ -// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 - -using System.IO; -using System.Reflection; -using UnityEngine; -using FairyGUI; -using NBC; -using Unity.VisualScripting; - -namespace NBF -{ - public partial class SettingItem : GButton - { - public string TitleKey; - public string DescriptionKey; - - private void OnInited() - { - } - - public void SetData(FieldInfo field, object value) - { - var titleAttribute = field.GetAttribute(); - if (titleAttribute != null) - { - TitleKey = titleAttribute.Title; - } - - var descriptionAttribute = field.GetAttribute(); - if (descriptionAttribute != null) - { - DescriptionKey = descriptionAttribute.Description; - } - - TextName.text = Lan.Get(TitleKey); - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/UI/Home/SettingPanel.cs b/Assets/Scripts/UI/Home/SettingPanel.cs deleted file mode 100644 index 202562db5..000000000 --- a/Assets/Scripts/UI/Home/SettingPanel.cs +++ /dev/null @@ -1,94 +0,0 @@ -// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 - -using System.Collections.Generic; -using UnityEngine; -using NBC; -using Unity.VisualScripting; - -namespace NBF -{ - public partial class SettingPanel : UIPanel - { - public override string UIPackName => "Main"; - public override string UIResName => "SettingPanel"; - - private List tabList = new List(); - - private object _currentSettingsObject; - - protected override void OnInit() - { - base.OnInit(); - IsShowCursor = true; - - TabListSettingData tabInput = new TabListSettingData(); - tabInput.Tab = new TabItemData(); - tabInput.Tab.Name = "键盘和鼠标"; - tabList.Add(tabInput); - - TabListSettingData tabCtrl = new TabListSettingData(); - tabCtrl.Tab = new TabItemData(); - tabCtrl.Tab.Name = "控制器"; - tabList.Add(tabCtrl); - - TabListSettingData tabVideo = new TabListSettingData(); - tabVideo.Tab = new TabItemData(); - tabVideo.Tab.Name = "视频"; - tabVideo.SettingsObject = GameSettings.Instance.UseSettings; - tabList.Add(tabVideo); - - TabListSettingData tabSound = new TabListSettingData(); - tabSound.Tab = new TabItemData(); - tabSound.Tab.Name = "音频和语言"; - tabList.Add(tabSound); - - Menu.OnTabChange += ChangeTab; - } - - protected override void OnShow() - { - Menu.SetTabs(tabList); - } - - private void ChangeTab(int index) - { - Log.Info($"Change tab index={index}"); - var tabListData = tabList[index]; - _currentSettingsObject = tabListData.SettingsObject; - ResetSettingList(); - } - - - private void ResetSettingList() - { - List.RemoveChildrenToPool(); - if (_currentSettingsObject == null) return; - var fields = _currentSettingsObject.GetType().GetFields(); - foreach (var field in fields) - { - if (List.AddItemFromPool() is SettingItem item) - { - item.SetData(field, _currentSettingsObject); - } - } - } - - private void Reset() - { - } - - private void Save() - { - } - - protected override void OnHide() - { - base.OnHide(); - } - - protected override void OnDestroy() - { - base.OnDestroy(); - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/UI/Settings.meta b/Assets/Scripts/UI/Settings.meta new file mode 100644 index 000000000..cc4a2d5af --- /dev/null +++ b/Assets/Scripts/UI/Settings.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: c812afefed4f43beb3ab200bf67bacf6 +timeCreated: 1748569083 \ No newline at end of file diff --git a/Assets/Scripts/UI/Home/SettingItem.Designer.cs b/Assets/Scripts/UI/Settings/SettingItem.Designer.cs similarity index 100% rename from Assets/Scripts/UI/Home/SettingItem.Designer.cs rename to Assets/Scripts/UI/Settings/SettingItem.Designer.cs diff --git a/Assets/Scripts/UI/Home/SettingItem.Designer.cs.meta b/Assets/Scripts/UI/Settings/SettingItem.Designer.cs.meta similarity index 100% rename from Assets/Scripts/UI/Home/SettingItem.Designer.cs.meta rename to Assets/Scripts/UI/Settings/SettingItem.Designer.cs.meta diff --git a/Assets/Scripts/UI/Settings/SettingItem.cs b/Assets/Scripts/UI/Settings/SettingItem.cs new file mode 100644 index 000000000..34695ca06 --- /dev/null +++ b/Assets/Scripts/UI/Settings/SettingItem.cs @@ -0,0 +1,114 @@ +// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖 + +using System.IO; +using System.Reflection; +using UnityEngine; +using FairyGUI; +using NBC; +using NBF.Setting; +using Unity.VisualScripting; + +namespace NBF +{ + public partial class SettingItem : GButton + { + public OptionBase Option; + + private void OnInited() + { + BtnPrev.onClick.Set(OnPrev); + BtnNext.onClick.Set(OnNext); + Slider.onChanged.Set(OnSliderChanged); + } + + public void SetData(OptionBase option) + { + Option = option; + + if (option is IMultiOption multiOption) + { + style.selectedIndex = 0; + } + else if (option is RangeOption range) + { + style.selectedIndex = 1; + Slider.min = range.MinValue; + Slider.max = range.MaxValue; + Slider.wholeNumbers = true; + } + else if (option is RangeOptionFloat rangeOptionFloat) + { + style.selectedIndex = 1; + Slider.min = rangeOptionFloat.MinValue; + Slider.max = rangeOptionFloat.MaxValue; + Slider.wholeNumbers = false; + } + + TextName.text = Lan.Get(Option.Name); + SetShow(); + } + + private void SetShow() + { + if (Option is IMultiOption multiOption) + { + // style.selectedIndex = 0; + TextInfo.text = multiOption.GetName(); + } + // else if (option is RangeOption range) + // { + // + // } + // else if (option is RangeOptionFloat rangeOptionFloat) + // { + // + // } + } + + public void OnPrev() + { + if (Option is IMultiOption multiOption) + { + var index = multiOption.GetIndex(); + if (index > 0) + { + index--; + } + else if (index == 0) + { + var names = multiOption.GetOptionNames(); + index = names.Count - 1; + } + + multiOption.SetIndex(index); + } + + SetShow(); + } + + public void OnNext() + { + if (Option is IMultiOption multiOption) + { + var names = multiOption.GetOptionNames(); + var index = multiOption.GetIndex(); + if (index < names.Count - 1) + { + index++; + } + else if (index == names.Count - 1) + { + index = 0; + } + + multiOption.SetIndex(index); + } + + SetShow(); + } + + public void OnSliderChanged() + { + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/UI/Home/SettingItem.cs.meta b/Assets/Scripts/UI/Settings/SettingItem.cs.meta similarity index 100% rename from Assets/Scripts/UI/Home/SettingItem.cs.meta rename to Assets/Scripts/UI/Settings/SettingItem.cs.meta diff --git a/Assets/Scripts/UI/Home/SettingPanel.Designer.cs b/Assets/Scripts/UI/Settings/SettingPanel.Designer.cs similarity index 100% rename from Assets/Scripts/UI/Home/SettingPanel.Designer.cs rename to Assets/Scripts/UI/Settings/SettingPanel.Designer.cs diff --git a/Assets/Scripts/UI/Home/SettingPanel.Designer.cs.meta b/Assets/Scripts/UI/Settings/SettingPanel.Designer.cs.meta similarity index 100% rename from Assets/Scripts/UI/Home/SettingPanel.Designer.cs.meta rename to Assets/Scripts/UI/Settings/SettingPanel.Designer.cs.meta diff --git a/Assets/Scripts/UI/Settings/SettingPanel.cs b/Assets/Scripts/UI/Settings/SettingPanel.cs new file mode 100644 index 000000000..3f3788f6c --- /dev/null +++ b/Assets/Scripts/UI/Settings/SettingPanel.cs @@ -0,0 +1,135 @@ +// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 + +using System.Collections.Generic; +using UnityEngine; +using NBC; +using Unity.VisualScripting; + +namespace NBF +{ + public partial class SettingPanel : UIPanel + { + public override string UIPackName => "Main"; + public override string UIResName => "SettingPanel"; + + private List tabList = new List(); + + + private string _currentGroup = ""; + + protected override void OnInit() + { + base.OnInit(); + IsShowCursor = true; + + var groupNames = Settings.Instance.GetAllGroups(); + foreach (var group in groupNames) + { + var tab = new TabListData + { + Name = group + }; + tabList.Add(tab); + } + + Menu.OnTabChange += ChangeTab; + } + + protected override void OnShow() + { + Settings.Instance.LoadAllSettings(); + InputManager.OnUICanceled += OnUICanceled; + Menu.SetTabs(tabList); + UseBottomMenu(); + } + + private void ChangeTab(int index) + { + Log.Info($"Change tab index={index}"); + var tabListData = tabList[index]; + _currentGroup = tabListData.Name; + // _currentSettingsObject = tabListData.SettingsObject; + ResetSettingList(); + } + + + private void ResetSettingList() + { + TextTitle.text = Lan.Get(_currentGroup); + + List.RemoveChildrenToPool(); + if (string.IsNullOrEmpty(_currentGroup)) return; + var options = Settings.Instance.GetOptionsByGroup(_currentGroup); + + foreach (var option in options) + { + if (List.AddItemFromPool() is SettingItem item) + { + item.SetData(option); + } + } + } + + private void UseBottomMenu() + { + BottomMenu.OnBack += Hide; + BottomMenu.Use(); + } + + private void OnUICanceled(string action) + { + if (action == InputDef.UI.SubPrev) + { + if (List.GetChildAt(List.selectedIndex) is SettingItem item) + { + item.OnPrev(); + } + } + else if (action == InputDef.UI.SubNext) + { + if (List.GetChildAt(List.selectedIndex) is SettingItem item) + { + item.OnNext(); + } + } + else if (action == InputDef.UI.Up) + { + SetListSelected(List.selectedIndex - 1); + } + else if (action == InputDef.UI.Down) + { + if (List.selectedIndex < 0) + { + SetListSelected(0); + } + else + { + SetListSelected(List.selectedIndex + 1); + } + } + } + + private void SetListSelected(int selectedIndex) + { + if (selectedIndex >= 0 && selectedIndex < List.numItems) + { + List.selectedIndex = selectedIndex; + List.ScrollToView(List.selectedIndex); + } + } + + protected override void OnHide() + { + base.OnHide(); + BottomMenu.OnBack -= Hide; + BottomMenu.UnUse(); + InputManager.OnUICanceled -= OnUICanceled; + } + + protected override void OnDestroy() + { + base.OnDestroy(); + Menu.OnTabChange -= ChangeTab; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/UI/Home/SettingPanel.cs.meta b/Assets/Scripts/UI/Settings/SettingPanel.cs.meta similarity index 100% rename from Assets/Scripts/UI/Home/SettingPanel.cs.meta rename to Assets/Scripts/UI/Settings/SettingPanel.cs.meta diff --git a/Assets/Scripts/Utils/Extends/ListExtends.cs b/Assets/Scripts/Utils/Extends/ListExtends.cs new file mode 100644 index 000000000..ccf9bf31c --- /dev/null +++ b/Assets/Scripts/Utils/Extends/ListExtends.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using NBF.Setting; + +namespace NBF +{ + public static class ListExtends + { + public static void SortBySortAttribute(this List list) + { + if (list == null) + throw new ArgumentNullException(nameof(list)); + + list.Sort((a, b) => + { + var orderA = GetSortOrder(a); + var orderB = GetSortOrder(b); + return orderA.CompareTo(orderB); + }); + } + + private static int GetSortOrder(OptionBase option) + { + if (option == null) + return 999; + + var sortAttribute = option.GetType() + .GetCustomAttribute(inherit: false); + + return sortAttribute?.Sort ?? 999; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Utils/Extends/ListExtends.cs.meta b/Assets/Scripts/Utils/Extends/ListExtends.cs.meta new file mode 100644 index 000000000..c81c99f83 --- /dev/null +++ b/Assets/Scripts/Utils/Extends/ListExtends.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 87135425aeb24b8ead2f411dceabb955 +timeCreated: 1748591603 \ No newline at end of file diff --git a/Assets/Scripts/Utils/Reflection.cs b/Assets/Scripts/Utils/Reflection.cs index 11ebda145..9699f8352 100644 --- a/Assets/Scripts/Utils/Reflection.cs +++ b/Assets/Scripts/Utils/Reflection.cs @@ -8,7 +8,9 @@ namespace NBF { public static class Reflection { - static Assembly _assembly; + private static readonly Assembly _assembly; + + public static Assembly Assembly => _assembly; static Reflection() { @@ -34,6 +36,5 @@ namespace NBF return derivedTypes; } - } } \ No newline at end of file diff --git a/FGUIProject/assets/Main/Com/Items/SettingItem.xml b/FGUIProject/assets/Main/Com/Items/SettingItem.xml index a157d61ca..e8956e917 100644 --- a/FGUIProject/assets/Main/Com/Items/SettingItem.xml +++ b/FGUIProject/assets/Main/Com/Items/SettingItem.xml @@ -1,6 +1,6 @@ - + @@ -9,9 +9,9 @@ - + - + diff --git a/Fishing2.sln.DotSettings.user b/Fishing2.sln.DotSettings.user index 13a1fa6cf..e26313309 100644 --- a/Fishing2.sln.DotSettings.user +++ b/Fishing2.sln.DotSettings.user @@ -8,6 +8,7 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 3db87f87e..ca1726efa 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -9,31 +9,31 @@ EditorUserSettings: value: 18134705175a055722080a3115371d4a0d55006876786860616b0471b8b07a68ffab74f9ee2a3a30300cea1a11320d0beb1a0c25f7060f494b4cc80018eb09361fc211cb1f862d19c51d19dcc413d6ade0d8ddfcddf9f4d9d29195fcfde6ebeae6f0a9c9afa6f8c5b89ff7a1aacececac4eba4d7c9d28bda flags: 0 RecentlyUsedSceneGuid-0: - value: 51090c5503010d5d5f0b0e26427a0b444215402f287e7f327b2c1f30e6b8303c - flags: 0 - RecentlyUsedSceneGuid-1: - value: 5553075e5c0d59080f0d597347770f44444f4a7f78787e36782f4967bae43769 - flags: 0 - RecentlyUsedSceneGuid-2: - value: 5b08565357035d0c0f5d0a774277071242154029757170697b784e66e6b33060 - flags: 0 - RecentlyUsedSceneGuid-3: value: 0150055704510808545c0a26467506444516197a747874637b7e1860b5b6616c flags: 0 - RecentlyUsedSceneGuid-4: - value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e - flags: 0 - RecentlyUsedSceneGuid-5: + RecentlyUsedSceneGuid-1: value: 565706045c050b5a5b5b0f7512710b44144f4f7f297a7569297c1967b0b66168 flags: 0 - RecentlyUsedSceneGuid-6: + RecentlyUsedSceneGuid-2: value: 550007565c005e0858575d23497a5c441516417d7a7171347c794931b6b1313c flags: 0 - RecentlyUsedSceneGuid-7: + RecentlyUsedSceneGuid-3: + value: 500606050702510d0e570876137a09441516197b782925632e2a4d64b3b16169 + flags: 0 + RecentlyUsedSceneGuid-4: value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661 flags: 0 + RecentlyUsedSceneGuid-5: + value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e + flags: 0 + RecentlyUsedSceneGuid-6: + value: 0157070300060d0c5c595a2346710d44174f497e2a2d223478714d32b2b86561 + flags: 0 + RecentlyUsedSceneGuid-7: + value: 5a57045103000a580e595d2615270d44104e1e722e7d7e697f284936e3e6623e + flags: 0 RecentlyUsedSceneGuid-8: - value: 500606050702510d0e570876137a09441516197b782925632e2a4d64b3b16169 + value: 50570c050056515e540a097048275e444f154e287f2e20367c7e4532b0b96468 flags: 0 RecentlyUsedSceneGuid-9: value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e