blob: f038df5c99a8d078711982feb33c29901032690e (
plain)
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
|
using System.Collections;
using Photon.Pun;
using UnityEngine;
public class TimeHandler : MonoBehaviour
{
public AnimationCurve slowDown;
public AnimationCurve speedUp;
public float baseTimeScale = 0.85f;
public float gameOverTime = 1f;
public float gameStartTime;
public float timeStop = 1f;
public static float timeScale = 1f;
public static TimeHandler instance;
public static float deltaTime;
public static float fixedDeltaTime;
private void Awake()
{
instance = this;
}
private void Update()
{
float num = baseTimeScale;
if (gameOverTime < 1f)
{
num *= gameOverTime;
}
if (gameStartTime < 1f)
{
num *= gameStartTime;
}
if (timeStop < 1f)
{
num *= timeStop;
}
if (PhotonNetwork.OfflineMode && EscapeMenuHandler.isEscMenu)
{
num *= 0f;
}
timeScale = num;
deltaTime = Time.deltaTime * timeScale;
fixedDeltaTime = Time.fixedDeltaTime * timeScale;
Time.timeScale = 1f;
}
public void StartGame()
{
gameStartTime = 1f;
}
public void DoSpeedUp()
{
StartCoroutine(DoCurve(speedUp));
}
public void DoSlowDown()
{
StartCoroutine(DoCurve(slowDown));
}
private IEnumerator DoCurve(AnimationCurve curve)
{
float c = 0f;
float t = curve.keys[curve.keys.Length - 1].time;
while (c < t)
{
gameOverTime = curve.Evaluate(c);
c += Time.unscaledDeltaTime;
yield return null;
}
gameOverTime = curve.Evaluate(t);
}
public void HitStop()
{
StartCoroutine(DoHitStop());
}
private IEnumerator DoHitStop()
{
timeStop = 0f;
yield return new WaitForSeconds(0.3f);
timeStop = 1f;
}
}
|