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