69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using Animancer;
|
|
using Unity.VisualScripting;
|
|
|
|
namespace UI.Common{
|
|
public class MainUIButtonHoverEffect : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public AnimationClip popupClip;
|
|
public AnimationClip popinClip;
|
|
public Color normalColor;
|
|
public Color highlightColor;
|
|
public Color LockedColor;
|
|
public bool IsLocked = false;
|
|
private Image _image;
|
|
private Image _buttonImage;
|
|
private AnimancerComponent _animancer;
|
|
|
|
private void Awake()
|
|
{
|
|
_image = GetComponent<Image>();
|
|
_buttonImage = this.transform.Find("AnimObject/Button").GetComponent<Image>();
|
|
_animancer = this.transform.Find("AnimObject").GetComponent<AnimancerComponent>();
|
|
if (_animancer == null)
|
|
_animancer = this.transform.Find("AnimObject").AddComponent<AnimancerComponent>();
|
|
if (popupClip == null)
|
|
popupClip = Resources.Load<AnimationClip>("Animations/UI/MainUIButton/MainUIButtonPopup");
|
|
|
|
if (popinClip == null)
|
|
popinClip = Resources.Load<AnimationClip>("Animations/UI/MainUIButton/MainUIButtonPopin");
|
|
if (IsLocked)
|
|
SetLock();
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (IsLocked) return;
|
|
if (_image != null) _buttonImage.color = highlightColor;
|
|
if (popupClip != null && _animancer != null)
|
|
{
|
|
_animancer.Play(popupClip);
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (IsLocked) return;
|
|
if (_image != null) _buttonImage.color = normalColor;
|
|
if (popinClip != null && _animancer != null)
|
|
{
|
|
_animancer.Play(popinClip);
|
|
}
|
|
}
|
|
|
|
public void SetLock()
|
|
{
|
|
if (IsLocked)
|
|
{
|
|
_buttonImage.color = LockedColor;
|
|
/*var colors = _button.colors;
|
|
colors.normalColor = LockedColor;
|
|
colors.highlightedColor = LockedColor;
|
|
colors.pressedColor = LockedColor;
|
|
_button.colors = colors;*/
|
|
}
|
|
}
|
|
}
|
|
} |