设置相关功能脚本呢
This commit is contained in:
37
Assets/Scripts/UI/Settings/SettingItem.Designer.cs
generated
Normal file
37
Assets/Scripts/UI/Settings/SettingItem.Designer.cs
generated
Normal file
@@ -0,0 +1,37 @@
|
||||
/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
|
||||
|
||||
|
||||
using FairyGUI;
|
||||
using FairyGUI.Utils;
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public partial class SettingItem
|
||||
{
|
||||
public const string URL = "ui://hxr7rc7pe9z88";
|
||||
|
||||
public Controller style;
|
||||
public GImage back;
|
||||
public GTextField TextName;
|
||||
public GTextField TextInfo;
|
||||
public GSlider Slider;
|
||||
public BtnInputControl BtnPrev;
|
||||
public BtnInputControl BtnNext;
|
||||
|
||||
public override void ConstructFromXML(XML xml)
|
||||
{
|
||||
base.ConstructFromXML(xml);
|
||||
|
||||
style = GetController("style");
|
||||
back = (GImage)GetChild("back");
|
||||
TextName = (GTextField)GetChild("TextName");
|
||||
TextInfo = (GTextField)GetChild("TextInfo");
|
||||
Slider = (GSlider)GetChild("Slider");
|
||||
BtnPrev = (BtnInputControl)GetChild("BtnPrev");
|
||||
BtnNext = (BtnInputControl)GetChild("BtnNext");
|
||||
OnInited();
|
||||
UILanguage.TrySetComponentLanguage(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/Settings/SettingItem.Designer.cs.meta
Normal file
2
Assets/Scripts/UI/Settings/SettingItem.Designer.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a99a3eda0b402314e998ff820ebb5b4d
|
||||
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()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/Settings/SettingItem.cs.meta
Normal file
2
Assets/Scripts/UI/Settings/SettingItem.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 80e8fd431260afb49a8f82e2b17ad93d
|
||||
32
Assets/Scripts/UI/Settings/SettingPanel.Designer.cs
generated
Normal file
32
Assets/Scripts/UI/Settings/SettingPanel.Designer.cs
generated
Normal file
@@ -0,0 +1,32 @@
|
||||
/**本脚本为自动生成,每次生成会覆盖!请勿手动修改,生成插件文档及项目地址:https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
|
||||
|
||||
using FairyGUI;
|
||||
using FairyGUI.Utils;
|
||||
using NBC;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary> </summary>
|
||||
public partial class SettingPanel
|
||||
{
|
||||
public GObject this[string aKey] => ContentPane.GetChild(aKey);
|
||||
[AutoFind(Name = "back")]
|
||||
public GImage back;
|
||||
[AutoFind(Name = "Menu")]
|
||||
public CommonMenu Menu;
|
||||
[AutoFind(Name = "TextTitle")]
|
||||
public GTextField TextTitle;
|
||||
[AutoFind(Name = "Introduce")]
|
||||
public GComponent Introduce;
|
||||
[AutoFind(Name = "List")]
|
||||
public GList List;
|
||||
[AutoFind(Name = "BottomMenu")]
|
||||
public BottomMenu BottomMenu;
|
||||
[AutoFind(Name = "BottomLine")]
|
||||
public GImage BottomLine;
|
||||
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/Settings/SettingPanel.Designer.cs.meta
Normal file
2
Assets/Scripts/UI/Settings/SettingPanel.Designer.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bd9a89782b28a342b84154c6ca06d32
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/UI/Settings/SettingPanel.cs.meta
Normal file
2
Assets/Scripts/UI/Settings/SettingPanel.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9daadae7a1573774cb1b07ea9dc5b077
|
||||
Reference in New Issue
Block a user