using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Audio; public class AudioManager : MonoBehaviour { public static AudioManager Instance; [Header("AudioMixer")] public AudioMixer mixer; public AudioMixerSnapshot defaultSnapshot; public AudioMixerSnapshot muteSnapshot; [Header("References")] public AudioSource musicSource; public AudioSource sfxSource; [Header("Musics")] public List musics = new List(); private bool isMute = false; private void Awake() { Instance = this; } public void ChangeMusic(MusicTitle _title) { Debug.Log($"changing music to {_title}"); musicSource.clip = musics.Find(x => x.title == _title).clip; musicSource.Play(); } public void StopMusic() { musicSource.Stop(); } public void PlaySFX(AudioClip _clip) { Debug.Log($"playing {_clip.name} SFX"); sfxSource.PlayOneShot(_clip); } public void ToggleMute(bool _toggle) { mixer.TransitionToSnapshots(new AudioMixerSnapshot[] { defaultSnapshot, muteSnapshot }, _toggle ? new float[] { 0, 1 } : new float[] { 1, 0 }, 0.2f); } } [System.Serializable] public class MusicByTitle { public MusicTitle title; public AudioClip clip; } public enum MusicTitle { Menu, TakingPicture, VotingSession, Ending }