1+ using System ;
12using Unity . UIWidgets . foundation ;
23using Unity . UIWidgets . ui ;
34using UnityEngine ;
45
56namespace Unity . UIWidgets . animation {
67 public abstract class Curve {
7- public abstract float transform ( float t ) ;
8+ public float transform ( float t ) {
9+ D . assert ( t >= 0.0f && t <= 1.0f ) ;
10+ if ( t == 0.0f || t == 1.0f ) {
11+ return t ;
12+ }
13+
14+ return this . transformInternal ( t ) ;
15+ }
16+
17+ protected virtual float transformInternal ( float t ) {
18+ throw new NotImplementedException ( ) ;
19+ }
820
921 public Curve flipped {
1022 get { return new FlippedCurve ( this ) ; }
@@ -16,7 +28,7 @@ public override string ToString() {
1628 }
1729
1830 class _Linear : Curve {
19- public override float transform ( float t ) {
31+ protected override float transformInternal ( float t ) {
2032 return t ;
2133 }
2234 }
@@ -28,12 +40,7 @@ public SawTooth(int count) {
2840
2941 public readonly int count ;
3042
31- public override float transform ( float t ) {
32- D . assert ( t >= 0.0 && t <= 1.0 ) ;
33- if ( t == 1.0f ) {
34- return 1.0f ;
35- }
36-
43+ protected override float transformInternal ( float t ) {
3744 t *= this . count ;
3845 return t - ( int ) t ;
3946 }
@@ -56,17 +63,13 @@ public Interval(float begin, float end, Curve curve = null) {
5663
5764 public readonly Curve curve ;
5865
59- public override float transform ( float t ) {
66+ protected override float transformInternal ( float t ) {
6067 D . assert ( t >= 0.0 && t <= 1.0 ) ;
6168 D . assert ( this . begin >= 0.0 ) ;
6269 D . assert ( this . begin <= 1.0 ) ;
6370 D . assert ( this . end >= 0.0 ) ;
6471 D . assert ( this . end <= 1.0 ) ;
6572 D . assert ( this . end >= this . begin ) ;
66- if ( t == 0.0 || t == 1.0 ) {
67- return t ;
68- }
69-
7073 t = ( ( t - this . begin ) / ( this . end - this . begin ) ) . clamp ( 0.0f , 1.0f ) ;
7174 if ( t == 0.0 || t == 1.0 ) {
7275 return t ;
@@ -91,14 +94,9 @@ public Threshold(float threshold) {
9194
9295 public readonly float threshold ;
9396
94- public override float transform ( float t ) {
95- D . assert ( t >= 0.0 && t <= 1.0 ) ;
97+ protected override float transformInternal ( float t ) {
9698 D . assert ( this . threshold >= 0.0 ) ;
9799 D . assert ( this . threshold <= 1.0 ) ;
98- if ( t == 0.0 || t == 1.0 ) {
99- return t ;
100- }
101-
102100 return t < this . threshold ? 0.0f : 1.0f ;
103101 }
104102 }
@@ -127,9 +125,7 @@ float _evaluateCubic(float a, float b, float m) {
127125 m * m * m ;
128126 }
129127
130- public override float transform ( float t ) {
131- D . assert ( t >= 0.0 && t <= 1.0 ) ;
132-
128+ protected override float transformInternal ( float t ) {
133129 float start = 0.0f ;
134130 float end = 1.0f ;
135131 while ( true ) {
@@ -161,7 +157,7 @@ public FlippedCurve(Curve curve) {
161157
162158 public readonly Curve curve ;
163159
164- public override float transform ( float t ) {
160+ protected override float transformInternal ( float t ) {
165161 return 1.0f - this . curve . transform ( 1.0f - t ) ;
166162 }
167163
@@ -174,8 +170,7 @@ class _DecelerateCurve : Curve {
174170 internal _DecelerateCurve ( ) {
175171 }
176172
177- public override float transform ( float t ) {
178- D . assert ( t >= 0.0 && t <= 1.0 ) ;
173+ protected override float transformInternal ( float t ) {
179174 t = 1.0f - t ;
180175 return 1.0f - t * t ;
181176 }
@@ -185,8 +180,7 @@ class _BounceInCurve : Curve {
185180 internal _BounceInCurve ( ) {
186181 }
187182
188- public override float transform ( float t ) {
189- D . assert ( t >= 0.0 && t <= 1.0 ) ;
183+ protected override float transformInternal ( float t ) {
190184 return 1.0f - Curves . _bounce ( 1.0f - t ) ;
191185 }
192186 }
@@ -195,8 +189,7 @@ class _BounceOutCurve : Curve {
195189 internal _BounceOutCurve ( ) {
196190 }
197191
198- public override float transform ( float t ) {
199- D . assert ( t >= 0.0f && t <= 1.0f ) ;
192+ protected override float transformInternal ( float t ) {
200193 return Curves . _bounce ( t ) ;
201194 }
202195 }
@@ -205,8 +198,7 @@ class _BounceInOutCurve : Curve {
205198 internal _BounceInOutCurve ( ) {
206199 }
207200
208- public override float transform ( float t ) {
209- D . assert ( t >= 0.0 && t <= 1.0f ) ;
201+ protected override float transformInternal ( float t ) {
210202 if ( t < 0.5f ) {
211203 return ( 1.0f - Curves . _bounce ( 1.0f - t ) ) * 0.5f ;
212204 }
@@ -223,8 +215,7 @@ public ElasticInCurve(float period = 0.4f) {
223215
224216 public readonly float period ;
225217
226- public override float transform ( float t ) {
227- D . assert ( t >= 0.0 && t <= 1.0 ) ;
218+ protected override float transformInternal ( float t ) {
228219 float s = this . period / 4.0f ;
229220 t = t - 1.0f ;
230221 return - Mathf . Pow ( 2.0f , 10.0f * t ) * Mathf . Sin ( ( t - s ) * ( Mathf . PI * 2.0f ) / this . period ) ;
@@ -242,8 +233,7 @@ public ElasticOutCurve(float period = 0.4f) {
242233
243234 public readonly float period ;
244235
245- public override float transform ( float t ) {
246- D . assert ( t >= 0.0 && t <= 1.0 ) ;
236+ protected override float transformInternal ( float t ) {
247237 float s = this . period / 4.0f ;
248238 return Mathf . Pow ( 2.0f , - 10.0f * t ) * Mathf . Sin ( ( t - s ) * ( Mathf . PI * 2.0f ) / this . period ) + 1.0f ;
249239 }
@@ -260,8 +250,7 @@ public ElasticInOutCurve(float period = 0.4f) {
260250
261251 public readonly float period ;
262252
263- public override float transform ( float t ) {
264- D . assert ( t >= 0.0 && t <= 1.0 ) ;
253+ protected override float transformInternal ( float t ) {
265254 float s = this . period / 4.0f ;
266255 t = 2.0f * t - 1.0f ;
267256 if ( t < 0.0 ) {
@@ -345,7 +334,9 @@ public static class Curves {
345334
346335 public static readonly Cubic easeInOutBack = new Cubic ( 0.68f , - 0.55f , 0.265f , 1.55f ) ;
347336
348- public static readonly Curve fastOutSlowIn = new Cubic ( 0.4f , 0.0f , 0.2f , 1.0f ) ;
337+ public static readonly Cubic fastOutSlowIn = new Cubic ( 0.4f , 0.0f , 0.2f , 1.0f ) ;
338+
339+ public static readonly Cubic slowMiddle = new Cubic ( 0.15f , 0.85f , 0.85f , 0.15f ) ;
349340
350341 public static readonly Curve bounceIn = new _BounceInCurve ( ) ;
351342
0 commit comments