优化 UI 效果
This commit is contained in:
@@ -9,33 +9,14 @@ namespace SepCore.UI
|
||||
{
|
||||
[SerializeField] private Image _background = null;
|
||||
|
||||
private Color _originalBackgroundColor;
|
||||
|
||||
[SerializeField] private UnityEvent _onPointerEnterAction = new();
|
||||
|
||||
[SerializeField] private UnityEvent _onPointerExitAction = new();
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
_originalBackgroundColor = _background.color;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
_background.color = _originalBackgroundColor;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_background.color = new Color(0.3f, 0.3f, 0.3f, 0.3f);
|
||||
}
|
||||
|
||||
public override void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
base.OnPointerEnter(eventData);
|
||||
if (eventData.button != PointerEventData.InputButton.Left || !IsActive() || !IsInteractable())
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -45,6 +26,7 @@ namespace SepCore.UI
|
||||
|
||||
public override void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
base.OnPointerExit(eventData);
|
||||
if (eventData.button != PointerEventData.InputButton.Left)
|
||||
{
|
||||
return;
|
||||
@@ -55,16 +37,33 @@ namespace SepCore.UI
|
||||
|
||||
public override void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
_background.color = new Color(1f, 0.9f, 0.3f);
|
||||
base.OnSelect(eventData);
|
||||
if (!IsActive() || !IsInteractable())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnterHoverState();
|
||||
}
|
||||
|
||||
public override void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
_background.color = _originalBackgroundColor;
|
||||
base.OnDeselect(eventData);
|
||||
ExitHoverState();
|
||||
}
|
||||
|
||||
protected override void DoStateTransition(SelectionState state, bool instant)
|
||||
{
|
||||
base.DoStateTransition(state, instant);
|
||||
if (transition == Transition.SpriteSwap)
|
||||
{
|
||||
_background.canvasRenderer.SetColor(
|
||||
state == SelectionState.Highlighted || state == SelectionState.Selected
|
||||
? new Color(1f, 0.96f, 0.8f, 1f)
|
||||
: Color.white);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnterHoverState()
|
||||
{
|
||||
if (EventSystem.current.currentSelectedGameObject != gameObject)
|
||||
|
||||
Reference in New Issue
Block a user