Skip to content

Commit 02d1567

Browse files
committed
Refactor DemoCameraWork
1 parent 93b66c5 commit 02d1567

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

Assets/Demo/DemoCameraWork.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,39 @@
44

55
public class DemoCameraWork : MonoBehaviour, ITimeControl
66
{
7-
[SerializeField] private Transform target;
7+
[SerializeField]
8+
Transform target;
9+
10+
const float c1 = 3f;
11+
const float c2 = 5f;
12+
const float c3 = 6f;
13+
const float c4 = 13f;
814

915
public void SetTime(double time)
1016
{
11-
float t = (float) time;
17+
var t = (float) time;
1218

13-
if (t < 3f)
19+
if (t < c1)
1420
{
15-
float rate = t / 3f;
21+
float rate = t / c1;
1622
transform.position = target.position + new Vector3(0f, 0f, Mathf.Lerp(2f, 1f, rate * rate));
1723
transform.LookAt(target);
1824
}
19-
else if (t < 5f)
25+
else if (t < c2)
2026
{
21-
float rate = (t - 3f) / (5f - 3f);
27+
float rate = (t - c1) / (c2 - c1);
2228
transform.position = target.position + new Vector3(Mathf.Sin(rate * rate), 0f, Mathf.Cos(rate * rate));
2329
transform.LookAt(target);
2430
}
25-
else if (t < 6f)
31+
else if (t < c3)
2632
{
2733
transform.position = new Vector3(1f, 2f, 10f);
2834
transform.LookAt(target);
2935
}
30-
else
36+
else if (t < c4)
3137
{
32-
float rate = (t - 6f) / (13f - 6f);
33-
transform.position = new Vector3(0f, Mathf.Lerp(2f, 20f, rate * rate * rate), 11f);
38+
float rate = (t - c3) / (c4 - c3);
39+
transform.position = new Vector3(0f, Mathf.Lerp(2f, 25f, rate * rate), 11f);
3440
transform.LookAt(new Vector3(0f, 1f, 11f + rate * 23f));
3541
}
3642
}

0 commit comments

Comments
 (0)