From d3a585beee9c4664745e18a4d7e09d1c6e13424e Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 23 Jul 2021 09:10:59 +0200 Subject: [PATCH] Added a volume slider to the inspector for the audio manager, so we can silence the game during testing if audio is not needed --- Assets/Scripts/AudioManager.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Assets/Scripts/AudioManager.cs b/Assets/Scripts/AudioManager.cs index 1e7f5ce..c00020e 100644 --- a/Assets/Scripts/AudioManager.cs +++ b/Assets/Scripts/AudioManager.cs @@ -30,6 +30,13 @@ public class AudioManager : MonoBehaviour return instance; } } + + [SerializeField, Range(0, 1)] + private float masterVolume = 1f; + + private float prevMasterVolume; + + private FMOD.ChannelGroup masterChannelGroup; void Awake() { @@ -43,6 +50,20 @@ public class AudioManager : MonoBehaviour InitFmod(); } + void Update() + { + if (!fmodSystem.hasHandle() || !masterChannelGroup.hasHandle()) + return; + + if (!Mathf.Approximately(masterVolume, prevMasterVolume)) + { + masterChannelGroup.setVolume(masterVolume); + prevMasterVolume = masterVolume; + } + + masterChannelGroup.getVolume(out masterVolume); + } + void OnDisable() { // Ensure FMOD gets closed before hot reload @@ -85,6 +106,11 @@ public class AudioManager : MonoBehaviour result = fmodSystem.init(MaxVirtualChannels, FMOD.INITFLAGS.VOL0_BECOMES_VIRTUAL, IntPtr.Zero); CheckFmodResult(result, "FMOD.System.init"); + + result = fmodSystem.getMasterChannelGroup(out masterChannelGroup); + CheckFmodResult(result, "FMOD.System.getMasterChannelGroup"); + masterChannelGroup.setVolume(masterVolume); + prevMasterVolume = masterVolume; } private void CheckFmodResult(FMOD.RESULT result, string cause)