设置相关功能脚本呢
This commit is contained in:
Binary file not shown.
@@ -2,12 +2,10 @@
|
|||||||
|
|
||||||
namespace NBF
|
namespace NBF
|
||||||
{
|
{
|
||||||
|
|
||||||
public abstract class BaseAttribute : Attribute
|
public abstract class BaseAttribute : Attribute
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[AttributeUsage(AttributeTargets.Field)]
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
public class InputIconAttribute : BaseAttribute
|
public class InputIconAttribute : BaseAttribute
|
||||||
{
|
{
|
||||||
@@ -48,4 +46,15 @@ namespace NBF
|
|||||||
Description = description;
|
Description = description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Class, AllowMultiple = true)]
|
||||||
|
public class SortAttribute : BaseAttribute
|
||||||
|
{
|
||||||
|
public int Sort;
|
||||||
|
|
||||||
|
public SortAttribute(int sort)
|
||||||
|
{
|
||||||
|
Sort = sort;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
3
Assets/Scripts/Common/Services/Settings/Base.meta
Normal file
3
Assets/Scripts/Common/Services/Settings/Base.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c12ca701ad9f433d9e6e7eaf04f507d0
|
||||||
|
timeCreated: 1748570535
|
||||||
85
Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs
Normal file
85
Assets/Scripts/Common/Services/Settings/Base/MultiOption.cs
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NBF.Setting
|
||||||
|
{
|
||||||
|
public interface IMultiOption : IOptionBase
|
||||||
|
{
|
||||||
|
List<string> GetOptionNames();
|
||||||
|
int GetIndex();
|
||||||
|
void SetIndex(int index);
|
||||||
|
string GetName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class MultiOption<T> : OptionBase, IMultiOption
|
||||||
|
{
|
||||||
|
private int _index;
|
||||||
|
|
||||||
|
protected OptionTable<T> OptionTable = new OptionTable<T>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认值
|
||||||
|
/// </summary>
|
||||||
|
protected abstract T DefaultValue { get; }
|
||||||
|
|
||||||
|
protected override void OnLoad()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void AddOption(string name, T value)
|
||||||
|
{
|
||||||
|
OptionTable.Add(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<string> 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<T> 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<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(_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5b25650e359243468131db1f9b951ae7
|
||||||
|
timeCreated: 1748571045
|
||||||
49
Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs
Normal file
49
Assets/Scripts/Common/Services/Settings/Base/OptionBase.cs
Normal file
@@ -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; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 所在组
|
||||||
|
/// </summary>
|
||||||
|
public abstract string Group { get; }
|
||||||
|
|
||||||
|
public void Initialize()
|
||||||
|
{
|
||||||
|
OnInitialize();
|
||||||
|
Load();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加载用户的设置
|
||||||
|
/// </summary>
|
||||||
|
public void Load()
|
||||||
|
{
|
||||||
|
OnLoad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Apply()
|
||||||
|
{
|
||||||
|
OnApply();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void OnInitialize();
|
||||||
|
|
||||||
|
|
||||||
|
protected abstract void OnApply();
|
||||||
|
|
||||||
|
protected abstract void OnReset();
|
||||||
|
|
||||||
|
protected abstract void OnLoad();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dd2d6f346b1145debf370bc3ac71bd7e
|
||||||
|
timeCreated: 1748570612
|
||||||
34
Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs
Normal file
34
Assets/Scripts/Common/Services/Settings/Base/OptionTable.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
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) => entries[index].Value;
|
||||||
|
|
||||||
|
public string GetName(int index) => entries != null ? entries[index].Name : string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a7241b5524db446eb4f73ae3a8d7b0ec
|
||||||
|
timeCreated: 1748571519
|
||||||
55
Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs
Normal file
55
Assets/Scripts/Common/Services/Settings/Base/RangeOption.cs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
namespace NBF.Setting
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 范围设置
|
||||||
|
/// </summary>
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 范围设置
|
||||||
|
/// </summary>
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3531567c76fc48d5939644966fe22057
|
||||||
|
timeCreated: 1748572844
|
||||||
15
Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs
Normal file
15
Assets/Scripts/Common/Services/Settings/Base/ToggleOption.cs
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsEnabled() => GetSelectedOption();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dbcf52430d8b483497f040fe7cbcfa62
|
||||||
|
timeCreated: 1748572278
|
||||||
@@ -1,301 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Rendering;
|
|
||||||
using UnityEngine.Rendering.Universal;
|
|
||||||
|
|
||||||
namespace NBF
|
|
||||||
{
|
|
||||||
public class GameSettings : MonoService<GameSettings>
|
|
||||||
{
|
|
||||||
public enum QualityEnum
|
|
||||||
{
|
|
||||||
Low = 0,
|
|
||||||
Medium = 1,
|
|
||||||
High = 2,
|
|
||||||
Ultra = 3
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum VSyncEnum
|
|
||||||
{
|
|
||||||
Off = 0,
|
|
||||||
On = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 抗锯齿等级
|
|
||||||
/// </summary>
|
|
||||||
public enum AntiAliasLevelEnum
|
|
||||||
{
|
|
||||||
Off = 1,
|
|
||||||
x2 = 2,
|
|
||||||
x4 = 4,
|
|
||||||
x8 = 8
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 贴图质量
|
|
||||||
/// </summary>
|
|
||||||
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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 质量等级 0 1 2 3
|
|
||||||
/// </summary>
|
|
||||||
// [Title("Settings_Title_quality")] [Description("Settings_Description_quality")]
|
|
||||||
[Title("图像质量")] [Description("图像质量324234图像质量图像质量图像质量图像质量3434")]
|
|
||||||
public QualityEnum QualityLevel = QualityEnum.High;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 显示分辨率,有任意一个为0,则为全屏
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Title_Resolution")] [Description("Settings_Description_Resolution")]
|
|
||||||
public Vector2Int Resolution = new Vector2Int(0, 0);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 渲染比例
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Title_RenderScale")] [Description("Settings_Description_RenderScale")] [Range(0.1f, 2f)]
|
|
||||||
public float RenderScale = 1f;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 窗口模式
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Title_WindowedMode")] [Description("Settings_Description_WindowedMode")]
|
|
||||||
public FullScreenMode WindowedMode = FullScreenMode.MaximizedWindow;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 垂直同步个数
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Title_VSync")] [Description("Settings_Description_VSync")]
|
|
||||||
public VSyncEnum VSync = VSyncEnum.Off;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///抗锯齿等级
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Title_AntiAliasLevel")] [Description("Settings_Description_AntiAliasLevel")]
|
|
||||||
public AntiAliasLevelEnum AntiAliasLevel = AntiAliasLevelEnum.Off;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 纹理质量
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Title_TextureQuality")] [Description("Settings_Description_TextureQuality")]
|
|
||||||
public TextureQualityEnum TextureQuality = TextureQualityEnum.FullRes;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 全局各向异性纹理过滤模式
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Title_AnisotropicMode")] [Description("Settings_Description_AnisotropicMode")]
|
|
||||||
public AnisotropicFiltering AnisotropicMode = AnisotropicFiltering.Enable;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 全局各向异性过滤限制
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Description_AnisotropicLevel")] [Description("Settings_Description_AnisotropicLevel")]
|
|
||||||
public AnisotropicLevelEnum AnisotropicLevel = AnisotropicLevelEnum.x4;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 阴影等级
|
|
||||||
/// </summary>
|
|
||||||
[Title("Settings_Description_ShadowmapResolution")]
|
|
||||||
[Description("Settings_Description_ShadowmapResolution")]
|
|
||||||
public ShadowmapResolutionEnum ShadowmapResolution = ShadowmapResolutionEnum.High;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 默认配置
|
|
||||||
/// </summary>
|
|
||||||
private GameSettingsData DefaultSettingsConverted = new GameSettingsData();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 当前正在调整的配置
|
|
||||||
/// </summary>
|
|
||||||
private GameSettingsData CurrentSettings = new GameSettingsData();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 当前使用配置
|
|
||||||
/// </summary>
|
|
||||||
public readonly GameSettingsData UseSettings = new GameSettingsData();
|
|
||||||
|
|
||||||
protected override void OnAwake()
|
|
||||||
{
|
|
||||||
LoadSettings();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 重置
|
|
||||||
/// </summary>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 开始进入设置模式,将当前使用的配置缓存一份
|
|
||||||
/// </summary>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 保存设置
|
|
||||||
/// </summary>
|
|
||||||
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<GameSettingsData>(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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 应用设置
|
|
||||||
/// </summary>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
3
Assets/Scripts/Common/Services/Settings/Options.meta
Normal file
3
Assets/Scripts/Common/Services/Settings/Options.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b3f3e6458ad24086b8838b3750453007
|
||||||
|
timeCreated: 1748585143
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fc7b116a771640d58d650ff79698f301
|
||||||
|
timeCreated: 1748589438
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b96e677183324f5d8d01e786a828c0db
|
||||||
|
timeCreated: 1748590207
|
||||||
@@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a6386dea2d44f3fb004905e688b97d5
|
||||||
|
timeCreated: 1748588770
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6937878e8f61426687c62e26252e9258
|
||||||
|
timeCreated: 1748590403
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ae51922900c9429cb0de97b473a3429e
|
||||||
|
timeCreated: 1748589774
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 470180f8a41b4856bf3318bc60f2abf1
|
||||||
|
timeCreated: 1748588124
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e54edac5d4fe4dbda2da5bce433482dc
|
||||||
|
timeCreated: 1748589449
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 08fa420645764519a7a960565464a708
|
||||||
|
timeCreated: 1748586208
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d7ca1e2468b24b6285be9176ae024864
|
||||||
|
timeCreated: 1748590058
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 00628a08aaac416796a4018119e77cc6
|
||||||
|
timeCreated: 1748585191
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3ca3dc82471a404ea2346559f1e86f12
|
||||||
|
timeCreated: 1748590614
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 03ec1dd2a17344dcb27d9f06c7dbbc34
|
||||||
|
timeCreated: 1748590602
|
||||||
@@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6eb19d962e5644ada69dca074c6e720a
|
||||||
|
timeCreated: 1748592356
|
||||||
98
Assets/Scripts/Common/Services/Settings/Settings.cs
Normal file
98
Assets/Scripts/Common/Services/Settings/Settings.cs
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using NBF.Setting;
|
||||||
|
|
||||||
|
namespace NBF
|
||||||
|
{
|
||||||
|
public class Settings : MonoService<Settings>
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list.SortBySortAttribute();
|
||||||
|
|
||||||
|
AddRangeToGroup(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadAllSettings()
|
||||||
|
{
|
||||||
|
foreach (var list in _dictionary.Values)
|
||||||
|
{
|
||||||
|
foreach (var option in list)
|
||||||
|
{
|
||||||
|
option.Load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#region 设置组
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取指定 Group 的所有 OptionBase
|
||||||
|
/// </summary>
|
||||||
|
public List<OptionBase> 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<OptionBase>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取所有 Group 名字列表
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<string> GetAllGroups()
|
||||||
|
{
|
||||||
|
return _dictionary.Keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 将 OptionBase 按 Group 分类存入字典
|
||||||
|
/// </summary>
|
||||||
|
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<OptionBase>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将 Option 添加到对应的 Group List 中
|
||||||
|
_dictionary[option.Group].Add(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 批量添加 OptionBase 到字典
|
||||||
|
/// </summary>
|
||||||
|
private void AddRangeToGroup(IEnumerable<OptionBase> options)
|
||||||
|
{
|
||||||
|
if (options == null) return;
|
||||||
|
|
||||||
|
foreach (var option in options)
|
||||||
|
{
|
||||||
|
AddToGroup(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Assets/Scripts/Common/Services/Settings/SettingsDef.cs
Normal file
13
Assets/Scripts/Common/Services/Settings/SettingsDef.cs
Normal file
@@ -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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 071c8f83b867467e9a4af17e3d474ab0
|
||||||
|
timeCreated: 1748585459
|
||||||
@@ -10,25 +10,15 @@ namespace NBF
|
|||||||
public string Icon;
|
public string Icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TabSubItemData : TabItemData
|
public class TabListData : TabItemData
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public class TabSubItemData : TabListData
|
||||||
{
|
{
|
||||||
public List<object> Items = new List<object>();
|
public List<object> Items = new List<object>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class TabListData
|
|
||||||
{
|
|
||||||
public TabItemData Tab;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TabListSettingData : TabListData
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 设置保存对象
|
|
||||||
/// </summary>
|
|
||||||
public object SettingsObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保护二级子目录的列表
|
/// 保护二级子目录的列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -38,8 +28,8 @@ namespace NBF
|
|||||||
|
|
||||||
public void AddTestData(int index)
|
public void AddTestData(int index)
|
||||||
{
|
{
|
||||||
Tab = new TabItemData();
|
Name = $"标题-{index + 1}";
|
||||||
Tab.Name = $"标题-{index + 1}";
|
|
||||||
string[] testIcon = { "Globe", "Granade", "Gun" };
|
string[] testIcon = { "Globe", "Granade", "Gun" };
|
||||||
var count1 = Random.Range(5, 10);
|
var count1 = Random.Range(5, 10);
|
||||||
var count2 = Random.Range(90, 200);
|
var count2 = Random.Range(90, 200);
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace NBF
|
|||||||
private void InitService()
|
private void InitService()
|
||||||
{
|
{
|
||||||
AddService<InputManager>();
|
AddService<InputManager>();
|
||||||
AddService<GameSettings>();
|
AddService<Settings>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
var tabData = tabList[i];
|
var tabData = tabList[i];
|
||||||
var tabItem = List.AddItemFromPool().asButton;
|
var tabItem = List.AddItemFromPool().asButton;
|
||||||
tabItem.title = Lan.Get(tabData.Tab.Name);
|
tabItem.title = Lan.Get(tabData.Name);
|
||||||
listWidth += tabItem.width;
|
listWidth += tabItem.width;
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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<TitleAttribute>();
|
|
||||||
if (titleAttribute != null)
|
|
||||||
{
|
|
||||||
TitleKey = titleAttribute.Title;
|
|
||||||
}
|
|
||||||
|
|
||||||
var descriptionAttribute = field.GetAttribute<DescriptionAttribute>();
|
|
||||||
if (descriptionAttribute != null)
|
|
||||||
{
|
|
||||||
DescriptionKey = descriptionAttribute.Description;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextName.text = Lan.Get(TitleKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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<TabListSettingData> tabList = new List<TabListSettingData>();
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
3
Assets/Scripts/UI/Settings.meta
Normal file
3
Assets/Scripts/UI/Settings.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c812afefed4f43beb3ab200bf67bacf6
|
||||||
|
timeCreated: 1748569083
|
||||||
114
Assets/Scripts/UI/Settings/SettingItem.cs
Normal file
114
Assets/Scripts/UI/Settings/SettingItem.cs
Normal file
@@ -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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
135
Assets/Scripts/UI/Settings/SettingPanel.cs
Normal file
135
Assets/Scripts/UI/Settings/SettingPanel.cs
Normal file
@@ -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<TabListData> tabList = new List<TabListData>();
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
Assets/Scripts/Utils/Extends/ListExtends.cs
Normal file
34
Assets/Scripts/Utils/Extends/ListExtends.cs
Normal file
@@ -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<OptionBase> 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<SortAttribute>(inherit: false);
|
||||||
|
|
||||||
|
return sortAttribute?.Sort ?? 999;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/Scripts/Utils/Extends/ListExtends.cs.meta
Normal file
3
Assets/Scripts/Utils/Extends/ListExtends.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 87135425aeb24b8ead2f411dceabb955
|
||||||
|
timeCreated: 1748591603
|
||||||
@@ -8,7 +8,9 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
public static class Reflection
|
public static class Reflection
|
||||||
{
|
{
|
||||||
static Assembly _assembly;
|
private static readonly Assembly _assembly;
|
||||||
|
|
||||||
|
public static Assembly Assembly => _assembly;
|
||||||
|
|
||||||
static Reflection()
|
static Reflection()
|
||||||
{
|
{
|
||||||
@@ -34,6 +36,5 @@ namespace NBF
|
|||||||
|
|
||||||
return derivedTypes;
|
return derivedTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<component size="874,70" extention="Button">
|
<component size="874,70" extention="Button">
|
||||||
<controller name="style" pages="0,文本,1,进度条" selected="1"/>
|
<controller name="style" pages="0,文本,1,进度条" selected="0"/>
|
||||||
<controller name="button" pages="2,up,3,down,4,over,5,selectedOver" selected="0"/>
|
<controller name="button" pages="2,up,3,down,4,over,5,selectedOver" selected="0"/>
|
||||||
<displayList>
|
<displayList>
|
||||||
<image id="n5_e9z8" name="back" src="kryob" fileName="Images/Square.png" pkg="6hgkvlau" xy="0,0" size="868,70" alpha="0.2" color="#5c748b">
|
<image id="n5_e9z8" name="back" src="kryob" fileName="Images/Square.png" pkg="6hgkvlau" xy="0,0" size="868,70" alpha="0.2" color="#5c748b">
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
<relation target="" sidePair="width-width,height-height"/>
|
<relation target="" sidePair="width-width,height-height"/>
|
||||||
</image>
|
</image>
|
||||||
<text id="n6_e9z8" name="TextName" xy="22,19" size="189,32" alpha="0.7" fontSize="22" color="#ffffff" text="Screen resolution"/>
|
<text id="n6_e9z8" name="TextName" xy="22,19" size="189,32" alpha="0.7" fontSize="22" color="#ffffff" text="Screen resolution"/>
|
||||||
<text id="n7_e9z8" name="TextInfo" xy="610,18" pivot="0.5,0.5" size="131,32" alpha="0.7" fontSize="22" color="#ffffff" text="1920 x 1080">
|
<text id="n7_e9z8" name="TextInfo" xy="610,18" pivot="0.5,0.5" size="131,32" alpha="0.7" fontSize="22" color="#ffffff" align="center" text="1920 x 1080">
|
||||||
<gearDisplay controller="style" pages="0"/>
|
<gearDisplay controller="style" pages="0"/>
|
||||||
<relation target="" sidePair="right-right%"/>
|
<relation target="" sidePair="left-right"/>
|
||||||
</text>
|
</text>
|
||||||
<component id="n9_e9z8" name="Slider" src="e9z8k4" fileName="Com/Slider/CommonSlider.xml" pkg="6hgkvlau" xy="550,30" pivot="0.5,0.5" size="250,5">
|
<component id="n9_e9z8" name="Slider" src="e9z8k4" fileName="Com/Slider/CommonSlider.xml" pkg="6hgkvlau" xy="550,30" pivot="0.5,0.5" size="250,5">
|
||||||
<gearDisplay controller="style" pages="1"/>
|
<gearDisplay controller="style" pages="1"/>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIMGUIContainer_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4f75f0eb2d14004826911645c6175d61fbe00_003F49_003F22dd7281_003FIMGUIContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AIMGUIContainer_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4f75f0eb2d14004826911645c6175d61fbe00_003F49_003F22dd7281_003FIMGUIContainer_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyCode_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003Fd1_003F01a95d3a_003FKeyCode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AKeyCode_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003Fd1_003F01a95d3a_003FKeyCode_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARenderChain_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4f75f0eb2d14004826911645c6175d61fbe00_003Fde_003Fedac53d9_003FRenderChain_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ARenderChain_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003Fb4f75f0eb2d14004826911645c6175d61fbe00_003Fde_003Fedac53d9_003FRenderChain_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AResolution_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F44_003Fe8dd878d_003FResolution_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASphereCollider_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F03ef825315384b1cab81c4b53eb03d922ac00_003F31_003F871dbbe1_003FSphereCollider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASphereCollider_002Ecs_002Fl_003AC_0021_003FUsers_003F60527_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F03ef825315384b1cab81c4b53eb03d922ac00_003F31_003F871dbbe1_003FSphereCollider_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASystemLanguage_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F90_003F0e6861e6_003FSystemLanguage_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASystemLanguage_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F90_003F0e6861e6_003FSystemLanguage_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector2Int_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F23_003F52710087_003FVector2Int_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AVector2Int_002Ecs_002Fl_003AC_0021_003FUsers_003Fbob_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F021f30a9a92b48ce98ae6b39956dd76a1df600_003F23_003F52710087_003FVector2Int_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
|
||||||
|
|||||||
@@ -9,31 +9,31 @@ EditorUserSettings:
|
|||||||
value: 18134705175a055722080a3115371d4a0d55006876786860616b0471b8b07a68ffab74f9ee2a3a30300cea1a11320d0beb1a0c25f7060f494b4cc80018eb09361fc211cb1f862d19c51d19dcc413d6ade0d8ddfcddf9f4d9d29195fcfde6ebeae6f0a9c9afa6f8c5b89ff7a1aacececac4eba4d7c9d28bda
|
value: 18134705175a055722080a3115371d4a0d55006876786860616b0471b8b07a68ffab74f9ee2a3a30300cea1a11320d0beb1a0c25f7060f494b4cc80018eb09361fc211cb1f862d19c51d19dcc413d6ade0d8ddfcddf9f4d9d29195fcfde6ebeae6f0a9c9afa6f8c5b89ff7a1aacececac4eba4d7c9d28bda
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-0:
|
RecentlyUsedSceneGuid-0:
|
||||||
value: 51090c5503010d5d5f0b0e26427a0b444215402f287e7f327b2c1f30e6b8303c
|
|
||||||
flags: 0
|
|
||||||
RecentlyUsedSceneGuid-1:
|
|
||||||
value: 5553075e5c0d59080f0d597347770f44444f4a7f78787e36782f4967bae43769
|
|
||||||
flags: 0
|
|
||||||
RecentlyUsedSceneGuid-2:
|
|
||||||
value: 5b08565357035d0c0f5d0a774277071242154029757170697b784e66e6b33060
|
|
||||||
flags: 0
|
|
||||||
RecentlyUsedSceneGuid-3:
|
|
||||||
value: 0150055704510808545c0a26467506444516197a747874637b7e1860b5b6616c
|
value: 0150055704510808545c0a26467506444516197a747874637b7e1860b5b6616c
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-4:
|
RecentlyUsedSceneGuid-1:
|
||||||
value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e
|
|
||||||
flags: 0
|
|
||||||
RecentlyUsedSceneGuid-5:
|
|
||||||
value: 565706045c050b5a5b5b0f7512710b44144f4f7f297a7569297c1967b0b66168
|
value: 565706045c050b5a5b5b0f7512710b44144f4f7f297a7569297c1967b0b66168
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-6:
|
RecentlyUsedSceneGuid-2:
|
||||||
value: 550007565c005e0858575d23497a5c441516417d7a7171347c794931b6b1313c
|
value: 550007565c005e0858575d23497a5c441516417d7a7171347c794931b6b1313c
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-7:
|
RecentlyUsedSceneGuid-3:
|
||||||
|
value: 500606050702510d0e570876137a09441516197b782925632e2a4d64b3b16169
|
||||||
|
flags: 0
|
||||||
|
RecentlyUsedSceneGuid-4:
|
||||||
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
|
value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661
|
||||||
flags: 0
|
flags: 0
|
||||||
|
RecentlyUsedSceneGuid-5:
|
||||||
|
value: 020056535456585e0f0d0a7541210d441215482c2d297f36752c1b65b3b0376e
|
||||||
|
flags: 0
|
||||||
|
RecentlyUsedSceneGuid-6:
|
||||||
|
value: 0157070300060d0c5c595a2346710d44174f497e2a2d223478714d32b2b86561
|
||||||
|
flags: 0
|
||||||
|
RecentlyUsedSceneGuid-7:
|
||||||
|
value: 5a57045103000a580e595d2615270d44104e1e722e7d7e697f284936e3e6623e
|
||||||
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-8:
|
RecentlyUsedSceneGuid-8:
|
||||||
value: 500606050702510d0e570876137a09441516197b782925632e2a4d64b3b16169
|
value: 50570c050056515e540a097048275e444f154e287f2e20367c7e4532b0b96468
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedSceneGuid-9:
|
RecentlyUsedSceneGuid-9:
|
||||||
value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e
|
value: 5505015f5c515a085f5b092149760f441716407a787d7564287b1b36e7e1366e
|
||||||
|
|||||||
Reference in New Issue
Block a user