ButtonSFX.cs 2.1 KB

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