Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit abeb39e

Browse files
committed
Fidget that spinner
1 parent 2270f0e commit abeb39e

File tree

1 file changed

+5
-67
lines changed
  • src/UnityExtension/Assets/Editor/GitHub.Unity/UI

1 file changed

+5
-67
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Spinner.cs

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public override string ToString()
2121
}
2222
}
2323

24-
private readonly float totalAnimationTime = 2f;
24+
private float speed = 120f;
2525
private float currentRotation;
26-
private float startTime;
26+
private float lastTime;
2727
private bool started;
2828
private float centerX;
2929
private float centerY;
@@ -54,7 +54,6 @@ public void Start(float currentTime)
5454
if (started)
5555
return;
5656
started = true;
57-
startTime = currentTime;
5857
}
5958

6059
public void Stop()
@@ -64,9 +63,10 @@ public void Stop()
6463

6564
public float Rotate(float currentTime)
6665
{
67-
var elapsed = Mathf.Repeat(currentTime - startTime, totalAnimationTime);
68-
currentRotation = Linear(elapsed, 360f, totalAnimationTime);
66+
var deltaTime = currentTime - lastTime;
67+
currentRotation += deltaTime * speed * ((Mathf.Sin(currentTime * 1.2f)) + 2);
6968
currentRotation = Mathf.Repeat(currentRotation, 360f);
69+
lastTime = currentTime;
7070
return currentRotation;
7171
}
7272

@@ -141,67 +141,5 @@ private void PopRotation()
141141
var rot = rotations.Pop();
142142
GUIUtility.RotateAroundPivot(-rot.rotation, rot.center);
143143
}
144-
145-
private float ExpoEase(float currentTime, float end, float duration)
146-
{
147-
//Debug.LogFormat("ExpoEase: {0} {1}", currentTime, duration);
148-
currentTime /= duration / 2;
149-
if (currentTime < 1) return duration / 2 * Mathf.Pow(2, 10 * (currentTime - 1));
150-
currentTime--;
151-
return end / 2 * (-Mathf.Pow(2, -10 * currentTime) + 2);
152-
}
153-
private float SinEase(float currentTime, float end, float duration)
154-
{
155-
return -end / 2 * (Mathf.Cos(Mathf.PI * currentTime / duration) - 1);
156-
}
157-
158-
private float SinEaseIn(float t, float c, float d)
159-
{
160-
//Debug.LogFormat("SinEaseIn: {0} {1}", t, d);
161-
162-
return -c * Mathf.Cos(t / d * (Mathf.PI / 2)) + c;
163-
}
164-
private float SinEaseOut(float t, float c, float d)
165-
{
166-
//Debug.LogFormat("SinEaseOut: {0} {1}", t, d);
167-
return c * Mathf.Sin(t / d * (Mathf.PI / 2));
168-
}
169-
170-
private float Linear(float t, float c, float d)
171-
{
172-
//Debug.LogFormat("Linear: {0} {1}", t, d);
173-
return c * t / d;
174-
}
175-
176-
private float CubicIn(float t, float c, float d)
177-
{
178-
//Debug.LogFormat("CubicIn: {0} {1}", t, d);
179-
t /= d;
180-
return c * t * t * t;
181-
}
182-
183-
private float CubicOut(float t, float c, float d)
184-
{
185-
//Debug.LogFormat("CubicOut: {0} {1}", t, d);
186-
t /= d;
187-
t--;
188-
return c * (t * t * t + 1);
189-
}
190-
191-
private float CubicInOut(float t, float c, float d)
192-
{
193-
t /= d / 2;
194-
if (t < 1) return c / 2 * t * t * t;
195-
t -= 2;
196-
return c / 2 * (t * t * t + 2);
197-
}
198-
199-
private float QuintInOut(float t, float c, float d)
200-
{
201-
t /= d / 2;
202-
if (t < 1) return c / 2 * t * t * t * t * t;
203-
t -= 2;
204-
return c / 2 * (t * t * t * t * t + 2);
205-
}
206144
}
207145
}

0 commit comments

Comments
 (0)