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