57 lines
1.4 KiB
C#
57 lines
1.4 KiB
C#
using System;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class BaseButton : Button
|
|
{
|
|
public SelectionType CurSelectionState => TransStateToType(currentSelectionState);
|
|
|
|
public UnityEvent<SelectionType, bool> onStateTransition = new();
|
|
|
|
protected override void DoStateTransition(SelectionState state, bool instant)
|
|
{
|
|
if (!gameObject.activeInHierarchy)
|
|
return;
|
|
|
|
onStateTransition?.Invoke(TransStateToType(state), instant);
|
|
}
|
|
|
|
protected static SelectionType TransStateToType(SelectionState state)
|
|
{
|
|
return Enum.Parse<SelectionType>(state.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 因为作用域问题把枚举转出来用
|
|
/// </summary>
|
|
public enum SelectionType
|
|
{
|
|
/// <summary>
|
|
/// The UI object can be selected.
|
|
/// </summary>
|
|
Normal,
|
|
|
|
/// <summary>
|
|
/// The UI object is highlighted.
|
|
/// </summary>
|
|
Highlighted,
|
|
|
|
/// <summary>
|
|
/// The UI object is pressed.
|
|
/// </summary>
|
|
Pressed,
|
|
|
|
/// <summary>
|
|
/// The UI object is selected
|
|
/// </summary>
|
|
Selected,
|
|
|
|
/// <summary>
|
|
/// The UI object cannot be selected.
|
|
/// </summary>
|
|
Disabled
|
|
}
|
|
} |