2025-08-18 23:16:13 +08:00

43 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Logic.Audio;
using UnityEngine;
using UnityEngine.EventSystems;
// using UnityEngine.UI; // 如果 ButtonSFX 不需要直接操作UI.Image则不需要
namespace TH1Audio
{
// 继承自 SFXComponent处理按钮的Hover和Click音效
public class ButtonSFX : SFXComponent, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
[Header("Button SFX Settings")]
[Tooltip("鼠标悬停在按钮上时播放的音效资源路径或名称。")]
public string hoverAudioName = "SFX/UI_buttonHover";
[Tooltip("鼠标点击按钮时播放的音效资源路径或名称。")]
public string clickAudioName = "SFX/UI_buttonClick";
// Awake方法由SFXComponent处理这里可以添加ButtonSFX特有的初始化
public void OnPointerEnter(PointerEventData eventData)
{
// 可以在这里添加额外的条件,例如如果按钮被锁定则不播放音效
// 比如从MainUIButtonHoverEffect中获取IsLocked状态
// MainUIButtonHoverEffect hoverEffect = GetComponent<MainUIButtonHoverEffect>(); // 如果它们在同一个GameObject上
// if (hoverEffect != null && hoverEffect.IsLocked) return;
AudioManager.Instance.PlayAudio(hoverAudioName,0,0,false);
}
public void OnPointerExit(PointerEventData eventData)
{
// 通常鼠标移出时不需要播放音效,但如果有特殊需求可以添加
// 比如停止一个循环的hover音效
// StopSound(hoverAudioName); // 需要AudioManager支持
}
public void OnPointerClick(PointerEventData eventData)
{
AudioManager.Instance.PlayAudio(clickAudioName,0,0,false);
}
}
}