68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using System;
|
|
using AibisDream.Utility;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class LanguageItem : AbsFormItem
|
|
{
|
|
public override FieldType FieldType => FieldType.Select;
|
|
|
|
#region 索引
|
|
|
|
private TMP_Text _showText;
|
|
private Button _leftBtn;
|
|
private Button _rightBtn;
|
|
|
|
#endregion
|
|
|
|
#region 数据
|
|
|
|
[Header("可选项")]
|
|
public UIFormOption[] options;
|
|
private int _curIdx;
|
|
|
|
#endregion
|
|
|
|
protected override void InitField()
|
|
{
|
|
var field = transform.Find("Field");
|
|
_showText = field.Find("ShowText").GetComponent<TMP_Text>();
|
|
_leftBtn = field.Find("Left Btn").GetComponent<Button>();
|
|
_rightBtn = field.Find("Right Btn").GetComponent<Button>();
|
|
|
|
_leftBtn.onClick.AddListener(LeftRoll);
|
|
_rightBtn.onClick.AddListener(RightRoll);
|
|
}
|
|
|
|
public override void SetValue(string value)
|
|
{
|
|
var idx = Array.FindIndex(options, item => item.prop == value);
|
|
if (idx < 0)
|
|
{
|
|
Debug.LogError($"{prop} setting value error");
|
|
}
|
|
|
|
_curIdx = idx;
|
|
_showText.text = options[idx].label;
|
|
}
|
|
|
|
private void LeftRoll()
|
|
{
|
|
_curIdx = CommonUtil.LoopStep(_curIdx, 0, options.Length - 1);
|
|
_showText.text = options[_curIdx].label;
|
|
|
|
OnValueChanged?.Invoke(prop, options[_curIdx].prop);
|
|
}
|
|
|
|
private void RightRoll()
|
|
{
|
|
_curIdx = CommonUtil.LoopStep(_curIdx, 0, options.Length - 1, -1);
|
|
_showText.text = options[_curIdx].label;
|
|
|
|
OnValueChanged?.Invoke(prop, options[_curIdx].prop);
|
|
}
|
|
}
|
|
} |