-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameManagerSingleton.cs
More file actions
114 lines (102 loc) · 3.12 KB
/
Copy pathGameManagerSingleton.cs
File metadata and controls
114 lines (102 loc) · 3.12 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
using UnityEngine;
public class GameManagerSingleton : MonoBehaviour
{
public bool isPaused = false;
private UIManager UI;
[FMODUnity.EventRef]
public string audioMixerEvent;
FMOD.Studio.EventInstance audioMixer;
private static GameManagerSingleton singleton = null;
public static GameManagerSingleton Singleton
{
get { return singleton; }
}
//---------------------------------------
// Use this for initialization
void Awake()
{
if (singleton == null) singleton = this;
// DontDestroyOnLoad(this.gameObject);
UI = GetComponent<UIManager>();
Cursor.visible = false;
audioMixer = FMODUnity.RuntimeManager.CreateInstance(audioMixerEvent);
audioMixer.start();
audioMixer.setParameterValue("paused", 0);
audioMixer.setParameterValue("preRace", 1);
audioMixer.setParameterValue("raceFinished", 0);
}
//---------------------------------------
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown("Start_1"))
{
if (!isPaused) pauseGame();
else resumeGame();
}
if (GetComponent<RaceManagerSingleton>().raceStarted)
{
updatePreRaceCondition();
}
if (GetComponent<RaceManagerSingleton>().raceFinished)
{
updateRaceFinishedCondition();
}
}
//---------------------------------------
public void updatePreRaceCondition()
{
audioMixer.setParameterValue("preRace", 0);
}
//---------------------------------------
private void updateRaceFinishedCondition()
{
audioMixer.setParameterValue("raceFinished", 1);
}
//---------------------------------------
public void pauseGame()
{
if (isPaused) return;
isPaused = true;
UI.pauseGame(true);
audioMixer.setParameterValue("paused", 1);
Time.timeScale = 0;
Debug.Log("paused");
}
//---------------------------------------
public void resumeGame()
{
if (!isPaused) return;
isPaused = false;
UI.pauseGame(false);
audioMixer.setParameterValue("paused", 0);
Time.timeScale = 1;
}
//---------------------------------------
public void quitGame()
{
returnToMenu();
}
//---------------------------------------
public void returnToMenu()
{
print("returning to menu!");
if (MusicSingleton.Instance) MusicSingleton.Instance.EndRace();
audioMixer.setParameterValue("paused", 0);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);//SceneManager.GetActiveScene().buildIndex-1);
}
//---------------------------------------
public void raceFinished()
{
UI.raceFinished();
}
void OnDestroy()
{
audioMixer.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
audioMixer.release();
Debug.Log("mixer released");
}
}