Assets/Scripts/Menu/MenuManager.cs (view raw)
1using UnityEngine;
2using UnityEngine.Audio;
3using UnityEngine.SceneManagement;
4using UnityEngine.UI;
5
6public class MenuManager : MonoBehaviour
7{
8 public GameObject loadPanel;
9 public GameObject creditsPanel;
10 public GameObject settingsPanel;
11 public AudioMixer mixer;
12
13 private SettingsManager sm;
14 enum Panel
15 {
16 None = -1,
17 Load = 0,
18 Credits = 1,
19 Settings = 2
20 }
21 Panel currentPanel = Panel.None;
22
23 private void Start() //remember this is shared between gameover and main menu
24 {
25 //set music menu
26 mixer.SetFloat("MusicVolume", Mathf.Log10(PlayerPrefs.GetFloat("MusicVolume", 0.75f)) * 20);
27 mixer.SetFloat("SfxVolume", Mathf.Log10(PlayerPrefs.GetFloat("SfxVolume", 0.75f)) * 20);
28
29 GameMaster.Instance.resetGame();
30 if (settingsPanel)
31 {
32 sm = settingsPanel.GetComponent<SettingsManager>();
33 settingsPanel.SetActive(false); //TODO: start with settings panel open or set mixer volume in another way
34 }
35 }
36
37 #region Menu buttons
38 public void NewGame()
39 {
40 SceneManager.LoadScene("Level0");
41 }
42
43 public void LoadGame()
44 {
45 if(currentPanel == Panel.Load)
46 {
47 hideAllPanels();
48 currentPanel = Panel.None;
49 } else
50 {
51 currentPanel = Panel.Load;
52 Button btn;
53 //Fill load slots
54 for (int i = 0; i < loadPanel.transform.childCount; i++)
55 {
56 btn = loadPanel.transform.GetChild(i).GetComponent<Button>();
57 UI.setSLButtonText(btn, i, true);
58 }
59 loadPanel.SetActive(true);
60 }
61 }
62
63 public void Credits()
64 {
65 if (currentPanel == Panel.Credits)
66 {
67 hideAllPanels();
68 currentPanel = Panel.None;
69 }
70 else
71 {
72 currentPanel = Panel.Credits;
73 creditsPanel.SetActive(true);
74 }
75 }
76
77 public void Settings()
78 {
79 if (currentPanel == Panel.Settings)
80 {
81 hideAllPanels();
82 currentPanel = Panel.None;
83 }
84 else
85 {
86 currentPanel = Panel.Settings;
87 settingsPanel.SetActive(true);
88 }
89 }
90
91 public void Quit()
92 {
93 Application.Quit();
94 }
95 #endregion
96
97 #region GameOver Button
98 public void BackToMainMenu()
99 {
100 SceneManager.LoadScene("Menu");
101 }
102 #endregion
103
104 private void hideAllPanels()
105 {
106 loadPanel.SetActive(false);
107 creditsPanel.SetActive(false);
108 settingsPanel.SetActive(false);
109 }
110}