PauseMenu.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. namespace HQFPSWeapons.UserInterface
  3. {
  4. public class PauseMenu : UserInterfaceBehaviour
  5. {
  6. [SerializeField]
  7. private Panel m_Panel = null;
  8. [SerializeField]
  9. private Panel m_MapSelectionPanel = null;
  10. [SerializeField]
  11. private bool m_UseKeyToPause = true;
  12. [SerializeField]
  13. [ShowIf("m_UseKeyToPause", true)]
  14. private KeyCode m_PauseKey = KeyCode.Escape;
  15. public void Pause()
  16. {
  17. Player.Pause.ForceStart();
  18. //Time.timeScale = 1f;
  19. m_Panel.TryShow(true);
  20. Cursor.lockState = CursorLockMode.None;
  21. Cursor.visible = true;
  22. }
  23. public void LoadScene(int index)
  24. {
  25. Resume();
  26. GameManager.Instance.StartGame(index);
  27. }
  28. public void Resume()
  29. {
  30. Player.Pause.ForceStop();
  31. // Time.timeScale = 1f;
  32. m_Panel.TryShow(false);
  33. Cursor.lockState = CursorLockMode.Locked;
  34. Cursor.visible = false;
  35. m_MapSelectionPanel.TryShow(false);
  36. }
  37. public void ToggleMapSelection()
  38. {
  39. m_MapSelectionPanel.TryShow(!m_MapSelectionPanel.IsVisible);
  40. }
  41. public void Quit()
  42. {
  43. GameManager.Instance.Quit();
  44. }
  45. private void Update()
  46. {
  47. if(m_UseKeyToPause && Input.GetKeyDown(m_PauseKey))
  48. {
  49. if (!Player.Pause.Active)
  50. {
  51. Pause();
  52. }
  53. else
  54. Resume();
  55. }
  56. }
  57. }
  58. }