TweenText.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System;
  4. using System.Collections;
  5. public class TweenText : Tween
  6. {
  7. #region 变量
  8. public override bool InOrigin
  9. {
  10. get
  11. {
  12. if (Math.Abs(Target.fontSize - Origin) < 0.0005f)
  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.fontSize = (int)Origin;
  28. FinishBackward();
  29. }
  30. }
  31. }
  32. public override bool InDestination
  33. {
  34. get
  35. {
  36. if (Math.Abs(Target.fontSize - 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.fontSize = (int)Destination;
  52. FinishForward();
  53. }
  54. }
  55. }
  56. protected float Delta;
  57. protected float Origin;
  58. protected float Destination;
  59. protected Text Target;
  60. protected CurveFunctionF Func;
  61. #endregion
  62. public TweenText(Text target, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false) : base(cg, target)
  63. {
  64. Func = ManaAnim.CurveFuncDicF[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. if (InBackward)
  79. {
  80. Timer = Duration - Timer;
  81. }
  82. else
  83. {
  84. Target.fontSize = (int) Origin;
  85. }
  86. }
  87. public override void StartBackward()
  88. {
  89. base.StartBackward();
  90. if (InForward)
  91. {
  92. Timer = Duration - Timer;
  93. }
  94. else
  95. {
  96. Target.fontSize = (int) Destination;
  97. }
  98. }
  99. public override bool DoForward()
  100. {
  101. Timer += Time.fixedDeltaTime;
  102. if (Timer > Duration)
  103. {
  104. FinishForward();
  105. Timer = 0;
  106. InForward = false;
  107. InDestination = true;
  108. if (OnForwardFinish != null)
  109. {
  110. OnForwardFinish.Invoke();
  111. }
  112. ManaAnim.TweenForList.Remove(this);
  113. return true;
  114. }
  115. else
  116. {
  117. Target.fontSize = (int) Func(Timer, Duration, Origin, Delta);
  118. return false;
  119. }
  120. }
  121. public override bool DoBackward()
  122. {
  123. Timer += Time.fixedDeltaTime;
  124. if (Timer > Duration)
  125. {
  126. FinishBackward();
  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.fontSize = (int) Func(Timer, Duration, Destination, -Delta);
  140. return false;
  141. }
  142. }
  143. }