设置分组
This commit is contained in:
@@ -5,8 +5,8 @@ namespace NBF
|
||||
{
|
||||
public interface ISettings
|
||||
{
|
||||
List<OptionBase> GetOptionsByGroup(string group);
|
||||
IEnumerable<string> GetAllGroups();
|
||||
List<OptionBase> GetOptionsByTab(string group);
|
||||
IEnumerable<string> GetAllTabs();
|
||||
T GetSettingOption<T>() where T : OptionBase;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,11 @@ namespace NBF.Setting
|
||||
/// </summary>
|
||||
public abstract string Group { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 所在分切页
|
||||
/// </summary>
|
||||
public abstract string Tab { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 默认值
|
||||
/// </summary>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
{
|
||||
public abstract int MinValue { get; }
|
||||
public abstract int MaxValue { get; }
|
||||
|
||||
public virtual int ShowRate => 0;
|
||||
|
||||
public override void SetValue(int value)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98f6ee319dd5406e9cce3495ebf843e3
|
||||
timeCreated: 1749538582
|
||||
@@ -12,6 +12,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "AnisotropicMode";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
|
||||
protected override int DefaultValue => (int)AnisotropicFiltering.Enable;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "FullScreenMode";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => (int)FullScreenMode.ExclusiveFullScreen;
|
||||
|
||||
protected override void OnInitialize()
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "GlobalAnisotropicFilteringLimits";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => (int)AnisotropicLevelEnum.x4;
|
||||
|
||||
protected override void OnInitialize()
|
||||
@@ -54,6 +55,5 @@ namespace NBF.Setting
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "MsaaSample";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => (int)MsaaSampleEnum.Off;
|
||||
|
||||
protected override void OnInitialize()
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace NBF.Setting
|
||||
private int _defaultQualityLevel;
|
||||
public override string Name => "QualityLevel";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => _defaultQualityLevel;
|
||||
|
||||
protected override void OnInitialize()
|
||||
@@ -29,6 +30,5 @@ namespace NBF.Setting
|
||||
{
|
||||
QualitySettings.SetQualityLevel(GetSelectedOption());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,14 @@ namespace NBF.Setting
|
||||
{
|
||||
public override string Name => "RenderScale";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
public override int MinValue => 1;
|
||||
public override int MaxValue => 20;
|
||||
|
||||
protected override int DefaultValue => 10;
|
||||
|
||||
public override int ShowRate => 10;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace NBF.Setting
|
||||
public override string Name => "Resolution";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
protected override int DefaultValue => _defaultResolution;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace NBF.Setting
|
||||
public override string Name => "TextureQuality";
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
protected override int DefaultValue => (int)TextureQualityEnum.FullRes;
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace NBF.Setting
|
||||
public override string Name => "VSync";
|
||||
|
||||
public override string Group => SettingsDef.Group.Graphic;
|
||||
|
||||
public override string Tab => SettingsDef.Tab.Graphic;
|
||||
protected override int DefaultValue => 0;
|
||||
|
||||
protected override void OnApply()
|
||||
@@ -19,6 +19,5 @@ namespace NBF.Setting
|
||||
//垂直同步
|
||||
QualitySettings.vSyncCount = GetSelectedOption() ? 1 : 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 283a2fdc117b4b4c8c5e9a5245740a8e
|
||||
timeCreated: 1749538578
|
||||
@@ -19,7 +19,10 @@ namespace NBF.Setting
|
||||
{
|
||||
private SettingLanguage _defaultLanguage;
|
||||
public override string Name => "Language";
|
||||
public override string Group => SettingsDef.Group.SoundAndLanguage;
|
||||
public override string Group => SettingsDef.Group.Language;
|
||||
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
|
||||
protected override int DefaultValue => (int)_defaultLanguage;
|
||||
|
||||
protected override void OnInitialize()
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab9087f7f0a74aaa8a8824e2ec55657d
|
||||
timeCreated: 1749537412
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(3)]
|
||||
public class AmbientVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "AmbientVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetVolume(AudioChannelType.Ambient, GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e841f4c4a4954318b67235033e58576b
|
||||
timeCreated: 1749537896
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(1)]
|
||||
public class MasterVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "MasterVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetMasterVolume(GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e2fca480fb44b0a8d38fd15d2ef1413
|
||||
timeCreated: 1749537486
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(2)]
|
||||
public class PlayerVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "PlayerVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetVolume(AudioChannelType.Player, GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f421f4166fe4bd3a31c78f5a8e47364
|
||||
timeCreated: 1749537942
|
||||
@@ -0,0 +1,26 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF.Setting
|
||||
{
|
||||
[Sort(4)]
|
||||
public class UIVolumeSetting : RangeOption
|
||||
{
|
||||
public override string Name => "UIVolume";
|
||||
public override string Group => SettingsDef.Group.Sound;
|
||||
public override string Tab => SettingsDef.Tab.SoundAndLanguage;
|
||||
public override int MinValue => 0;
|
||||
public override int MaxValue => 100;
|
||||
|
||||
protected override int DefaultValue => 100;
|
||||
|
||||
protected override void OnInitialize()
|
||||
{
|
||||
SetValue(10);
|
||||
}
|
||||
|
||||
protected override void OnApply()
|
||||
{
|
||||
SoundManager.Inst.SetVolume(AudioChannelType.UI, GetValue() / 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a63098af5bd4b36929f75a58e2a5159
|
||||
timeCreated: 1749537834
|
||||
@@ -25,7 +25,7 @@ namespace NBF
|
||||
|
||||
list.SortBySortAttribute();
|
||||
|
||||
AddRangeToGroup(list);
|
||||
AddRangeToTab(list);
|
||||
}
|
||||
|
||||
public void LoadAllSettings()
|
||||
@@ -63,55 +63,55 @@ namespace NBF
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定 Group 的所有 OptionBase
|
||||
/// 获取指定 Tab 的所有 OptionBase
|
||||
/// </summary>
|
||||
public List<OptionBase> GetOptionsByGroup(string group)
|
||||
public List<OptionBase> GetOptionsByTab(string group)
|
||||
{
|
||||
if (string.IsNullOrEmpty(group))
|
||||
{
|
||||
throw new ArgumentException("Group name cannot be null or empty.");
|
||||
throw new ArgumentException("Tab name cannot be null or empty.");
|
||||
}
|
||||
|
||||
return _dictionary.TryGetValue(group, out var options) ? options : new List<OptionBase>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有 Group 名字列表
|
||||
/// 获取所有 Tab 名字列表
|
||||
/// </summary>
|
||||
public IEnumerable<string> GetAllGroups()
|
||||
public IEnumerable<string> GetAllTabs()
|
||||
{
|
||||
return _dictionary.Keys;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将 OptionBase 按 Group 分类存入字典
|
||||
/// 将 OptionBase 按 Tab 分类存入字典
|
||||
/// </summary>
|
||||
private void AddToGroup(OptionBase option)
|
||||
private void AddToTab(OptionBase option)
|
||||
{
|
||||
if (option == null) return;
|
||||
|
||||
if (string.IsNullOrEmpty(option.Group)) return;
|
||||
if (string.IsNullOrEmpty(option.Tab)) return;
|
||||
|
||||
// 如果字典中没有该 Group,则新建一个 List 并加入字典
|
||||
if (!_dictionary.ContainsKey(option.Group))
|
||||
// 如果字典中没有该 Tab,则新建一个 List 并加入字典
|
||||
if (!_dictionary.ContainsKey(option.Tab))
|
||||
{
|
||||
_dictionary[option.Group] = new List<OptionBase>();
|
||||
_dictionary[option.Tab] = new List<OptionBase>();
|
||||
}
|
||||
|
||||
// 将 Option 添加到对应的 Group List 中
|
||||
_dictionary[option.Group].Add(option);
|
||||
// 将 Option 添加到对应的 Tab List 中
|
||||
_dictionary[option.Tab].Add(option);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量添加 OptionBase 到字典
|
||||
/// </summary>
|
||||
private void AddRangeToGroup(IEnumerable<OptionBase> options)
|
||||
private void AddRangeToTab(IEnumerable<OptionBase> options)
|
||||
{
|
||||
if (options == null) return;
|
||||
|
||||
foreach (var option in options)
|
||||
{
|
||||
AddToGroup(option);
|
||||
AddToTab(option);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
namespace NBF
|
||||
{
|
||||
public class SettingsDef
|
||||
public static class SettingsDef
|
||||
{
|
||||
public class Group
|
||||
public static class Group
|
||||
{
|
||||
public const string Graphic = "Graphic";
|
||||
public const string Keyboard = "Keyboard";
|
||||
public const string Controller = "Controller";
|
||||
public const string Language = "Language";
|
||||
public const string Sound = "Sound";
|
||||
}
|
||||
|
||||
public static class Tab
|
||||
{
|
||||
public const string Graphic = "Graphic";
|
||||
public const string Keyboard = "Keyboard";
|
||||
|
||||
3
Assets/Scripts/NBC/Sound.meta
Normal file
3
Assets/Scripts/NBC/Sound.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f46be0a4fb246e2a6eb08f7cba069d6
|
||||
timeCreated: 1749530178
|
||||
10
Assets/Scripts/NBC/Sound/Sound.cs
Normal file
10
Assets/Scripts/NBC/Sound/Sound.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace NBC
|
||||
{
|
||||
public class Sound
|
||||
{
|
||||
public static void Play(string path)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/Sound/Sound.cs.meta
Normal file
3
Assets/Scripts/NBC/Sound/Sound.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02eb15d4c0464accaa7d2b90433c8b8c
|
||||
timeCreated: 1749530280
|
||||
93
Assets/Scripts/NBC/Sound/SoundManager.cs
Normal file
93
Assets/Scripts/NBC/Sound/SoundManager.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
namespace NBC
|
||||
{
|
||||
public enum AudioChannelType
|
||||
{
|
||||
BGM,
|
||||
SFX,
|
||||
UI,
|
||||
Ambient,
|
||||
Player
|
||||
}
|
||||
|
||||
public class SoundManager : MonoBehaviour
|
||||
{
|
||||
[Header("Mixer Settings")] public AudioMixer mixer;
|
||||
|
||||
[Header("Mixer Group Routing")] public AudioMixerGroup bgmGroup;
|
||||
public AudioMixerGroup sfxGroup;
|
||||
public AudioMixerGroup uiGroup;
|
||||
public AudioMixerGroup ambientGroup;
|
||||
public AudioMixerGroup playerGroup;
|
||||
private Dictionary<AudioChannelType, AudioMixerGroup> groupMap;
|
||||
|
||||
public static SoundManager Inst { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Inst = this;
|
||||
Init();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Log.Info("UI 模块初始化");
|
||||
}
|
||||
|
||||
void Init()
|
||||
{
|
||||
groupMap = new Dictionary<AudioChannelType, AudioMixerGroup>
|
||||
{
|
||||
{ AudioChannelType.BGM, bgmGroup },
|
||||
{ AudioChannelType.SFX, sfxGroup },
|
||||
{ AudioChannelType.UI, uiGroup },
|
||||
{ AudioChannelType.Ambient, ambientGroup },
|
||||
{ AudioChannelType.Player, playerGroup },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void PlaySound(AudioClip clip, AudioChannelType type, Vector3 position = default, bool is3D = false)
|
||||
{
|
||||
if (clip == null) return;
|
||||
GameObject go = new GameObject("Audio_" + clip.name);
|
||||
go.transform.position = position;
|
||||
|
||||
AudioSource source = go.AddComponent<AudioSource>();
|
||||
source.clip = clip;
|
||||
source.outputAudioMixerGroup = groupMap[type];
|
||||
source.spatialBlend = is3D ? 1f : 0f;
|
||||
source.Play();
|
||||
|
||||
Destroy(go, clip.length + 0.5f); // 延迟销毁
|
||||
}
|
||||
|
||||
public void SetVolume(AudioChannelType type, float volume01)
|
||||
{
|
||||
string exposedName = type + "Volume";
|
||||
mixer.SetFloat(exposedName, Mathf.Log10(Mathf.Clamp01(volume01)) * 20);
|
||||
}
|
||||
|
||||
public void SetMasterVolume(float volume01)
|
||||
{
|
||||
mixer.SetFloat("MasterVolume", Mathf.Log10(Mathf.Clamp01(volume01)) * 20);
|
||||
}
|
||||
|
||||
// public void LoadVolumes()
|
||||
// {
|
||||
// foreach (AudioChannelType type in System.Enum.GetValues(typeof(AudioChannelType)))
|
||||
// {
|
||||
// string exposed = type + "Volume";
|
||||
// float volume = PlayerPrefs.GetFloat(exposed, 1f);
|
||||
// SetVolume(type, volume);
|
||||
// }
|
||||
//
|
||||
// float master = PlayerPrefs.GetFloat("MasterVolume", 1f);
|
||||
// SetMasterVolume(master);
|
||||
// }
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/NBC/Sound/SoundManager.cs.meta
Normal file
3
Assets/Scripts/NBC/Sound/SoundManager.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2d7fdf813c745158477dbca5fff93ee
|
||||
timeCreated: 1749530271
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.Video;
|
||||
|
||||
namespace NBF
|
||||
@@ -14,7 +15,6 @@ namespace NBF
|
||||
[SerializeField] private GameObject startCanvas;
|
||||
[SerializeField] private bool playVideo;
|
||||
|
||||
|
||||
private void CheckOver(VideoPlayer vp)
|
||||
{
|
||||
Destroy(startCanvas);
|
||||
@@ -26,6 +26,7 @@ namespace NBF
|
||||
Log.Open = true;
|
||||
Inst = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
// new GameObject("GameManager").AddComponent<GameManager>();
|
||||
}
|
||||
|
||||
@@ -72,12 +73,12 @@ namespace NBF
|
||||
Lan.Inst.AddLanguageModule((int)LanguageModuleType.Text, new LanguageText());
|
||||
Lan.Inst.AddLanguageModule((int)LanguageModuleType.Image, new LanguageImage());
|
||||
Lan.Inst.AddLanguageModule((int)LanguageModuleType.Font, new LanguageFont());
|
||||
|
||||
|
||||
foreach (var key in LanguageConst.languageMap.Keys)
|
||||
{
|
||||
Lan.Inst.AddLanguage(key);
|
||||
}
|
||||
|
||||
|
||||
UI.Inst.SetUILanguage<UILangeageConfig>();
|
||||
Lan.Inst.AutoUseLanguage();
|
||||
}
|
||||
@@ -138,8 +139,8 @@ namespace NBF
|
||||
// UI.Inst.OpenUI<FishingShopPanel>();
|
||||
LoadData();
|
||||
UI.Inst.OpenUI<CommonTopPanel>();
|
||||
// UI.Inst.OpenUI<FishingPanel>();
|
||||
Fishing.Inst.Go(1);
|
||||
UI.Inst.OpenUI<FishingPanel>();
|
||||
// Fishing.Inst.Go(1);
|
||||
// UI.Inst.OpenUI<SettingPanel>();
|
||||
// UI.Inst.OpenUI<HomePanel>();
|
||||
}
|
||||
|
||||
@@ -142,20 +142,20 @@ namespace NBF
|
||||
range.SetValue((int)Slider.value);
|
||||
UpdateValueText();
|
||||
}
|
||||
// else if (Option is RangeOptionFloat rangeOptionFloat)
|
||||
// {
|
||||
// rangeOptionFloat.SetValue((float)Math.Round(Slider.value, 1));
|
||||
// // Slider
|
||||
// SliderTitle.text = Math.Round(rangeOptionFloat.GetValue(), 1).ToString(CultureInfo.InvariantCulture);
|
||||
// Debug.LogError(Slider.value);
|
||||
// }
|
||||
}
|
||||
|
||||
private void UpdateValueText()
|
||||
{
|
||||
if (Option is RangeOption range)
|
||||
{
|
||||
TextSliderValue.text = Math.Round(range.GetValue() / 10f, 1).ToString(CultureInfo.InvariantCulture);
|
||||
if (range.ShowRate > 0)
|
||||
{
|
||||
TextSliderValue.text = Math.Round(range.GetValue() / 10f, 1).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextSliderValue.text = range.GetValue().ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,6 @@ namespace NBF
|
||||
public GImage back;
|
||||
[AutoFind(Name = "Menu")]
|
||||
public CommonMenu Menu;
|
||||
[AutoFind(Name = "TextTitle")]
|
||||
public GTextField TextTitle;
|
||||
[AutoFind(Name = "Introduce")]
|
||||
public IntroduceTag Introduce;
|
||||
[AutoFind(Name = "List")]
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
|
||||
|
||||
using System.Collections.Generic;
|
||||
using FairyGUI;
|
||||
using UnityEngine;
|
||||
using NBC;
|
||||
using NBF.Setting;
|
||||
using Unity.VisualScripting;
|
||||
using UIPanel = NBC.UIPanel;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
@@ -12,10 +15,8 @@ namespace NBF
|
||||
public override string UIPackName => "Main";
|
||||
public override string UIResName => "SettingPanel";
|
||||
|
||||
private List<TabListData> tabList = new List<TabListData>();
|
||||
|
||||
|
||||
private string _currentGroup = "";
|
||||
private readonly List<TabListData> tabList = new List<TabListData>();
|
||||
private string _currentTab = "";
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
@@ -23,7 +24,7 @@ namespace NBF
|
||||
IsShowCursor = true;
|
||||
IsDontBack = true;
|
||||
|
||||
var groupNames = Settings.Instance.GetAllGroups();
|
||||
var groupNames = Settings.Instance.GetAllTabs();
|
||||
foreach (var group in groupNames)
|
||||
{
|
||||
var tab = new TabListData
|
||||
@@ -33,6 +34,7 @@ namespace NBF
|
||||
tabList.Add(tab);
|
||||
}
|
||||
|
||||
|
||||
Menu.OnTabChange += ChangeTab;
|
||||
List.onClickItem.Set(OnClickListItem);
|
||||
}
|
||||
@@ -50,24 +52,45 @@ namespace NBF
|
||||
if (index < 0) return;
|
||||
Log.Info($"Change tab index={index}");
|
||||
var tabListData = tabList[index];
|
||||
_currentGroup = tabListData.Name;
|
||||
_currentTab = tabListData.Name;
|
||||
ResetSettingList();
|
||||
}
|
||||
|
||||
|
||||
private void ResetSettingList()
|
||||
{
|
||||
TextTitle.text = Lan.Get(_currentGroup);
|
||||
// TextTitle.text = Lan.Get(_currentGroup);
|
||||
|
||||
List.RemoveChildrenToPool();
|
||||
if (string.IsNullOrEmpty(_currentGroup)) return;
|
||||
var options = Settings.Instance.GetOptionsByGroup(_currentGroup);
|
||||
|
||||
if (string.IsNullOrEmpty(_currentTab)) return;
|
||||
var options = Settings.Instance.GetOptionsByTab(_currentTab);
|
||||
Dictionary<string, List<OptionBase>> groupOptions = new Dictionary<string, List<OptionBase>>();
|
||||
foreach (var option in options)
|
||||
{
|
||||
if (List.AddItemFromPool() is SettingItem item)
|
||||
if (!groupOptions.TryGetValue(option.Group, out List<OptionBase> list))
|
||||
{
|
||||
item.SetData(option);
|
||||
list = new List<OptionBase>();
|
||||
groupOptions.Add(option.Group, list);
|
||||
}
|
||||
|
||||
list.Add(option);
|
||||
}
|
||||
|
||||
var url = UIPackage.GetItemURL(UIPackName, "SettingSubTitleItem");
|
||||
foreach (var key in groupOptions.Keys)
|
||||
{
|
||||
var value = groupOptions[key];
|
||||
if (List.AddItemFromPool(url) is GLabel label)
|
||||
{
|
||||
label.title = Lan.Get(key);
|
||||
}
|
||||
|
||||
foreach (var option in value)
|
||||
{
|
||||
if (List.AddItemFromPool() is SettingItem item)
|
||||
{
|
||||
item.SetData(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +102,7 @@ namespace NBF
|
||||
|
||||
private void OnApplySettings()
|
||||
{
|
||||
var options = Settings.Instance.GetOptionsByGroup(_currentGroup);
|
||||
var options = Settings.Instance.GetOptionsByTab(_currentTab);
|
||||
|
||||
foreach (var option in options)
|
||||
{
|
||||
@@ -89,7 +112,7 @@ namespace NBF
|
||||
|
||||
private void OnResetSettings()
|
||||
{
|
||||
var options = Settings.Instance.GetOptionsByGroup(_currentGroup);
|
||||
var options = Settings.Instance.GetOptionsByTab(_currentTab);
|
||||
|
||||
foreach (var option in options)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user