using UnityEngine;
namespace Akila.FPSFramework.UI
{
///
/// Represents a Pause Menu in the FPS Framework.
/// Handles pausing and unpausing the game and updating the UI accordingly.
///
[AddComponentMenu("Akila/FPS Framework/UI/Pause Menu")]
public class PauseMenu : Menu
{
///
/// Input controls for the pause menu.
///
private Controls _controls;
///
/// Indicates whether the game is currently paused.
///
public bool IsPaused => FPSFrameworkCore.IsPaused;
///
/// Initializes the Pause Menu.
///
protected override void Start()
{
base.Start();
// Initialize and enable input controls
_controls = new Controls();
_controls.Enable();
// Ensure the game starts unpaused
FPSFrameworkCore.IsPaused = false;
}
///
/// Updates the Pause Menu. Listens for pause/unpause input.
///
protected override void Update()
{
base.Update();
if (_controls.UI.Pause.triggered)
{
if (IsPaused)
Unpause();
else
Pause();
}
if(IsPaused == false) CloseMenu();
}
///
/// Pauses the game and opens the pause menu.
///
public void Pause()
{
// Update game state to paused
FPSFrameworkCore.IsPaused = true;
// Unlock the cursor and make it visible
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
// Open the pause menu UI
OpenMenu();
}
///
/// Unpauses the game and closes the pause menu.
///
public void Unpause()
{
// Close the pause menu UI
if (IsOpen)
{
// Update game state to unpaused
FPSFrameworkCore.IsPaused = false;
// Lock the cursor and hide it
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
public void LoadScene(string sceneName)
{
LoadingScreen.LoadScene(sceneName);
}
}
}