forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasingCurves.cs
More file actions
233 lines (199 loc) · 5.6 KB
/
Copy pathEasingCurves.cs
File metadata and controls
233 lines (199 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
namespace UnityEngine.UIElements.Experimental
{
public static class Easing
{
private const float HalfPi = Mathf.PI / 2;
public static float Step(float t)
{
return t < 0.5f ? 0 : 1;
}
public static float Linear(float t)
{
return t;
}
public static float InSine(float t)
{
return Mathf.Sin(HalfPi * (t - 1)) + 1;
}
public static float OutSine(float t)
{
return Mathf.Sin(t * HalfPi);
}
public static float InOutSine(float t)
{
return (Mathf.Sin(Mathf.PI * (t - 0.5f)) + 1) * 0.5f;
}
public static float InQuad(float t)
{
return t * t;
}
public static float OutQuad(float t)
{
return t * (2 - t);
}
public static float InOutQuad(float t)
{
t *= 2;
if (t < 1.0f)
return (t * t * 0.5f);
return -0.5f * ((t - 1) * (t - 3) - 1);
}
public static float InCubic(float t)
{
return InPower(t, 3);
}
public static float OutCubic(float t)
{
return OutPower(t, 3);
}
public static float InOutCubic(float t)
{
return InOutPower(t, 3);
}
public static float InPower(float t, int power)
{
return Mathf.Pow(t, power);
}
public static float OutPower(float t, int power)
{
var sign = power % 2 == 0 ? -1 : 1;
return (float)(sign * (Mathf.Pow(t - 1, power) + sign));
}
public static float InOutPower(float t, int power)
{
t *= 2;
if (t < 1) return InPower(t, power) * 0.5f;
var sign = power % 2 == 0 ? -1 : 1;
return sign * 0.5f * (Mathf.Pow(t - 2, power) + sign * 2);
}
public static float InBounce(float t)
{
return 1 - OutBounce((1 - t));
}
public static float OutBounce(float t)
{
if (t < (1 / 2.75f))
{
return (7.5625f * t * t);
}
if (t < (2 / 2.75f))
{
float postFix = t -= (1.5f / 2.75f);
return (7.5625f * (postFix) * t + .75f);
}
else if (t < (2.5f / 2.75f))
{
float postFix = t -= (2.25f / 2.75f);
return (7.5625f * (postFix) * t + .9375f);
}
else
{
float postFix = t -= (2.625f / 2.75f);
return (7.5625f * (postFix) * t + .984375f);
}
}
public static float InOutBounce(float t)
{
if (t < 0.5f)
{
return InBounce(t * 2) * 0.5f;
}
else
{
return OutBounce((t - 0.5f) * 2) * 0.5f + 0.5f;
}
}
public static float InElastic(float t)
{
if (t == 0) return 0;
if ((t) == 1) return 1;
float p = .3f;
float s = p / 4;
float power = Mathf.Pow(2, 10 * (t -= 1));
return -(power * Mathf.Sin((t - s) * (2 * Mathf.PI) / p));
}
public static float OutElastic(float t)
{
if (t == 0) return 0;
if (t == 1) return 1;
float p = .3f;
float s = p / 4;
return Mathf.Pow(2, -10 * t) * Mathf.Sin((t - s) * (2 * Mathf.PI) / p) + 1;
}
public static float InOutElastic(float t)
{
if (t < 0.5f)
{
return InElastic(t * 2) * 0.5f;
}
else
{
return OutElastic((t - 0.5f) * 2) * 0.5f + 0.5f;
}
}
public static float InBack(float t)
{
float s = 1.70158f;
return (t) * t * ((s + 1) * t - s);
}
public static float OutBack(float t)
{
return 1 - (InBack(1 - t));
}
public static float InOutBack(float t)
{
if (t < 0.5f)
{
return InBack(t * 2) * 0.5f;
}
else
{
return OutBack((t - 0.5f) * 2) * 0.5f + 0.5f;
}
}
public static float InBack(float t, float s)
{
return (t) * t * ((s + 1) * t - s);
}
public static float OutBack(float t, float s)
{
return 1 - (InBack(1 - t, s));
}
public static float InOutBack(float t, float s)
{
if (t < 0.5f)
{
return InBack(t * 2, s) * 0.5f;
}
else
{
return OutBack((t - 0.5f) * 2, s) * 0.5f + 0.5f;
}
}
public static float InCirc(float t)
{
return -(Mathf.Sqrt(1 - (t * t)) - 1);
}
public static float OutCirc(float t)
{
t = t - 1;
return Mathf.Sqrt(1 - (t * t));
}
public static float InOutCirc(float t)
{
t = t * 2;
if (t < 1)
{
return -0.5f * (Mathf.Sqrt(1 - (t * t)) - 1);
}
else
{
t = t - 2;
return 0.5f * (Mathf.Sqrt(1 - (t * t)) + 1);
}
}
}
}