123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class AudioManager : MonoBehaviour
- {
- public static AudioManager Instance { get; private set; }
- private AudioSource ad;
- private Animator anim;
- private Dictionary<string,AudioClip> clipDic = new Dictionary<string,AudioClip>();
- private async void Awake()
- {
- Instance = this;
- ad = gameObject.AddComponent<AudioSource>();
- anim = gameObject.AddComponent<Animator>();
- ad.volume = 0.5f;
- //anim.runtimeAnimatorController = await YooAssetManager.Instance.LoadAsset<RuntimeAnimatorController>("AudioManager");
- DontDestroyOnLoad(gameObject);
- }
- /// <summary>
- /// 꺄렴교쒼稜있
- /// </summary>
- /// <param name="audioName"></param>
- public async void PlayAudio(string audioName, bool loop = false)
- {
- if (ad.clip == null)
- {
- ad.clip = await YooAssetManager.Instance.LoadAsset<AudioClip>(audioName);
- ad.volume = 0.5f;
- ad.Play();
- ad.loop = true;
- }
- else
- {
- Debug.Log(anim);
- //anim.Play("bgmdown");
- StartCoroutine("PlayUp", audioName);
- }
- }
- /// <summary>
- /// 못膠竟藤속�稜莉숭 꺄렴뗌접돨稜틉
- /// </summary>
- /// <param name="audioName"></param>
- public void PlayDirectAudio(GameObject go, string audioName, float volume = 1, bool loop = false)
- {
- AudioSource goAD;
- if (go.GetComponent<AudioSource>())
- {
- goAD = go.GetComponent<AudioSource>();
- }
- else
- {
- goAD = go.AddComponent<AudioSource>();
- }
- goAD.spatialBlend = 0; goAD.dopplerLevel = 1; goAD.spread = 45; goAD.rolloffMode = AudioRolloffMode.Logarithmic;
- goAD.minDistance = 20; goAD.maxDistance = 500; goAD.volume = volume; goAD.loop = loop;
- goAD.clip = clipDic[audioName];
- if (goAD.clip != null) goAD.Play();
- }
- /// <summary>
- /// 꺄렴供뎠품AudioManager稜틉헌왕
- /// </summary>
- public void AudioFinished()
- {
- StartCoroutine("Finished", ad);
- }
- /// <summary>
- /// 꺄렴供뎠품膠竟稜틉헌왕
- /// </summary>
- /// <param name="go"></param>
- public void AudioFinished(GameObject go)
- {
- AudioSource gAD = go.GetComponent<AudioSource>();
- if (gAD) StartCoroutine("Finished", gAD);
- }
- IEnumerator Finished(AudioSource audioSource)
- {
- yield return new WaitForSeconds(audioSource.clip.length);
- audioSource.clip = null;
- Destroy(audioSource);
- StopCoroutine("Finished");
- }
- /// <summary>
- /// 교쒼稜있숑흽돕轟
- /// </summary>
- public void Mute()
- {
- //anim.Play("bgmdown");
- }
- /// <summary>
- /// 교쒼稜있쉈퓻
- /// </summary>
- public void VolumeUp()
- {
- //anim.Play("bgmup");
- }
- /// <summary>
- /// 쓰稜 GameObject
- /// </summary>
- /// <param name="go"></param>
- public void Mute(GameObject go)
- {
- AudioSource gAD = go.GetComponent<AudioSource>();
- gAD.mute = true;
- }
-
- /// <summary>
- /// �零稜좆
- /// </summary>
- /// <param name="volume"></param>
- public void SetVolume(float volume)
- {
- ad.volume = volume;
- }
- }
|