diff --git a/UltraStar Play/Assets/Common/Audio/AudioManager.cs b/UltraStar Play/Assets/Common/Audio/AudioManager.cs index 3346699d2..2cc8d7aab 100644 --- a/UltraStar Play/Assets/Common/Audio/AudioManager.cs +++ b/UltraStar Play/Assets/Common/Audio/AudioManager.cs @@ -14,6 +14,8 @@ public class AudioManager : MonoBehaviour private static readonly int criticalCacheSize = 10; private static readonly Dictionary audioClipCache = new Dictionary(); + private static float volumeBeforeMute = -1; + public static AudioManager Instance { get @@ -22,6 +24,22 @@ public static AudioManager Instance } } + public static void ToggleMuteAudio() + { + if (volumeBeforeMute >= 0) + { + AudioListener.volume = volumeBeforeMute; + volumeBeforeMute = -1; + UiManager.Instance.CreateNotification("Unmute"); + } + else + { + volumeBeforeMute = AudioListener.volume; + AudioListener.volume = 0; + UiManager.Instance.CreateNotification("Mute"); + } + } + // When streamAudio is false, all audio data is loaded at once in a blocking way. public AudioClip GetAudioClip(string path, bool streamAudio = true) { diff --git a/UltraStar Play/Assets/Common/Input/GlobalKeyboardShortcutManager.cs b/UltraStar Play/Assets/Common/Input/GlobalKeyboardShortcutManager.cs index d5f8eefab..441c3478c 100644 --- a/UltraStar Play/Assets/Common/Input/GlobalKeyboardShortcutManager.cs +++ b/UltraStar Play/Assets/Common/Input/GlobalKeyboardShortcutManager.cs @@ -20,5 +20,11 @@ void Update() StartCoroutine(CoroutineUtils.ExecuteAfterDelayInSeconds(0.1f, () => SettingsManager.Instance.Settings.GraphicSettings.fullScreenMode = Screen.fullScreenMode)); } + + // Mute / unmute audio via F12 + if (Input.GetKeyUp(KeyCode.F12)) + { + AudioManager.ToggleMuteAudio(); + } } }