12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class uGUISelectableSound : MonoBehaviour, IPointerEnterHandler, IPointerDownHandler, IPointerClickHandler, IEventSystemHandler
- {
- private void Start()
- {
- this.OnReset();
- }
- public virtual void OnPointerEnter(PointerEventData eventData)
- {
- if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
- {
- return;
- }
- CanvasGroup canvasGroup = this.GetCanvasGroup();
- if (canvasGroup != null && !canvasGroup.interactable)
- {
- return;
- }
- GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
- }
- public virtual void OnPointerDown(PointerEventData eventData)
- {
- if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
- {
- return;
- }
- CanvasGroup canvasGroup = this.GetCanvasGroup();
- if (canvasGroup != null && !canvasGroup.interactable)
- {
- return;
- }
- this.m_IsPointerDown = true;
- }
- public virtual void OnPointerClick(PointerEventData eventData)
- {
- if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
- {
- return;
- }
- if (this.m_IsPointerDown)
- {
- GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
- this.m_IsPointerDown = false;
- }
- }
- private CanvasGroup GetCanvasGroup()
- {
- return base.GetComponentInParent<CanvasGroup>();
- }
- private void OnReset()
- {
- this.m_PtrSelectable = base.GetComponentInChildren<Selectable>();
- this.m_IsPointerDown = false;
- }
- [SerializeField]
- [HideInInspector]
- private Selectable m_PtrSelectable;
- private bool m_IsPointerDown;
- }
|