123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using System;
- using System.Collections;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- [RequireComponent(typeof(Animation))]
- public class uGUISelectableAnimation : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IEventSystemHandler
- {
- private void Start()
- {
- this.OnReset();
- }
- public virtual void OnPointerEnter(PointerEventData eventData)
- {
- if (!this.m_AnimationButtonPuyo)
- {
- return;
- }
- if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
- {
- return;
- }
- CanvasGroup canvasGroup = this.GetCanvasGroup();
- if (canvasGroup != null && !canvasGroup.interactable)
- {
- return;
- }
- IEnumerator enumerator = this.m_AnimationButtonPuyo.GetEnumerator();
- try
- {
- while (enumerator.MoveNext())
- {
- object obj = enumerator.Current;
- AnimationState animationState = (AnimationState)obj;
- animationState.speed = 1f;
- }
- }
- finally
- {
- IDisposable disposable;
- if ((disposable = (enumerator as IDisposable)) != null)
- {
- disposable.Dispose();
- }
- }
- this.m_AnimationButtonPuyo.Play();
- }
- public virtual void OnPointerExit(PointerEventData eventData)
- {
- if (!this.m_AnimationButtonPuyo)
- {
- return;
- }
- if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
- {
- return;
- }
- CanvasGroup canvasGroup = this.GetCanvasGroup();
- if (canvasGroup != null && !canvasGroup.interactable)
- {
- return;
- }
- IEnumerator enumerator = this.m_AnimationButtonPuyo.GetEnumerator();
- try
- {
- while (enumerator.MoveNext())
- {
- object obj = enumerator.Current;
- AnimationState animationState = (AnimationState)obj;
- if (animationState.speed < 0f)
- {
- return;
- }
- animationState.speed = -1f;
- if (animationState.normalizedTime <= 0f)
- {
- animationState.normalizedTime = 1f;
- }
- }
- }
- finally
- {
- IDisposable disposable;
- if ((disposable = (enumerator as IDisposable)) != null)
- {
- disposable.Dispose();
- }
- }
- this.m_AnimationButtonPuyo.Play();
- }
- public virtual void OnPointerClick(PointerEventData eventData)
- {
- if (eventData.button != PointerEventData.InputButton.Left)
- {
- return;
- }
- if (!this.m_AnimationButtonPuyo)
- {
- return;
- }
- if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
- {
- return;
- }
- CanvasGroup canvasGroup = this.GetCanvasGroup();
- if (canvasGroup != null && !canvasGroup.interactable)
- {
- return;
- }
- IEnumerator enumerator = this.m_AnimationButtonPuyo.GetEnumerator();
- try
- {
- while (enumerator.MoveNext())
- {
- object obj = enumerator.Current;
- AnimationState animationState = (AnimationState)obj;
- if (animationState.speed < 0f)
- {
- return;
- }
- animationState.speed = -1f;
- if (animationState.normalizedTime <= 0f)
- {
- animationState.normalizedTime = 1f;
- }
- }
- }
- finally
- {
- IDisposable disposable;
- if ((disposable = (enumerator as IDisposable)) != null)
- {
- disposable.Dispose();
- }
- }
- this.m_AnimationButtonPuyo.Play();
- }
- private CanvasGroup GetCanvasGroup()
- {
- return base.GetComponentInParent<CanvasGroup>();
- }
- private void OnReset()
- {
- if (!this.m_AnimationButtonPuyo)
- {
- this.m_AnimationButtonPuyo = base.GetComponent<Animation>();
- this.m_AnimationButtonPuyo.enabled = true;
- this.m_AnimationButtonPuyo.playAutomatically = false;
- this.m_AnimationButtonPuyo.clip = Resources.Load<AnimationClip>("SceneEdit/MainMenu/Animation/ButtonPuyo");
- }
- this.m_PtrSelectable = base.GetComponentInChildren<Selectable>();
- if (this.m_PtrSelectable && !this.m_PtrSelectable.gameObject.GetComponent<uGUISelectableSound>())
- {
- this.m_PtrSelectable.gameObject.AddComponent<uGUISelectableSound>();
- }
- }
- [SerializeField]
- [HideInInspector]
- private Animation m_AnimationButtonPuyo;
- [SerializeField]
- [HideInInspector]
- private Selectable m_PtrSelectable;
- }
|