- using MyCollections.Managers;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Xml.Serialization;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class PauseMenu : MonoBehaviour
- {
- private GameStateManager gameStateManager;
- [SerializeField] private GameObject[] buttonsGroup;
- [SerializeField] private GameObject settingsPanel;
- [SerializeField] private HUDManager hudManager;
- private PauseMenuState currentState;
- public void Exit()
- {
- SceneManager.LoadScene("MainMenu");
- }
- //Resumes the game
- private void Resume()
- {
- gameStateManager.ResumeGame();
- gameObject.SetActive(false);
- }
- //Open Settings Menu
- private void OpenSettings()
- {
- settingsPanel.SetActive(true);
- }
- private void OnEnable()
- {
- gameObject.SetActive(true);
- gameStateManager = GameStateManager.Instance;
- SetState(PauseMenuState.None);
- }
- private void OnDisable()
- {
- hudManager.SetHUDMode(HUDMode.None);
- }
- public void ToggleSettings()
- {
- if (currentState != PauseMenuState.Settings)
- {
- SetState(PauseMenuState.Settings);
- }
- else
- {
- SetState(PauseMenuState.None);
- }
- }
- private void SetState(PauseMenuState state)
- {
- ClearMenuHUD();
- switch (state)
- {
- case PauseMenuState.None:
- OpenMenuOptions();
- break;
- case PauseMenuState.Settings:
- OpenSettings();
- break;
- }
- currentState = state;
- }
- private void OpenMenuOptions()
- {
- for (int i = 0; i < buttonsGroup.Length; i++)
- {
- buttonsGroup[i].gameObject.SetActive(true);
- }
- }
- private void ClearMenuHUD()
- {
- for (int i = 0; i < buttonsGroup.Length; i++)
- {
- buttonsGroup[i].gameObject.SetActive(false);
- }
- settingsPanel.SetActive(false);
- }
- [Serializable]
- public enum PauseMenuState
- {
- None,
- Settings
- }
- }