Last active
June 4, 2019 09:37
-
-
Save shane-harper/b198337cc67e063074045e7a4b44f166 to your computer and use it in GitHub Desktop.
An object for Unity mobile to keep the screen awake while doing something
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using UnityEngine; | |
public struct ScreenNeverSleepScope : IDisposable | |
{ | |
public ScreenNeverSleepScope(bool neverSleep) | |
{ | |
if (neverSleep) | |
Screen.sleepTimeout = SleepTimeout.NeverSleep; | |
} | |
public void Dispose() | |
{ | |
Screen.sleepTimeout = SleepTimeout.SystemSetting; | |
} | |
} | |
public class ExampleUse : MonoBehaviour | |
{ | |
private IEnumerator Start() | |
{ | |
using (new ScreenNeverSleepScope(true)) | |
{ | |
// Do some things | |
yield return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment