using System.Collections; using System.Collections.Generic; using UnityEngine; using FMODUnity; using FMOD.Studio; public class AudioManager : MonoBehaviour { private List eventInstances; private EventInstance musicEventInstance; public static AudioManager instance { get; private set; } private void Awake() { if (instance != null) { Debug.LogError("Found more than one Audio Manager in the scene"); } instance = this; eventInstances = new List(); } private void Start() { InitializeMusic(FMODEvents.instance.music); } private void InitializeMusic(EventReference musicEventReference) { musicEventInstance = CreateEventInstance(musicEventReference); musicEventInstance.start(); } public void PlayOneShot(EventReference sound, Vector3 worldPos) { RuntimeManager.PlayOneShot(sound, worldPos); } public void PauseMusic() { musicEventInstance.setPaused(true); } public void PlayMusic() { musicEventInstance.setPaused(false); } public void StopMusic() { musicEventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); } public EventInstance CreateEventInstance(EventReference eventReference) { EventInstance eventInstance = RuntimeManager.CreateInstance(eventReference); eventInstances.Add(eventInstance); return eventInstance; } private void CleanUp() { foreach (EventInstance eventInstance in eventInstances) { eventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); eventInstance.release(); } } private void OnDestroy() { CleanUp(); } }