uGUISelectableAnimation.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. [RequireComponent(typeof(Animation))]
  7. public class uGUISelectableAnimation : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IEventSystemHandler
  8. {
  9. private void Start()
  10. {
  11. this.OnReset();
  12. }
  13. public virtual void OnPointerEnter(PointerEventData eventData)
  14. {
  15. if (!this.m_AnimationButtonPuyo)
  16. {
  17. return;
  18. }
  19. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  20. {
  21. return;
  22. }
  23. CanvasGroup canvasGroup = this.GetCanvasGroup();
  24. if (canvasGroup != null && !canvasGroup.interactable)
  25. {
  26. return;
  27. }
  28. IEnumerator enumerator = this.m_AnimationButtonPuyo.GetEnumerator();
  29. try
  30. {
  31. while (enumerator.MoveNext())
  32. {
  33. object obj = enumerator.Current;
  34. AnimationState animationState = (AnimationState)obj;
  35. animationState.speed = 1f;
  36. }
  37. }
  38. finally
  39. {
  40. IDisposable disposable;
  41. if ((disposable = (enumerator as IDisposable)) != null)
  42. {
  43. disposable.Dispose();
  44. }
  45. }
  46. this.m_AnimationButtonPuyo.Play();
  47. }
  48. public virtual void OnPointerExit(PointerEventData eventData)
  49. {
  50. if (!this.m_AnimationButtonPuyo)
  51. {
  52. return;
  53. }
  54. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  55. {
  56. return;
  57. }
  58. CanvasGroup canvasGroup = this.GetCanvasGroup();
  59. if (canvasGroup != null && !canvasGroup.interactable)
  60. {
  61. return;
  62. }
  63. IEnumerator enumerator = this.m_AnimationButtonPuyo.GetEnumerator();
  64. try
  65. {
  66. while (enumerator.MoveNext())
  67. {
  68. object obj = enumerator.Current;
  69. AnimationState animationState = (AnimationState)obj;
  70. if (animationState.speed < 0f)
  71. {
  72. return;
  73. }
  74. animationState.speed = -1f;
  75. if (animationState.normalizedTime <= 0f)
  76. {
  77. animationState.normalizedTime = 1f;
  78. }
  79. }
  80. }
  81. finally
  82. {
  83. IDisposable disposable;
  84. if ((disposable = (enumerator as IDisposable)) != null)
  85. {
  86. disposable.Dispose();
  87. }
  88. }
  89. this.m_AnimationButtonPuyo.Play();
  90. }
  91. public virtual void OnPointerClick(PointerEventData eventData)
  92. {
  93. if (eventData.button != PointerEventData.InputButton.Left)
  94. {
  95. return;
  96. }
  97. if (!this.m_AnimationButtonPuyo)
  98. {
  99. return;
  100. }
  101. if (this.m_PtrSelectable && (!this.m_PtrSelectable.interactable || !this.m_PtrSelectable.enabled))
  102. {
  103. return;
  104. }
  105. CanvasGroup canvasGroup = this.GetCanvasGroup();
  106. if (canvasGroup != null && !canvasGroup.interactable)
  107. {
  108. return;
  109. }
  110. IEnumerator enumerator = this.m_AnimationButtonPuyo.GetEnumerator();
  111. try
  112. {
  113. while (enumerator.MoveNext())
  114. {
  115. object obj = enumerator.Current;
  116. AnimationState animationState = (AnimationState)obj;
  117. if (animationState.speed < 0f)
  118. {
  119. return;
  120. }
  121. animationState.speed = -1f;
  122. if (animationState.normalizedTime <= 0f)
  123. {
  124. animationState.normalizedTime = 1f;
  125. }
  126. }
  127. }
  128. finally
  129. {
  130. IDisposable disposable;
  131. if ((disposable = (enumerator as IDisposable)) != null)
  132. {
  133. disposable.Dispose();
  134. }
  135. }
  136. this.m_AnimationButtonPuyo.Play();
  137. }
  138. private CanvasGroup GetCanvasGroup()
  139. {
  140. return base.GetComponentInParent<CanvasGroup>();
  141. }
  142. private void OnReset()
  143. {
  144. if (!this.m_AnimationButtonPuyo)
  145. {
  146. this.m_AnimationButtonPuyo = base.GetComponent<Animation>();
  147. this.m_AnimationButtonPuyo.enabled = true;
  148. this.m_AnimationButtonPuyo.playAutomatically = false;
  149. this.m_AnimationButtonPuyo.clip = Resources.Load<AnimationClip>("SceneEdit/MainMenu/Animation/ButtonPuyo");
  150. }
  151. this.m_PtrSelectable = base.GetComponentInChildren<Selectable>();
  152. if (this.m_PtrSelectable && !this.m_PtrSelectable.gameObject.GetComponent<uGUISelectableSound>())
  153. {
  154. this.m_PtrSelectable.gameObject.AddComponent<uGUISelectableSound>();
  155. }
  156. }
  157. [SerializeField]
  158. [HideInInspector]
  159. private Animation m_AnimationButtonPuyo;
  160. [SerializeField]
  161. [HideInInspector]
  162. private Selectable m_PtrSelectable;
  163. }