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

@ -31,6 +31,13 @@ public class AudioManager : MonoBehaviour
}
}
[SerializeField, Range(0, 1)]
private float masterVolume = 1f;
private float prevMasterVolume;
private FMOD.ChannelGroup masterChannelGroup;
void Awake()
{
// Ensure FMOD is initialized the moment Instance is accessed
@ -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)

Loading…
Cancel
Save