Implement pause functionality with UI and input bindings

This commit is contained in:
2025-12-13 16:13:22 +01:00
parent 4ae41b3ce9
commit c1d0af9a39
7 changed files with 354 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ namespace Infrastructure.Unity
[SerializeField] private TMP_Text scoreText;
[SerializeField] private TMP_Text highScoreText;
[SerializeField] private GameObject gameOverUi;
[SerializeField] private GameObject pauseUi;
[SerializeField] private GameObject startScreenUi;
[Header("Settings")]
@@ -46,6 +47,7 @@ namespace Infrastructure.Unity
private int _currentPlayerFloorIndex;
private int _currentDisplayedScore;
private float _inputBlockTimer;
private bool _isPaused;
private void OnEnable()
{
@@ -105,6 +107,13 @@ namespace Infrastructure.Unity
_inputBlockTimer -= Time.deltaTime;
return;
}
if (_actions.Player.Pause.triggered && _isGameRunning)
{
TogglePause();
}
if (_isPaused) return;
if (!_isGameRunning)
{
@@ -149,6 +158,26 @@ namespace Infrastructure.Unity
}
}
private void TogglePause()
{
_isPaused = !_isPaused;
if (_isPaused)
{
Time.timeScale = 0f;
if (soundManager) soundManager.SetPaused(true);
if (pauseUi) pauseUi.SetActive(true);
if (rumbleManager) rumbleManager.SetPaused(true);
}
else
{
Time.timeScale = 1f;
if (soundManager) soundManager.SetPaused(false);
if (pauseUi) pauseUi.SetActive(false);
if (rumbleManager) rumbleManager.SetPaused(false);
}
}
private void SpawnVisualOrb(string tileId)
{
if (_currentOrbInstance) Destroy(_currentOrbInstance);

View File

@@ -33,5 +33,16 @@ namespace Infrastructure.Unity
if (Gamepad.current != null)
Gamepad.current.SetMotorSpeeds(0f, 0f);
}
public void SetPaused(bool isPaused)
{
if (Gamepad.current != null)
{
if (isPaused)
Gamepad.current.PauseHaptics();
else
Gamepad.current.ResumeHaptics();
}
}
}
}

View File

@@ -66,5 +66,19 @@ namespace Infrastructure.Unity
sfxSource.PlayOneShot(clip);
}
public void SetPaused(bool isPaused)
{
if (isPaused)
{
musicSource.Pause();
}
else
{
musicSource.UnPause();
}
AudioListener.pause = isPaused;
}
}
}