-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIManager.cs
168 lines (148 loc) · 4.57 KB
/
UIManager.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
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.UI;
using UnityEngine;
public class UIManager : MonoBehaviour
{
public GameObject PauseMenu;
public GameObject GameUI;
public GameObject RaceFinishedUI;
public GameObject SettingsUI;
public GameObject PreStartUI;
public GameObject Compass;
private GameManagerSingleton GM;
private RaceManagerSingleton RM;
public Vehicle Player;
public Button pauseButton;
public Button returnButtenMenu;
public Button returnButton;
Resolution[] resolutions;
public Dropdown resolutionDropdown;
//---------------------------------------
// Use this for initialization
void Start()
{
GM = GameManagerSingleton.Singleton;
RM = RaceManagerSingleton.Singleton;
PauseMenu.SetActive(false);
RaceFinishedUI.SetActive(false);
GameUI.SetActive(false);
SettingsUI.SetActive(false);
Compass.SetActive(true);
PreStartUI.SetActive(true);
// create list of available resolutions:
resolutions = Screen.resolutions;
resolutionDropdown.ClearOptions();
List<string> options = new List<string>();
int currentResolutionIndex = 0;
for (int i = 0; i < resolutions.Length; i++)
{
string option = resolutions[i].width + "x" + resolutions[i].height;
options.Add(option);
if (resolutions[i].width == Screen.currentResolution.width && resolutions[i].height == Screen.currentResolution.height)
currentResolutionIndex = i;
}
resolutionDropdown.AddOptions(options);
resolutionDropdown.value = currentResolutionIndex;
resolutionDropdown.RefreshShownValue();
}
//---------------------------------------
// Update is called once per frame
void Update()
{
if (!GM.isPaused)
{
updateRacingUI();
}
// that's not efficient, but ...
if (RM.raceStarted)
{
GameUI.SetActive(true);
PreStartUI.SetActive(false);
}
if (RM.raceFinished)
{
setRaceFinishedUI();
}
}
//---------------------------------------
public void pauseGame(bool paused)
{
if (paused)
{
PauseMenu.SetActive(true);
GameUI.SetActive(false);
Compass.SetActive(false);
GetComponent<MenuManager>().initializeButton(pauseButton);
}
else
{
PauseMenu.SetActive(false);
if (!RM.raceFinished)
{
GameUI.SetActive(true);
Compass.SetActive(true);
SettingsUI.SetActive(false);
}
}
}
//---------------------------------------
public void openMenu()
{
Debug.Log("opening menu");
// disable pause, enable menu,
}
//---------------------------------------
public void closeMenu()
{
// go back to pause menu!
}
public void setVolume(float vol)
{
Debug.Log("vol: " + vol);
// implement fmod master fader thingy!
}
//---------------------------------------
public void setQuality(int qualityIndex)
{
QualitySettings.SetQualityLevel(qualityIndex);
}
//---------------------------------------
public void setFullScreen(bool isFullScreen)
{
Screen.fullScreen = isFullScreen;
}
//---------------------------------------
public void setResolution(int index)
{
Screen.SetResolution(resolutions[index].width, resolutions[index].height, Screen.fullScreen);
}
//---------------------------------------
public void raceFinished()
{
GameUI.SetActive(false);
RaceFinishedUI.SetActive(true);
// setRaceFinishedUI();
Debug.Log("RaceFinishedUI loaded");
Compass.SetActive(false);
}
private void updateRacingUI()
{
GameUI.GetComponent<GameUI>().UpdateUI();
}
private void setRaceFinishedUI()
{
Player[] HighScore = RM.getHighScore();
string text = "";
for (int i = 0; i < HighScore.Length; i++)
{
if (HighScore[i].GetComponent<CurrentPositionManager>().finishTime > 0)
text += HighScore[i].name + ": " + HighScore[i].GetComponent<CurrentPositionManager>().finishTime + " secs\n";
else
text += " ...\n";
}
RaceFinishedUI.GetComponentInChildren<Text>().text = text;
returnButton.Select();
}
}