Skip to content

Commit

Permalink
Merge pull request #165 from UltraStar-Deluxe/anst/shortcut-to-mute-a…
Browse files Browse the repository at this point in the history
…udio

mute / unmute audio via F12 (global keyboard shortcut)
  • Loading branch information
basisbit committed Apr 14, 2020
2 parents b3fe8fa + fcf111a commit 26a3178
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions UltraStar Play/Assets/Common/Audio/AudioManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class AudioManager : MonoBehaviour
private static readonly int criticalCacheSize = 10;
private static readonly Dictionary<string, CachedAudioClip> audioClipCache = new Dictionary<string, CachedAudioClip>();

private static float volumeBeforeMute = -1;

public static AudioManager Instance
{
get
Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}

0 comments on commit 26a3178

Please sign in to comment.