设置相关功能脚本呢
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user