-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPauseGame.cs
203 lines (194 loc) · 6.14 KB
/
PauseGame.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.EventSystems;
//I don't even know what's going on in here anymore, there's so, so much shit on this page.
public class PauseGame : MonoBehaviour
{
public bool IsPaused = false; //is the game paused?
public bool IsOptions = false; //is the options menu opened?
public AudioSource Audible; //music source
public GameObject BGcamera; //background camera
public GameObject BGimage; //image that is substituted for the background camera. Should I disable the background objects as well? maybe...
public GameObject PauseMenu; //Pause menu GUI
public GameObject OptionsMenu; //Options menu GUI
[HideInInspector]
public CanvasGroup PauseAlpha; //Changing the .alpha changes the pause menu alpha
[HideInInspector]
public GameObject Player; //Guess what this is?
public float CtimeScale = 1; //Current timescale, converted tickrate.
[HideInInspector]
public AudioListener Audacity;
[HideInInspector]
public int TextureQuality = 0; //overall game quality
[HideInInspector]
public float MusicVol = 1;
[HideInInspector]
public float MasterVol = 1;
[HideInInspector]
public float Tickrate = 60;
[HideInInspector]
public bool PrettyBackgrounds = false;
public Slider TexSlid;
public Slider TickSlid;
public Slider MusSlid;
public Slider MasSlid;
public Toggle BGTog;
void Start ()
{
Player = GameObject.FindGameObjectWithTag("Player");
PauseAlpha = GetComponentInChildren<CanvasGroup>();
PauseMenu.SetActive(false);
OptionsMenu.SetActive(false);
if (PlayerPrefs.GetInt("FirstPlay",0) != 1)
{
int QualityLvl = QualitySettings.GetQualityLevel();
TextureQuality = QualityLvl;
Tickrate = 250 * (QualityLvl + 1);
MusicVol = 50;
MasterVol = 50;
if (QualityLvl > 1)
{
PrettyBackgrounds = true;
PlayerPrefs.SetInt("PrettyBackgrounds", 1);
}
PlayerPrefs.SetFloat("Tickrate", Tickrate);
PlayerPrefs.SetInt("TextureQuality", QualityLvl);
PlayerPrefs.SetFloat("MusicVol", MusicVol);
PlayerPrefs.SetFloat("MasterVol", MasterVol);
PlayerPrefs.SetInt("FirstPlay", 1);
}
else
{
Tickrate = PlayerPrefs.GetFloat("Tickrate",60);
TextureQuality = PlayerPrefs.GetInt("TextureQuality",1);
MusicVol = PlayerPrefs.GetFloat("MusicVol",50);
MasterVol = PlayerPrefs.GetFloat("MasterVol",50);
int PBG = PlayerPrefs.GetInt("PrettyBackgrounds", 0);
if (PBG == 1)
PrettyBackgrounds = true;
else
PrettyBackgrounds = false;
}
}
public void AdjustTQ(float TQ)
{
TextureQuality = (int)TQ;
}
public void AdjustMusV(float MV)
{
MusicVol = MV;
}
public void AdjustMasV(float TQ)
{
MusicVol = TQ;
}
public void AdjustPB(bool PB)
{
PrettyBackgrounds = PB;
}
public void AdjustTick(float tick)
{
Tickrate = tick;
}
void Update ()
{
if (PauseMenu.activeSelf && PauseAlpha.alpha < 1)
{
PauseAlpha.alpha += 0.1f;
}
if (Input.GetButtonDown("Pause"))
{
if (IsPaused)
Continue();
else
OpenPause();
}
if (Input.GetButtonDown("Slow Time") && CtimeScale == 1)
{
CtimeScale = 0.2f;
}
else if (Input.GetButtonUp("Slow Time") && CtimeScale == 0.2f)
{
CtimeScale = 1f;
}
}
public void OpenPause()
{
//open Pause Menu
PauseMenu.SetActive(true);
IsPaused = true;
if (Player != null)
Player.SetActive(false);
}
public void Continue()
{
//close Pause Menu
PauseMenu.SetActive(false);
IsPaused = false;
PauseAlpha.alpha = 0;
if (Player != null)
Player.SetActive(true);
}
public void Restart()
{
IsPaused = false;
Time.timeScale = 1;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
Player.SetActive(true);
}
public void Map()
{
IsPaused = false;
Time.timeScale = 1;
SceneManager.LoadScene("Level select");
Player.SetActive(true);
}
public void OpenOptions()
{
//Opens Options Menu
IsOptions = true;
PauseMenu.SetActive(false);
OptionsMenu.SetActive(true);
TexSlid.value = TextureQuality;
TickSlid.value = Tickrate;
MusSlid.value = MusicVol;
MasSlid.value = MasterVol;
BGTog.isOn = PrettyBackgrounds;
}
public void CloseOptions()
{
IsOptions = false;
PauseMenu.SetActive(true);
OptionsMenu.SetActive(false);
}
public void Apply()
{
QualitySettings.SetQualityLevel(TextureQuality);
AudioListener.volume = MasterVol / 100;
Audible.volume = MusicVol / 100;
if (PrettyBackgrounds)
{
if (BGcamera != null)
BGcamera.SetActive(true);
BGimage.SetActive(false);
PlayerPrefs.SetInt("PrettyBackgrounds", 1);
}
else
{
if (BGcamera != null)
BGcamera.SetActive(false);
BGimage.SetActive(true);
PlayerPrefs.SetInt("PrettyBackgrounds", 0);
}
Time.fixedDeltaTime = 1/Tickrate;
Debug.Log(Tickrate);
CloseOptions();
PlayerPrefs.SetFloat("Tickrate", Tickrate);
PlayerPrefs.SetInt("TextureQuality", TextureQuality);
PlayerPrefs.SetFloat("MusicVol", MusicVol);
PlayerPrefs.SetFloat("MasterVol", MasterVol);
}
}