Browse Source

Added a volume slider to the inspector for the audio manager, so we can silence the game during testing if audio is not needed

readme
Nico de Poel 5 years ago
parent
commit
d3a585beee
  1. 26
      Assets/Scripts/AudioManager.cs

26
Assets/Scripts/AudioManager.cs

@ -30,6 +30,13 @@ public class AudioManager : MonoBehaviour
return instance; return instance;
} }
} }
[SerializeField, Range(0, 1)]
private float masterVolume = 1f;
private float prevMasterVolume;
private FMOD.ChannelGroup masterChannelGroup;
void Awake() void Awake()
{ {
@ -43,6 +50,20 @@ public class AudioManager : MonoBehaviour
InitFmod(); 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() void OnDisable()
{ {
// Ensure FMOD gets closed before hot reload // 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); result = fmodSystem.init(MaxVirtualChannels, FMOD.INITFLAGS.VOL0_BECOMES_VIRTUAL, IntPtr.Zero);
CheckFmodResult(result, "FMOD.System.init"); 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) private void CheckFmodResult(FMOD.RESULT result, string cause)

Loading…
Cancel
Save