FTween.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using UnityEngine;
  2. using System;
  3. namespace Flux
  4. {
  5. [Serializable]
  6. public abstract class FTweenBase
  7. {
  8. [SerializeField]
  9. protected FEasingType _easingType = FEasingType.EaseInOutQuad;
  10. public FEasingType EasingType { get { return _easingType; } set { _easingType = value; } }
  11. }
  12. [Serializable]
  13. public abstract class FTween<T> : FTweenBase
  14. {
  15. [SerializeField]
  16. protected T _from;
  17. public T From { get { return _from; } set { _from = value; } }
  18. [SerializeField]
  19. protected T _to;
  20. public T To { get { return _to; } set { _to = value; } }
  21. public abstract T GetValue( float t );
  22. }
  23. [Serializable]
  24. public class FTweenColor : FTween<Color>
  25. {
  26. public FTweenColor( Color from, Color to )
  27. {
  28. _from = from;
  29. _to = to;
  30. }
  31. public override Color GetValue( float t )
  32. {
  33. Color color;
  34. color.r = FEasing.Tween( _from.r, _to.r, t, _easingType );
  35. color.g = FEasing.Tween( _from.g, _to.g, t, _easingType );
  36. color.b = FEasing.Tween( _from.b, _to.b, t, _easingType );
  37. color.a = FEasing.Tween( _from.a, _to.a, t, _easingType );
  38. return color;
  39. }
  40. }
  41. [Serializable]
  42. public class FTweenFloat : FTween<float>
  43. {
  44. public FTweenFloat( float from, float to )
  45. {
  46. _from = from;
  47. _to = to;
  48. }
  49. public override float GetValue( float t )
  50. {
  51. return FEasing.Tween( _from, _to, t, _easingType );
  52. }
  53. }
  54. [Serializable]
  55. public class FTweenVector2 : FTween<Vector2>
  56. {
  57. public FTweenVector2( Vector2 from, Vector2 to )
  58. {
  59. _from = from;
  60. _to = to;
  61. }
  62. public override Vector2 GetValue( float t )
  63. {
  64. Vector2 v;
  65. v.x = FEasing.Tween( _from.x, _to.x, t, _easingType );
  66. v.y = FEasing.Tween( _from.y, _to.y, t, _easingType );
  67. return v;
  68. }
  69. }
  70. [Serializable]
  71. public class FTweenVector3 : FTween<Vector3>
  72. {
  73. public FTweenVector3( Vector3 from, Vector3 to )
  74. {
  75. _from = from;
  76. _to = to;
  77. }
  78. public override Vector3 GetValue( float t )
  79. {
  80. Vector3 v;
  81. v.x = FEasing.Tween( _from.x, _to.x, t, _easingType );
  82. v.y = FEasing.Tween( _from.y, _to.y, t, _easingType );
  83. v.z = FEasing.Tween( _from.z, _to.z, t, _easingType );
  84. return v;
  85. }
  86. }
  87. [Serializable]
  88. public class FTweenVector4 : FTween<Vector4>
  89. {
  90. public FTweenVector4( Vector4 from, Vector4 to )
  91. {
  92. _from = from;
  93. _to = to;
  94. }
  95. public override Vector4 GetValue( float t )
  96. {
  97. Vector4 v;
  98. v.x = FEasing.Tween( _from.x, _to.x, t, _easingType );
  99. v.y = FEasing.Tween( _from.y, _to.y, t, _easingType );
  100. v.z = FEasing.Tween( _from.z, _to.z, t, _easingType );
  101. v.w = FEasing.Tween( _from.w, _to.w, t, _easingType );
  102. return v;
  103. }
  104. }
  105. [Serializable]
  106. public class FTweenQuaternion : FTween<Quaternion>
  107. {
  108. public FTweenQuaternion( Quaternion from, Quaternion to )
  109. {
  110. _from = from;
  111. _to = to;
  112. }
  113. public override Quaternion GetValue( float t )
  114. {
  115. Quaternion q;
  116. q.x = FEasing.Tween( _from.x, _to.x, t, _easingType );
  117. q.y = FEasing.Tween( _from.y, _to.y, t, _easingType );
  118. q.z = FEasing.Tween( _from.z, _to.z, t, _easingType );
  119. q.w = FEasing.Tween( _from.w, _to.w, t, _easingType );
  120. return q;
  121. }
  122. }
  123. }