86 lines
2.3 KiB
C#
86 lines
2.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Pool;
|
|
|
|
public class SoundManager : SingletonMonoBehaviour<SoundManager>
|
|
{
|
|
[SerializeField] AudioClip[] backgroundMusic;
|
|
[SerializeField] AudioClip[] buttonSuond;
|
|
[SerializeField] AudioClip[] eftSuond;
|
|
float backgroundvolume = 0.1f;
|
|
float eftvolume = 0.3f;
|
|
public eBackgroundMusic nowMusic;
|
|
[SerializeField] GameObject eftSound;
|
|
ObjectPool<SoundBox> soundPool;
|
|
List<SoundBox> soundList = new List<SoundBox>();
|
|
|
|
|
|
AudioSource BackGround;
|
|
public eBackgroundMusic NowPlayMusic//현재 재생중인 배경음악 정보를 넘겨줌
|
|
{
|
|
get { return nowMusic; }
|
|
}
|
|
|
|
public void PlayBack(eBackgroundMusic Num)
|
|
{
|
|
BackGround.clip = backgroundMusic[(int)Num];
|
|
BackGround.mute = false;
|
|
BackGround.loop = true;
|
|
BackGround.volume = backgroundvolume;
|
|
BackGround.Play();
|
|
nowMusic = Num;
|
|
}
|
|
protected override void OnAwake()
|
|
{
|
|
eftSound = (GameObject)Resources.Load("System/SoundBox");
|
|
BackGround = GetComponent<AudioSource>();
|
|
soundPool = new ObjectPool<SoundBox>(PrefabsOnCreate, PrefabsOnGet, PrefabsOnRelease, null, true, 20);
|
|
nowMusic = 0;
|
|
}
|
|
private SoundBox PrefabsOnCreate()
|
|
{
|
|
return Instantiate<GameObject>(eftSound, transform).GetComponent<SoundBox>();
|
|
}
|
|
|
|
private void PrefabsOnGet(SoundBox sound)
|
|
{
|
|
soundList.Add(sound);
|
|
sound.gameObject.SetActive(true);
|
|
}
|
|
private void PrefabsOnRelease(SoundBox sound)
|
|
{
|
|
sound.gameObject.SetActive(false);
|
|
soundList.Remove(sound);
|
|
}
|
|
|
|
public void StartSound(eEftSuond Clip)
|
|
{
|
|
var obj = soundPool.Get();
|
|
obj.gameObject.SetActive(true);
|
|
obj.PlaySound(eftSuond[(int)Clip], eftvolume);
|
|
}
|
|
public void StartSound(eEftSuond Clip,Vector3 tr)
|
|
{
|
|
var obj = soundPool.Get();
|
|
obj.gameObject.SetActive(true);
|
|
obj.PlaySound(eftSuond[(int)Clip], eftvolume, tr);
|
|
}
|
|
public void EndSound(SoundBox Box)
|
|
{
|
|
Box.gameObject.SetActive(false);
|
|
soundPool.Release(Box);
|
|
}
|
|
public enum eBackgroundMusic
|
|
{
|
|
}
|
|
public enum eButtonSuond
|
|
{
|
|
}
|
|
public enum eEftSuond
|
|
{
|
|
TitleSound,
|
|
ButtonPop,
|
|
test,
|
|
}
|
|
}
|