TweenRect.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.Equal(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. BackwardFinish();
  27. }
  28. }
  29. }
  30. public override bool InDestination
  31. {
  32. get
  33. {
  34. if (Target.sizeDelta.Equal(Destination))
  35. {
  36. _InDestination = true;
  37. }
  38. else
  39. {
  40. _InDestination = false;
  41. }
  42. return _InDestination;
  43. }
  44. set
  45. {
  46. _InDestination = value;
  47. if (_InDestination)
  48. {
  49. Target.sizeDelta = Destination;
  50. ForwardFinish();
  51. }
  52. }
  53. }
  54. public Vector2 Delta;
  55. public Vector2 Origin;
  56. public Vector2 Destination;
  57. public RectTransform Target;
  58. public CurveFunctionV Func;
  59. #endregion
  60. public TweenRect(RectTransform target, Vector2 origin, Vector2 destination, float duration, bool originActive, bool destActive, Curve curve,bool cg=false) : base(cg, curve, target)
  61. {
  62. CanvasGroup = target.GetComponent<CanvasGroup>();
  63. Func = ManaAnim.CurveFuncDicV[curve];
  64. Target = target;
  65. InForward = false;
  66. InBackward = false;
  67. Delta = destination - origin;
  68. Origin = origin;
  69. Duration = duration;
  70. DestActive = destActive;
  71. Destination = destination;
  72. OriginActive = originActive;
  73. }
  74. public override void StartForward()
  75. {
  76. base.StartForward();
  77. if (InBackward)
  78. {
  79. Timer = ManaAnim.GetTimerVec(Target.sizeDelta, Duration, Origin, Delta, Curve);
  80. }
  81. }
  82. public override void StartBackward()
  83. {
  84. base.StartBackward();
  85. if (InForward)
  86. {
  87. Timer = ManaAnim.GetTimerVec(Target.sizeDelta, Duration, Destination, -Delta, Curve);
  88. }
  89. }
  90. public override bool DoForward()
  91. {
  92. Timer += Time.fixedDeltaTime;
  93. if (Timer > Duration)
  94. {
  95. InForward = false;
  96. InDestination = true;
  97. if (OnForwardFinish != null)
  98. {
  99. OnForwardFinish.Invoke();
  100. }
  101. return true;
  102. }
  103. else
  104. {
  105. Target.sizeDelta = Func(Timer, Duration, Origin, Delta);
  106. return false;
  107. }
  108. }
  109. public override bool DoBackward()
  110. {
  111. Timer += Time.fixedDeltaTime;
  112. if (Timer > Duration)
  113. {
  114. InBackward = false;
  115. InOrigin = true;
  116. if (OnBackwardFinish != null)
  117. {
  118. OnBackwardFinish.Invoke();
  119. }
  120. return true;
  121. }
  122. else
  123. {
  124. Target.sizeDelta = Func(Timer, Duration, Destination, -Delta);
  125. return false;
  126. }
  127. }
  128. }