TweenCG.cs 3.5 KB

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