Skip to content

Commit

Permalink
Prevent screen from sleeping while in game
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Jun 26, 2024
1 parent 296faf2 commit fe97f00
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Assets/Script/Gameplay/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public partial class GameManager : MonoBehaviour
private bool _isShowDebugText;
private bool _isReplaySaved;

private int _originalSleepTimeout;

private StemMixer _mixer;

private void Awake()
Expand Down Expand Up @@ -156,6 +158,10 @@ private void Awake()

// Hide vocals track (will be shown when players are initialized
VocalTrack.gameObject.SetActive(false);

// Prevent screen from sleeping
_originalSleepTimeout = Screen.sleepTimeout;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
}

private void OnDestroy()
Expand All @@ -180,6 +186,9 @@ private void OnDestroy()

// Reset the time scale back, as it would be 0 at this point (because of pausing)
Time.timeScale = 1f;

// Reset sleep timeout setting
Screen.sleepTimeout = _originalSleepTimeout;
}

private void Update()
Expand Down Expand Up @@ -362,6 +371,9 @@ public void Pause(bool showMenu = true)
Time.timeScale = 0f;
BackgroundManager.SetPaused(true);
GameStateFetcher.SetPaused(true);

// Allow sleeping
Screen.sleepTimeout = _originalSleepTimeout;
}

public void Resume(bool inputCompensation = true)
Expand All @@ -379,6 +391,9 @@ public void Resume(bool inputCompensation = true)
BackgroundManager.SetPaused(false);
GameStateFetcher.SetPaused(false);

// Disallow sleeping
Screen.sleepTimeout = SleepTimeout.NeverSleep;

_isReplaySaved = false;

_debugText.gameObject.SetActive(_isShowDebugText);
Expand Down

0 comments on commit fe97f00

Please sign in to comment.