uGUIButtonSE.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. using UnityEngine.UI;
  5. public class uGUIButtonSE : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IEventSystemHandler
  6. {
  7. private void Start()
  8. {
  9. if (base.transform.parent)
  10. {
  11. CanvasGroup component = base.transform.parent.GetComponent<CanvasGroup>();
  12. if (component)
  13. {
  14. this.m_ParentSelectable = component;
  15. }
  16. }
  17. }
  18. public void ClickSEPlay()
  19. {
  20. if (string.IsNullOrEmpty(this.m_PointerClickSE))
  21. {
  22. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
  23. }
  24. else
  25. {
  26. GameMain.Instance.SoundMgr.PlaySe(this.m_PointerClickSE, false);
  27. }
  28. }
  29. public void OnPointerEnter(PointerEventData eventData)
  30. {
  31. if (!this.m_SelectableComp)
  32. {
  33. return;
  34. }
  35. if (!this.m_SelectableComp.enabled || !this.m_SelectableComp.interactable)
  36. {
  37. return;
  38. }
  39. if (this.m_ParentSelectable && !this.m_ParentSelectable.interactable)
  40. {
  41. return;
  42. }
  43. if (string.IsNullOrEmpty(this.m_PointerEnterSE))
  44. {
  45. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
  46. }
  47. else
  48. {
  49. GameMain.Instance.SoundMgr.PlaySe(this.m_PointerEnterSE, false);
  50. }
  51. }
  52. public void OnPointerClick(PointerEventData eventData)
  53. {
  54. if (this.m_MyButton)
  55. {
  56. return;
  57. }
  58. if (!this.m_SelectableComp)
  59. {
  60. return;
  61. }
  62. if (!this.m_SelectableComp.enabled || !this.m_SelectableComp.interactable)
  63. {
  64. return;
  65. }
  66. this.ClickSEPlay();
  67. }
  68. [SerializeField]
  69. [HideInInspector]
  70. private Selectable m_SelectableComp;
  71. [SerializeField]
  72. [HideInInspector]
  73. private Button m_MyButton;
  74. [SerializeField]
  75. [Header("カーソルが乗ったときに再生するSEファイル名(拡張子含む)")]
  76. private string m_PointerEnterSE = string.Empty;
  77. [SerializeField]
  78. [Header("このUIをクリックしたときに再生するSEファイル名(拡張子含む)")]
  79. private string m_PointerClickSE = string.Empty;
  80. private CanvasGroup m_ParentSelectable;
  81. }