TweenGra.cs 3.4 KB

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