SHADE_Y3/Assets/Scripts/UI/SC_PauseMenu.cs

114 lines
2.7 KiB
C#

using System;
using SHADE;
using SHADE_Scripting.Audio;
public class PauseMenu : Script
{
public GameObject resumeBtn;
public GameObject retryBtn;
public GameObject quitBtn;
private TextRenderable gamePauseText;
public GameObject canvas;
protected override void awake()
{
if (GameManager.Instance != null)
GameManager.Instance.GamePause = false;
if (canvas)
{
gamePauseText = canvas.GetComponentInChildren<TextRenderable>();
canvas.SetActive(false);
}
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.OnRelease.RegisterAction(() =>
{
if (GameManager.Instance.GamePause)
{
GameManager.Instance.GamePause = false;
Input.SetMouseCentering(true);
Application.IsCursorVisible = false;
AudioHandler.PauseAllSounds(false);
if (gamePauseText)
gamePauseText.Enabled = false;
if (canvas)
canvas.SetActive(false);
Application.FixDeltaTime = Time.DefaultFixDeltaTime;
}
});
}
else
{
Debug.LogError("Failed to register resume button.");
}
//retry
UIElement retry = retryBtn.GetComponent<UIElement>();
if (retry != null)
{
retry.OnRelease.RegisterAction(() =>
{
Audio.StopAllSounds();
SceneManager.RestartScene();
GameManager.Instance.GamePause = false;
GameManager.Instance.stealFoodPopUpDone = false;
GameManager.Instance.PreviewLevelDone = false;
});
}
else
{
Debug.LogError("Failed to register retry button.");
}
UIElement quit = quitBtn.GetComponent<UIElement>();
if (quit != null)
{
quit.OnRelease.RegisterAction(() =>
{
Audio.StopAllSounds();
//go to main menu
SceneManager.ChangeScene(97158628);
});
}
else
{
Debug.LogError("Failed to register quit button.");
}
}
protected override void update()
{
if (Input.GetKeyUp(Input.KeyCode.Escape) && !GameManager.Instance.GamePause && GameManager.Instance.stealFoodPopUpDone)
{
GameManager.Instance.GamePause = true;
Input.SetMouseCentering(false);
Application.IsCursorVisible = true;
AudioHandler.PauseAllSounds(true);
if (gamePauseText)
gamePauseText.Enabled = true;
if (canvas)
canvas.SetActive(true);
Application.FixDeltaTime = 0;
}
}
}