uGUISelectableSound.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_IsPlayHover)
  14. {
  15. return;
  16. }
  17. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  18. {
  19. return;
  20. }
  21. CanvasGroup canvasGroup = this.GetCanvasGroup();
  22. if (canvasGroup != null && !canvasGroup.interactable)
  23. {
  24. return;
  25. }
  26. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
  27. }
  28. public virtual void OnPointerDown(PointerEventData eventData)
  29. {
  30. if (!this.m_IsPlayClick)
  31. {
  32. return;
  33. }
  34. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  35. {
  36. return;
  37. }
  38. CanvasGroup canvasGroup = this.GetCanvasGroup();
  39. if (canvasGroup != null && !canvasGroup.interactable)
  40. {
  41. return;
  42. }
  43. this.m_IsPointerDown = true;
  44. }
  45. public virtual void OnPointerClick(PointerEventData eventData)
  46. {
  47. if (this.m_IsPointerDown)
  48. {
  49. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
  50. this.m_IsPointerDown = false;
  51. }
  52. }
  53. private CanvasGroup GetCanvasGroup()
  54. {
  55. return base.GetComponentInParent<CanvasGroup>();
  56. }
  57. private void OnReset()
  58. {
  59. this.m_PtrSelectable = base.GetComponentInChildren<Selectable>();
  60. this.m_IsPointerDown = false;
  61. }
  62. [SerializeField]
  63. [HideInInspector]
  64. private Selectable m_PtrSelectable;
  65. private bool m_IsPointerDown;
  66. [SerializeField]
  67. public bool m_IsPlayHover = true;
  68. [SerializeField]
  69. public bool m_IsPlayClick = true;
  70. }