SHADE_Y3/Assets/Scripts/UI/SC_PauseMenu.cs

109 lines
2.4 KiB
C#
Raw Normal View History

2023-03-03 16:46:54 +08:00
using System;
2023-03-02 16:26:49 +08:00
using SHADE;
using SHADE_Scripting.Audio;
public class PauseMenu : Script
{
public GameObject resumeBtn;
public GameObject retryBtn;
public GameObject quitBtn;
2023-03-03 16:46:54 +08:00
private TextRenderable gamePauseText;
2023-03-02 16:26:49 +08:00
public GameObject canvas;
protected override void awake()
{
if (GameManager.Instance != null)
GameManager.Instance.GamePause = false;
2023-03-03 16:46:54 +08:00
2023-03-02 16:26:49 +08:00
if (canvas)
2023-03-03 16:46:54 +08:00
{
gamePauseText = canvas.GetComponentInChildren<TextRenderable>();
2023-03-02 16:26:49 +08:00
canvas.SetActive(false);
2023-03-03 16:46:54 +08:00
}
2023-03-02 16:26:49 +08:00
if (!resumeBtn)
Debug.LogError("Resume Btn missing");
if (!retryBtn)
Debug.LogError("Retry Btn missing");
if (!quitBtn)
Debug.LogError("Quit Btn missing");
}
protected override void start()
{
//resume
UIElement resume = resumeBtn.GetComponent<UIElement>();
if (resume != null)
{
resume.OnClick.RegisterAction(() =>
{
if (GameManager.Instance.GamePause)
{
GameManager.Instance.GamePause = false;
Input.SetMouseCentering(true);
Application.IsCursorVisible = false;
2023-03-02 16:26:49 +08:00
AudioHandler.PauseAllSounds(false);
if (gamePauseText)
2023-03-03 16:46:54 +08:00
gamePauseText.Enabled = false;
2023-03-02 16:26:49 +08:00
if (canvas)
canvas.SetActive(false);
}
});
}
else
{
Debug.LogError("Failed to register resume button.");
}
//retry
UIElement retry = retryBtn.GetComponent<UIElement>();
if (retry != null)
{
retry.OnClick.RegisterAction(() =>
{
Audio.StopAllSounds();
SceneManager.RestartScene();
});
}
else
{
Debug.LogError("Failed to register retry button.");
}
UIElement quit = quitBtn.GetComponent<UIElement>();
if (quit != null)
{
quit.OnClick.RegisterAction(() =>
{
Audio.StopAllSounds();
//go to main menu
SceneManager.ChangeScene(97158628);
});
}
else
{
Debug.LogError("Failed to register quit button.");
}
}
protected override void update()
{
2023-03-03 16:46:54 +08:00
if (Input.GetKeyDown(Input.KeyCode.Escape) && !GameManager.Instance.GamePause && GameManager.Instance.stealFoodPopUpDone)
2023-03-02 16:26:49 +08:00
{
GameManager.Instance.GamePause = true;
Input.SetMouseCentering(false);
Application.IsCursorVisible = true;
2023-03-02 16:26:49 +08:00
AudioHandler.PauseAllSounds(true);
if (gamePauseText)
2023-03-03 16:46:54 +08:00
gamePauseText.Enabled = true;
2023-03-02 16:26:49 +08:00
if (canvas)
canvas.SetActive(true);
}
}
}