ButtonSFX.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using KairoEngine.SFX;
  6. using UnityEngine.EventSystems;
  7. namespace KairoEngine.UI.SFX
  8. {
  9. [HideMonoScript]
  10. public class ButtonSFX : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerDownHandler, IPointerUpHandler
  11. {
  12. public SFXClip onPointerEnterSFX;
  13. public SFXClip onPointerExitSFX;
  14. public SFXClip onPointerDownSFX;
  15. public SFXClip onPointerUpSFX;
  16. public SFXClip onClickSFX;
  17. public void OnPointerEnter(PointerEventData eventData)
  18. {
  19. if(MouseInputUIBlocker.BlockedByUI) return;
  20. PlaySFX(onPointerEnterSFX);
  21. }
  22. public void OnPointerExit(PointerEventData eventData)
  23. {
  24. PlaySFX(onPointerExitSFX);
  25. }
  26. public void OnPointerDown(PointerEventData eventData)
  27. {
  28. if(MouseInputUIBlocker.BlockedByUI) return;
  29. PlaySFX(onPointerDownSFX);
  30. }
  31. public void OnPointerUp(PointerEventData eventData)
  32. {
  33. PlaySFX(onPointerUpSFX);
  34. }
  35. public void OnMouseEnter()
  36. {
  37. if(MouseInputUIBlocker.BlockedByUI) return;
  38. PlaySFX(onPointerEnterSFX);
  39. }
  40. public void OnMouseExit()
  41. {
  42. PlaySFX(onPointerExitSFX);
  43. }
  44. public void OnMouseDown()
  45. {
  46. if(MouseInputUIBlocker.BlockedByUI) return;
  47. PlaySFX(onPointerDownSFX);
  48. }
  49. public void OnMouseUp()
  50. {
  51. PlaySFX(onPointerUpSFX);
  52. }
  53. public void OnClick()
  54. {
  55. PlaySFX(onClickSFX);
  56. }
  57. private void PlaySFX(SFXClip clip)
  58. {
  59. if(clip == null) return;
  60. if(this.gameObject.activeInHierarchy == false) return;
  61. SoundController.EmmitSound(clip, new Vector3());
  62. }
  63. }
  64. }