TweenRect.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. using UnityEngine;
  2. using System.Collections;
  3. public class TweenRect : Tween
  4. {
  5. #region
  6. public override bool InOrigin
  7. {
  8. get
  9. {
  10. if (Target.sizeDelta == Origin)
  11. {
  12. _InOrigin = true;
  13. }
  14. else
  15. {
  16. _InOrigin = false;
  17. }
  18. return _InOrigin;
  19. }
  20. set
  21. {
  22. _InOrigin = value;
  23. if (_InOrigin)
  24. {
  25. Target.sizeDelta = Origin;
  26. Target.SetActive(OriginActive);
  27. if (CG != null)
  28. {
  29. CG.interactable = OriginActive;
  30. }
  31. }
  32. }
  33. }
  34. public override bool InDestination
  35. {
  36. get
  37. {
  38. if (Target.sizeDelta == Destination)
  39. {
  40. _InDestination = true;
  41. }
  42. else
  43. {
  44. _InDestination = false;
  45. }
  46. return _InDestination;
  47. }
  48. set
  49. {
  50. _InDestination = value;
  51. if (_InDestination)
  52. {
  53. Target.sizeDelta = Destination;
  54. Target.SetActive(DestActive);
  55. if (CG != null)
  56. {
  57. CG.interactable = DestActive;
  58. }
  59. }
  60. }
  61. }
  62. protected Vector2 Delta;
  63. protected Vector2 Origin;
  64. protected Vector2 Destination;
  65. protected CanvasGroup CG;
  66. protected RectTransform Target;
  67. protected CurveFunctionV Func;
  68. #endregion
  69. public TweenRect(RectTransform target, Vector2 origin, Vector2 destination, float duration, bool originActive, bool destActive, Curve curve)
  70. {
  71. CG = target.GetComponent<CanvasGroup>();
  72. Func = ManaAnim.CurveFuncDicV[curve];
  73. Target = target;
  74. InForward = false;
  75. InBackward = false;
  76. Delta = destination - origin;
  77. Origin = origin;
  78. Duration = duration;
  79. DestActive = destActive;
  80. Destination = destination;
  81. OriginActive = originActive;
  82. }
  83. public override void StartForward()
  84. {
  85. base.StartForward();
  86. Target.SetActive(true);
  87. if (CG != null)
  88. {
  89. CG.interactable = false;
  90. }
  91. if (InBackward)
  92. {
  93. Timer = Duration - Timer;
  94. }
  95. else
  96. {
  97. Target.sizeDelta = Origin;
  98. }
  99. }
  100. public override void StartBackward()
  101. {
  102. base.StartBackward();
  103. Target.SetActive(true);
  104. if (CG != null)
  105. {
  106. CG.interactable = false;
  107. }
  108. if (InForward)
  109. {
  110. Timer = Duration - Timer;
  111. }
  112. else
  113. {
  114. Target.sizeDelta = Destination;
  115. }
  116. }
  117. public override bool DoForward()
  118. {
  119. Timer += Time.fixedDeltaTime;
  120. if (Timer > Duration)
  121. {
  122. Timer = 0;
  123. InForward = false;
  124. InDestination = true;
  125. if (OnForwardFinish != null)
  126. {
  127. OnForwardFinish.Invoke();
  128. }
  129. ManaAnim.TweenForList.Remove(this);
  130. return true;
  131. }
  132. else
  133. {
  134. Target.sizeDelta = Func(Timer, Duration, Origin, Delta);
  135. return false;
  136. }
  137. }
  138. public override bool DoBackward()
  139. {
  140. Timer += Time.fixedDeltaTime;
  141. if (Timer > Duration)
  142. {
  143. Timer = 0;
  144. InBackward = false;
  145. InOrigin = true;
  146. if (OnBackwardFinish != null)
  147. {
  148. OnBackwardFinish.Invoke();
  149. }
  150. ManaAnim.TweenBacList.Remove(this);
  151. return true;
  152. }
  153. else
  154. {
  155. Target.sizeDelta = Func(Timer, Duration, Destination, -Delta);
  156. return false;
  157. }
  158. }
  159. }