uGUISelectableSound.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. public class uGUISelectableSound : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, IPointerClickHandler, IEventSystemHandler
  6. {
  7. private void Start()
  8. {
  9. this.OnReset();
  10. }
  11. public virtual void OnPointerEnter(PointerEventData eventData)
  12. {
  13. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  14. {
  15. return;
  16. }
  17. CanvasGroup canvasGroup = this.GetCanvasGroup();
  18. if (canvasGroup != null && !canvasGroup.interactable)
  19. {
  20. return;
  21. }
  22. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
  23. }
  24. public virtual void OnPointerDown(PointerEventData eventData)
  25. {
  26. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  27. {
  28. return;
  29. }
  30. CanvasGroup canvasGroup = this.GetCanvasGroup();
  31. if (canvasGroup != null && !canvasGroup.interactable)
  32. {
  33. return;
  34. }
  35. this.m_IsPointerDown = true;
  36. }
  37. public virtual void OnPointerClick(PointerEventData eventData)
  38. {
  39. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  40. {
  41. return;
  42. }
  43. if (this.m_IsPointerDown)
  44. {
  45. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
  46. this.m_IsPointerDown = false;
  47. }
  48. }
  49. private CanvasGroup GetCanvasGroup()
  50. {
  51. return base.GetComponentInParent<CanvasGroup>();
  52. }
  53. private void OnReset()
  54. {
  55. this.m_PtrSelectable = base.GetComponentInChildren<Selectable>();
  56. this.m_IsPointerDown = false;
  57. }
  58. [SerializeField]
  59. [HideInInspector]
  60. private Selectable m_PtrSelectable;
  61. private bool m_IsPointerDown;
  62. }