92 lines
3.4 KiB
C#
92 lines
3.4 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using Animancer;
|
|
using Logic.Audio;
|
|
using Unity.VisualScripting;
|
|
|
|
namespace UI.Common{
|
|
public class MainUIButtonHoverEffect : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
|
{
|
|
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);
|
|
}
|
|
AudioManager.Instance.PlayAudio("SFX/UI_buttonHover",0,0,false);
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (IsLocked) return;
|
|
if (_image != null) _buttonImage.color = normalColor;
|
|
if (popinClip != null && _animancer != null)
|
|
{
|
|
_animancer.Play(popinClip);
|
|
}
|
|
}
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
// 如果锁定,则不响应点击
|
|
if (IsLocked)
|
|
{
|
|
//Debug.Log("Button is locked, cannot be clicked.");
|
|
// 可以在这里播放一个锁定音效或者显示一个提示
|
|
// AudioManager.Instance.PlayAudio("SFX/UI_buttonLocked");
|
|
return;
|
|
}
|
|
// --- 在这里添加你的点击逻辑 ---
|
|
//Debug.Log("Button Clicked!");
|
|
// 播放点击音效
|
|
AudioManager.Instance.PlayAudio("SFX/UI_buttonClick", 0, 0, false);
|
|
// 示例:可以触发一个自定义事件或者调用其他方法
|
|
// UIManager.Instance.OpenPanel("SomePanel");
|
|
// GameController.Instance.StartGame();
|
|
// --- --------------------- ---
|
|
}
|
|
|
|
|
|
|
|
public void SetLock()
|
|
{
|
|
if (IsLocked)
|
|
{
|
|
_buttonImage.color = LockedColor;
|
|
/*var colors = _button.colors;
|
|
colors.normalColor = LockedColor;
|
|
colors.highlightedColor = LockedColor;
|
|
colors.pressedColor = LockedColor;
|
|
_button.colors = colors;*/
|
|
}
|
|
}
|
|
}
|
|
} |