1
+ using System ;
1
2
using Unity . UIWidgets . foundation ;
2
3
using Unity . UIWidgets . ui ;
3
4
using UnityEngine ;
4
5
5
6
namespace Unity . UIWidgets . animation {
6
7
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
+ }
8
20
9
21
public Curve flipped {
10
22
get { return new FlippedCurve ( this ) ; }
@@ -16,7 +28,7 @@ public override string ToString() {
16
28
}
17
29
18
30
class _Linear : Curve {
19
- public override float transform ( float t ) {
31
+ protected override float transformInternal ( float t ) {
20
32
return t ;
21
33
}
22
34
}
@@ -28,12 +40,7 @@ public SawTooth(int count) {
28
40
29
41
public readonly int count ;
30
42
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 ) {
37
44
t *= this . count ;
38
45
return t - ( int ) t ;
39
46
}
@@ -56,17 +63,13 @@ public Interval(float begin, float end, Curve curve = null) {
56
63
57
64
public readonly Curve curve ;
58
65
59
- public override float transform ( float t ) {
66
+ protected override float transformInternal ( float t ) {
60
67
D . assert ( t >= 0.0 && t <= 1.0 ) ;
61
68
D . assert ( this . begin >= 0.0 ) ;
62
69
D . assert ( this . begin <= 1.0 ) ;
63
70
D . assert ( this . end >= 0.0 ) ;
64
71
D . assert ( this . end <= 1.0 ) ;
65
72
D . assert ( this . end >= this . begin ) ;
66
- if ( t == 0.0 || t == 1.0 ) {
67
- return t ;
68
- }
69
-
70
73
t = ( ( t - this . begin ) / ( this . end - this . begin ) ) . clamp ( 0.0f , 1.0f ) ;
71
74
if ( t == 0.0 || t == 1.0 ) {
72
75
return t ;
@@ -91,14 +94,9 @@ public Threshold(float threshold) {
91
94
92
95
public readonly float threshold ;
93
96
94
- public override float transform ( float t ) {
95
- D . assert ( t >= 0.0 && t <= 1.0 ) ;
97
+ protected override float transformInternal ( float t ) {
96
98
D . assert ( this . threshold >= 0.0 ) ;
97
99
D . assert ( this . threshold <= 1.0 ) ;
98
- if ( t == 0.0 || t == 1.0 ) {
99
- return t ;
100
- }
101
-
102
100
return t < this . threshold ? 0.0f : 1.0f ;
103
101
}
104
102
}
@@ -127,9 +125,7 @@ float _evaluateCubic(float a, float b, float m) {
127
125
m * m * m ;
128
126
}
129
127
130
- public override float transform ( float t ) {
131
- D . assert ( t >= 0.0 && t <= 1.0 ) ;
132
-
128
+ protected override float transformInternal ( float t ) {
133
129
float start = 0.0f ;
134
130
float end = 1.0f ;
135
131
while ( true ) {
@@ -161,7 +157,7 @@ public FlippedCurve(Curve curve) {
161
157
162
158
public readonly Curve curve ;
163
159
164
- public override float transform ( float t ) {
160
+ protected override float transformInternal ( float t ) {
165
161
return 1.0f - this . curve . transform ( 1.0f - t ) ;
166
162
}
167
163
@@ -174,8 +170,7 @@ class _DecelerateCurve : Curve {
174
170
internal _DecelerateCurve ( ) {
175
171
}
176
172
177
- public override float transform ( float t ) {
178
- D . assert ( t >= 0.0 && t <= 1.0 ) ;
173
+ protected override float transformInternal ( float t ) {
179
174
t = 1.0f - t ;
180
175
return 1.0f - t * t ;
181
176
}
@@ -185,8 +180,7 @@ class _BounceInCurve : Curve {
185
180
internal _BounceInCurve ( ) {
186
181
}
187
182
188
- public override float transform ( float t ) {
189
- D . assert ( t >= 0.0 && t <= 1.0 ) ;
183
+ protected override float transformInternal ( float t ) {
190
184
return 1.0f - Curves . _bounce ( 1.0f - t ) ;
191
185
}
192
186
}
@@ -195,8 +189,7 @@ class _BounceOutCurve : Curve {
195
189
internal _BounceOutCurve ( ) {
196
190
}
197
191
198
- public override float transform ( float t ) {
199
- D . assert ( t >= 0.0f && t <= 1.0f ) ;
192
+ protected override float transformInternal ( float t ) {
200
193
return Curves . _bounce ( t ) ;
201
194
}
202
195
}
@@ -205,8 +198,7 @@ class _BounceInOutCurve : Curve {
205
198
internal _BounceInOutCurve ( ) {
206
199
}
207
200
208
- public override float transform ( float t ) {
209
- D . assert ( t >= 0.0 && t <= 1.0f ) ;
201
+ protected override float transformInternal ( float t ) {
210
202
if ( t < 0.5f ) {
211
203
return ( 1.0f - Curves . _bounce ( 1.0f - t ) ) * 0.5f ;
212
204
}
@@ -223,8 +215,7 @@ public ElasticInCurve(float period = 0.4f) {
223
215
224
216
public readonly float period ;
225
217
226
- public override float transform ( float t ) {
227
- D . assert ( t >= 0.0 && t <= 1.0 ) ;
218
+ protected override float transformInternal ( float t ) {
228
219
float s = this . period / 4.0f ;
229
220
t = t - 1.0f ;
230
221
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) {
242
233
243
234
public readonly float period ;
244
235
245
- public override float transform ( float t ) {
246
- D . assert ( t >= 0.0 && t <= 1.0 ) ;
236
+ protected override float transformInternal ( float t ) {
247
237
float s = this . period / 4.0f ;
248
238
return Mathf . Pow ( 2.0f , - 10.0f * t ) * Mathf . Sin ( ( t - s ) * ( Mathf . PI * 2.0f ) / this . period ) + 1.0f ;
249
239
}
@@ -260,8 +250,7 @@ public ElasticInOutCurve(float period = 0.4f) {
260
250
261
251
public readonly float period ;
262
252
263
- public override float transform ( float t ) {
264
- D . assert ( t >= 0.0 && t <= 1.0 ) ;
253
+ protected override float transformInternal ( float t ) {
265
254
float s = this . period / 4.0f ;
266
255
t = 2.0f * t - 1.0f ;
267
256
if ( t < 0.0 ) {
@@ -345,7 +334,9 @@ public static class Curves {
345
334
346
335
public static readonly Cubic easeInOutBack = new Cubic ( 0.68f , - 0.55f , 0.265f , 1.55f ) ;
347
336
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 ) ;
349
340
350
341
public static readonly Curve bounceIn = new _BounceInCurve ( ) ;
351
342
0 commit comments