-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPauseMenu.js
240 lines (189 loc) · 5.54 KB
/
PauseMenu.js
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
234
235
236
237
238
239
240
#pragma strict
var custompause : GUIStyle;
var custompausebg : GUIStyle;
var custompausebtn: GUIStyle;
var skin:GUISkin;
private var gldepth = -0.5;
private var startTime = 0.1;
var mat:Material;
private var tris = 0;
private var verts = 0;
private var savedTimeScale:float;
private var pauseFilter;
var lowFPSColor = Color.red;
var highFPSColor = Color.green;
var lowFPS = 30;
var highFPS = 50;
var start:GameObject;
var url = "unity.html";
var statColor:Color = Color.yellow;
var credits:String[]=[
"A Fugu Games Production",
"Programming by Phil Chu",
"Fugu logo by Shane Nakamura Designs",
"Copyright (c) 2007-2008 Technicat, LLC"] ;
var crediticons:Texture[];
enum Page {
None,Main,Options,Credits
}
private var currentPage:Page;
private var fpsarray:int[];
private var fps:float;
function Start() {
fpsarray = new int[Screen.width];
Time.timeScale = 1.0;
pauseFilter = Camera.main.GetComponent(SepiaToneEffect);
// PauseGame();
}
function ScrollFPS() {
for (var x=1; x<fpsarray.length; ++x) {
fpsarray[x-1]=fpsarray[x];
}
if (fps < 1000) {
fpsarray[fpsarray.length-1]=fps;
}
}
static function IsDashboard() {
return Application.platform == RuntimePlatform.OSXDashboardPlayer;
}
static function IsBrowser() {
return (Application.platform == RuntimePlatform.WindowsWebPlayer ||
Application.platform == RuntimePlatform.OSXWebPlayer);
}
//tap screen to pause
//function LateUpdate () {
// for (var touch : Touch in Input.touches) {
// if (touch.phase == TouchPhase.Began && !IsGamePaused())
// PauseGame();
// }
// }
var native_width : float = 960;
var native_height : float = 640;
function OnGUI () {
var rx : float = Screen.width / native_width;
var ry : float = Screen.height / native_height;
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));
if (skin != null) {
GUI.skin = skin;
}
if (IsGamePaused()) {
GUI.color = statColor;
switch (currentPage) {
case Page.Main: PauseMenu(); break;
case Page.Credits: ShowCredits(); break;
}
}
if (!IsGamePaused()) {if (GUI.Button(Rect(60,560,120,120)," ", custompausebtn)) {
PauseGame();
}}
}
function ShowCredits() {
BeginPage(300,300);
for (var credit in credits) {
GUILayout.Label(credit);
}
for (var credit in crediticons) {
GUILayout.Label(credit);
}
EndPage();
}
//function ShowBackButton() {
// if (GUI.Button(Rect(20,Screen.height-50,50,20),"Back")) {
// currentPage = Page.Main;
// }
//}
function ShowDevice() {
GUILayout.Label ("Unity player version "+Application.unityVersion);
GUILayout.Label("Graphics: "+SystemInfo.graphicsDeviceName+" "+
SystemInfo.graphicsMemorySize+"MB\n"+
SystemInfo.graphicsDeviceVersion+"\n"+
SystemInfo.graphicsDeviceVendor);
GUILayout.Label("Shadows: "+SystemInfo.supportsShadows);
GUILayout.Label("Image Effects: "+SystemInfo.supportsImageEffects);
GUILayout.Label("Render Textures: "+SystemInfo.supportsRenderTextures);
}
function Qualities() {
GUILayout.Label(QualitySettings.names[QualitySettings.GetQualityLevel()]);
}
function QualityControl() {
GUILayout.BeginHorizontal();
if (GUILayout.Button("Decrease")) {
QualitySettings.DecreaseLevel();
}
if (GUILayout.Button("Increase")) {
QualitySettings.IncreaseLevel();
}
GUILayout.EndHorizontal();
}
function BeginPage(width : int, height : int ) {
GUILayout.BeginArea(Rect((Screen.width - width)/2,(Screen.height - height)/2,width,height));
}
function EndPage() {
GUILayout.EndArea();
if (currentPage != Page.Main) {
// ShowBackButton();
}
}
function IsBeginning() {
return Time.time < startTime;
}
function PauseMenu() {
// BeginPage(200,200);
// if (GUILayout.Button (IsBeginning() ? "Play" : "Continue")) {
// UnPauseGame();
// }
// if (GUILayout.Button ("Options")) {
// currentPage = Page.Options;
// }
// if (GUILayout.Button ("Credits")) {
// currentPage = Page.Credits;
// }
// if (IsBrowser() && !IsBeginning() && GUILayout.Button ("Restart")) {
// Application.OpenURL(url);
// }
GUILayout.BeginArea (Rect (0,0,960,640), custompausebg);
// if (GUI.Button (Rect (330,340,300,120), "Continue", custompause)) {
// UnPauseGame();
// }
// if (GUI.Button (Rect (330,200,300,120), "Home", custompause)) {
// Application.LoadLevel (0);
// }
// if (GUI.Button(Rect(60,560,120,120),"Resume",custompausebtn)) {
// UnPauseGame();
// }
if (GUI.Button (Rect (60,20,900,300), " ", custompause)) {
Application.LoadLevel (0);
}
if (GUI.Button (Rect (60,340,900,300), " ", custompause)) {
UnPauseGame();
}
if (GUI.Button(Rect(60,560,120,120)," ",custompausebtn)) {
UnPauseGame();
}
GUILayout.EndArea ();
// EndPage();
}
function PauseGame() {
// Camera.main.SendMessage("fadeOutHalf");
// yield WaitForSeconds(1);
savedTimeScale = Time.timeScale;
Time.timeScale = 0;
AudioListener.pause = true;
currentPage = Page.Main;
}
function UnPauseGame() {
Time.timeScale = savedTimeScale;
AudioListener.pause = false;
if (IsBeginning() && start != null) {
start.active = true;
yield WaitForSeconds(1);
}
}
function IsGamePaused() {
return Time.timeScale==0;
}
function OnApplicationPause(pause:boolean) {
if (IsGamePaused()) {
AudioListener.pause = true;
}
}