2023-02-21 00:47:20 +08:00
|
|
|
|
using System;
|
|
|
|
|
using SHADE;
|
|
|
|
|
using SHADE_Scripting.Audio;
|
|
|
|
|
|
|
|
|
|
public class PauseMenu : Script
|
|
|
|
|
{
|
|
|
|
|
public GameObject resumeBtn;
|
|
|
|
|
public GameObject retryBtn;
|
|
|
|
|
public GameObject quitBtn;
|
|
|
|
|
|
2023-03-01 18:05:42 +08:00
|
|
|
|
private TextRenderable gamePauseText;
|
2023-02-21 00:47:20 +08:00
|
|
|
|
public GameObject canvas;
|
|
|
|
|
|
|
|
|
|
protected override void awake()
|
|
|
|
|
{
|
|
|
|
|
GameManager.Instance.GamePause = false;
|
2023-03-01 18:05:42 +08:00
|
|
|
|
|
2023-02-21 00:47:20 +08:00
|
|
|
|
if (canvas)
|
2023-03-01 18:05:42 +08:00
|
|
|
|
{
|
|
|
|
|
gamePauseText = canvas.GetComponentInChildren<TextRenderable>();
|
2023-02-21 00:47:20 +08:00
|
|
|
|
canvas.SetActive(false);
|
2023-03-01 18:05:42 +08:00
|
|
|
|
}
|
2023-02-21 00:47:20 +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;
|
2023-03-01 23:56:40 +08:00
|
|
|
|
Input.SetMouseCentering(true);
|
|
|
|
|
Application.IsCursorVisible = false;
|
2023-03-01 17:36:02 +08:00
|
|
|
|
AudioHandler.PauseAllSounds(false);
|
2023-02-21 00:47:20 +08:00
|
|
|
|
if (gamePauseText)
|
2023-03-01 18:05:42 +08:00
|
|
|
|
gamePauseText.Enabled = false;
|
2023-02-21 00:47:20 +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();
|
2023-02-21 19:31:50 +08:00
|
|
|
|
SceneManager.RestartScene();
|
2023-02-21 00:47:20 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
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-02 17:33:02 +08:00
|
|
|
|
if (Input.GetKeyDown(Input.KeyCode.Escape) && !GameManager.Instance.GamePause && GameManager.Instance.stealFoodPopUpDone)
|
2023-02-21 00:47:20 +08:00
|
|
|
|
{
|
|
|
|
|
GameManager.Instance.GamePause = true;
|
2023-03-01 23:56:40 +08:00
|
|
|
|
Input.SetMouseCentering(false);
|
|
|
|
|
Application.IsCursorVisible = true;
|
2023-03-01 17:36:02 +08:00
|
|
|
|
AudioHandler.PauseAllSounds(true);
|
2023-02-21 00:47:20 +08:00
|
|
|
|
if (gamePauseText)
|
2023-03-01 18:05:42 +08:00
|
|
|
|
gamePauseText.Enabled = true;
|
2023-02-21 00:47:20 +08:00
|
|
|
|
if (canvas)
|
|
|
|
|
canvas.SetActive(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|