|
|
|
@ -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) |
|
|
|
|