85 lines
2.4 KiB
C#
85 lines
2.4 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using AibisDream.Utility;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class OnelineOption : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text text;
|
|
[SerializeField] private BaseButton button;
|
|
[SerializeField] private Image arrow;
|
|
|
|
[Header("颜色配置")]
|
|
[SerializeField] private ColorBlock colorBlock;
|
|
|
|
[Header("已选择颜色")]
|
|
[SerializeField] private Color selectedColor;
|
|
private DialogOption _option;
|
|
|
|
public void Init()
|
|
{
|
|
button.onStateTransition.AddListener(OnStateTransition);
|
|
}
|
|
|
|
public void SetOption(DialogOption option, Action hide = null)
|
|
{
|
|
_option = option;
|
|
|
|
if (!option.IsAvailable)
|
|
{
|
|
// 不可用,设置为不可选
|
|
button.interactable = false;
|
|
text.SetText($"<s>{option.Line}</s>");
|
|
return;
|
|
}
|
|
|
|
text.SetText(option.Line);
|
|
button.onClick.AddListener(() =>
|
|
{
|
|
option.Select();
|
|
hide?.Invoke();
|
|
});
|
|
}
|
|
|
|
private void OnStateTransition(SelectionType state, bool instant)
|
|
{
|
|
switch (state)
|
|
{
|
|
case SelectionType.Normal:
|
|
arrow.SetAlpha(0f);
|
|
SetColor(colorBlock.normalColor);
|
|
break;
|
|
case SelectionType.Highlighted:
|
|
arrow.SetAlpha(1f);
|
|
SetColor(colorBlock.highlightedColor);
|
|
break;
|
|
case SelectionType.Pressed:
|
|
arrow.SetAlpha(1f);
|
|
SetColor(colorBlock.pressedColor);
|
|
break;
|
|
case SelectionType.Selected:
|
|
arrow.SetAlpha(1f);
|
|
SetColor(colorBlock.selectedColor);
|
|
break;
|
|
case SelectionType.Disabled:
|
|
arrow.SetAlpha(0f);
|
|
SetColor(colorBlock.disabledColor);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private Color GetNormalColor()
|
|
{
|
|
return colorBlock.normalColor;
|
|
}
|
|
|
|
private void SetColor(Color color)
|
|
{
|
|
arrow.color = color;
|
|
text.color = color;
|
|
}
|
|
}
|
|
} |