1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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_IsPlayHover)
- {
- return;
- }
- 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_IsPlayClick)
- {
- return;
- }
- 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_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;
- [SerializeField]
- public bool m_IsPlayHover = true;
- [SerializeField]
- public bool m_IsPlayClick = true;
- }
|