SHADE_Y3/Assets/Scripts/UI/SC_PauseMenu.cs

116 lines
2.8 KiB
C#
Raw Permalink Normal View History

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;
private TextRenderable gamePauseText;
2023-02-21 00:47:20 +08:00
public GameObject canvas;
protected override void awake()
{
2023-03-03 14:26:36 +08:00
if (GameManager.Instance != null)
GameManager.Instance.GamePause = false;
2023-02-21 00:47:20 +08:00
if (canvas)
{
gamePauseText = canvas.GetComponentInChildren<TextRenderable>();
2023-02-21 00:47:20 +08:00
canvas.SetActive(false);
}
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.OnRelease.RegisterAction(() =>
2023-02-21 00:47:20 +08:00
{
if (GameManager.Instance.GamePause)
{
GameManager.Instance.GamePause = false;
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)
gamePauseText.Enabled = false;
2023-02-21 00:47:20 +08:00
if (canvas)
canvas.SetActive(false);
2023-03-05 15:35:57 +08:00
Application.FixDeltaTime = Time.DefaultFixDeltaTime;
2023-03-10 16:26:52 +08:00
AnimationSystem.TimeScale = AnimationSystem.DefaultTimeScale;
2023-02-21 00:47:20 +08:00
}
});
}
else
{
Debug.LogError("Failed to register resume button.");
}
//retry
UIElement retry = retryBtn.GetComponent<UIElement>();
if (retry != null)
{
retry.OnRelease.RegisterAction(() =>
2023-02-21 00:47:20 +08:00
{
Audio.StopAllSounds();
2023-02-21 19:31:50 +08:00
SceneManager.RestartScene();
GameManager.Instance.GamePause = false;
GameManager.Instance.stealFoodPopUpDone = false;
GameManager.Instance.PreviewLevelDone = false;
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.OnRelease.RegisterAction(() =>
2023-02-21 00:47:20 +08:00
{
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)
2023-02-21 00:47:20 +08:00
{
GameManager.Instance.GamePause = true;
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)
gamePauseText.Enabled = true;
2023-02-21 00:47:20 +08:00
if (canvas)
canvas.SetActive(true);
2023-03-05 15:35:57 +08:00
Application.FixDeltaTime = 0;
2023-03-10 16:26:52 +08:00
AnimationSystem.TimeScale = 0;
2023-02-21 00:47:20 +08:00
}
}
}