2025-02-21 10:22:11 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
using System;
|
|
|
|
using UnityEngine.UI;
|
2025-02-28 16:11:11 +08:00
|
|
|
using AudioType = AlicizaX.Audio.Runtime.AudioType;
|
2025-02-21 10:22:11 +08:00
|
|
|
|
|
|
|
namespace AlicizaX.UI.Extension
|
|
|
|
{
|
|
|
|
public enum ButtonSoundType
|
|
|
|
{
|
|
|
|
Down,
|
|
|
|
Up,
|
|
|
|
Click,
|
|
|
|
Enter,
|
2025-04-17 16:03:39 +08:00
|
|
|
Exit
|
2025-02-21 10:22:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public class ButtonSoundCell
|
|
|
|
{
|
|
|
|
public ButtonSoundType ButtonSoundType = ButtonSoundType.Click;
|
2025-02-28 16:11:11 +08:00
|
|
|
public string ButtonUISoundName = "";
|
2025-02-21 10:22:11 +08:00
|
|
|
}
|
|
|
|
|
2025-04-17 16:03:39 +08:00
|
|
|
public class UIButtonSuper : Button,IButton
|
2025-02-21 10:22:11 +08:00
|
|
|
{
|
|
|
|
public List<ButtonSoundCell> m_ButtonUISounds = new List<ButtonSoundCell>();
|
|
|
|
|
|
|
|
public ButtonSoundCell GetButtonSound(ButtonSoundType buttonSoundType)
|
|
|
|
{
|
|
|
|
foreach (var buttonSound in m_ButtonUISounds)
|
|
|
|
{
|
|
|
|
if (buttonSound.ButtonSoundType == buttonSoundType)
|
|
|
|
{
|
|
|
|
return buttonSound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void PlayButtonSound(ButtonSoundType buttonSoundType)
|
|
|
|
{
|
|
|
|
ButtonSoundCell buttonSound = GetButtonSound(buttonSoundType);
|
2025-03-14 17:51:49 +08:00
|
|
|
if (buttonSound == null || string.IsNullOrEmpty(buttonSound.ButtonUISoundName))
|
2025-02-21 10:22:11 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2025-02-28 16:11:11 +08:00
|
|
|
|
|
|
|
GameApp.Audio.Play(AudioType.UISound, buttonSound.ButtonUISoundName, false, GameApp.Audio.UISoundVolume, true);
|
2025-02-21 10:22:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnPointerEnter(PointerEventData eventData)
|
|
|
|
{
|
|
|
|
base.OnPointerEnter(eventData);
|
|
|
|
PlayButtonSound(ButtonSoundType.Enter);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnPointerDown(PointerEventData eventData)
|
|
|
|
{
|
|
|
|
base.OnPointerDown(eventData);
|
|
|
|
PlayButtonSound(ButtonSoundType.Down);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnPointerUp(PointerEventData eventData)
|
|
|
|
{
|
|
|
|
base.OnPointerUp(eventData);
|
|
|
|
PlayButtonSound(ButtonSoundType.Up);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnPointerExit(PointerEventData eventData)
|
|
|
|
{
|
|
|
|
base.OnPointerExit(eventData);
|
|
|
|
PlayButtonSound(ButtonSoundType.Exit);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnPointerClick(PointerEventData eventData)
|
|
|
|
{
|
2025-04-17 16:03:39 +08:00
|
|
|
base.OnPointerClick(eventData);
|
2025-02-21 10:22:11 +08:00
|
|
|
PlayButtonSound(ButtonSoundType.Click);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|