public void SetBGMVolume(float volume) { if (bgmVolume == volume) { return; } bgmVolume = volume; for (int type = 0; type < soundTypeCount; type++) { Define.SoundType soundType = (Define.SoundType)type; if (!playingBGM.ContainsKey(soundType)) { continue; } if (playingBGM[soundType].fadingVolume == 0f) { playingBGM[soundType].source.volume = volume; } else { playingBGM[soundType].source.volume = playingBGM[soundType].fadingVolume; } } }
public void StopBGM(Define.SoundType soundType) { if (playingBGM.ContainsKey(soundType)) { playingBGM[soundType].source.Stop(); } }
public void AllPasueSound() { for (int type = 0; type < soundTypeCount; type++) { Define.SoundType soundType = (Define.SoundType)type; PauseSound(soundType); } }
public SoundPack(Define.SoundType type, AudioSource source) { this.type = type; this.source = source; fadingVolume = 0f; isPause = false; }
public void FadeInAndPlayBGM(Define.SoundType soundType, float time = 1f) { PlayBGM(soundType); if (playingBGM.ContainsKey(soundType)) { StartCoroutine(Fade(playingBGM[soundType], time, true)); } }
public void FadeOutAndStopBGM(Define.SoundType soundType, float time = 1f) { if (playingBGM.ContainsKey(soundType)) { StartCoroutine(Fade(playingBGM[soundType], time, false, () => { StopBGM(soundType); })); } }
public void ContinueBGM(Define.SoundType soundType) { if (playingBGM.ContainsKey(soundType)) { if (!playingBGM[soundType].source.isPlaying) { playingBGM[soundType].source.UnPause(); } } }
public void AllContinueSound() { for (int type = 0; type < soundTypeCount; type++) { Define.SoundType soundType = (Define.SoundType)type; if (!playingAudio.ContainsKey(soundType)) { continue; } ContinueSound(soundType); } }
public void ContinueAllBGM() { for (int type = 0; type < soundTypeCount; type++) { Define.SoundType soundType = (Define.SoundType)type; if (!playingBGM.ContainsKey(soundType)) { continue; } ContinueBGM(soundType); } }
public void StopSound(Define.SoundType soundType) { if (playingAudio.ContainsKey(soundType)) { for (int i = playingAudio[soundType].Count - 1; i >= 0; i--) { AudioSource source = playingAudio[soundType][i].source; playingAudio[soundType][i].source.Stop(); playingAudio[soundType].RemoveAt(i); ReturnAudioSource(source); } } }
public void AllStopSound() { for (int type = 0; type < soundTypeCount; type++) { Define.SoundType soundType = (Define.SoundType)type; if (!playingAudio.ContainsKey(soundType)) { continue; } StopSound(soundType); playingAudio[soundType].Clear(); } }
public void ContinueSound(Define.SoundType soundType) { if (playingAudio.ContainsKey(soundType)) { for (int i = 0, max = playingAudio[soundType].Count; i < max; i++) { if (!playingAudio[soundType][i].source.isPlaying) { playingAudio[soundType][i].source.UnPause(); } playingAudio[soundType][i].SetPause(false); } } }
private AudioClip LoadAudioClip(Define.SoundType type, string path) { switch (type) { case Define.SoundType.BGM: return(GameManager.Resource.Load <AudioClip>($"SoundSources/BGM/{path}")); case Define.SoundType.FX: return(GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}")); case Define.SoundType.LoopFX: return(GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}")); } return(null); }
public async Task PlayAsync(Define.SoundType type, string path, float duration, float volume = 1f) { if (LoadAudioAndClip(type, path, out var audio, out var source) == false) { return; } if (audio.isPlaying) { await DoTransition(audio, source, duration, volume); } else { await DoPlay(audio, source, duration, volume); } }
public void PauseSound(Define.SoundType soundType) { if (!playingAudio.ContainsKey(soundType)) { return; } for (int i = 0, max = playingAudio[soundType].Count; i < max; i++) { if (playingAudio[soundType][i].source.isPlaying) { playingAudio[soundType][i].source.Pause(); } playingAudio[soundType][i].SetPause(true); } }
public void PlaySound(Define.SoundType soundType) { if (soundStore.ContainsKey(soundType)) { if (!playingAudio.ContainsKey(soundType)) { playingAudio.Add(soundType, new List <SoundPack>()); } AudioSource source = GetAudioSource(); playingAudio[soundType].Add(new SoundPack(soundType, source)); source.clip = soundStore[soundType]; source.volume = soundVolume; source.loop = false; source.Play(); } }
private void Update() { for (int type = 0; type < soundTypeCount; type++) { Define.SoundType soundType = (Define.SoundType)type; if (playingAudio.ContainsKey(soundType)) { for (int i = playingAudio[soundType].Count - 1; i >= 0; i--) { if (!playingAudio[soundType][i].source.isPlaying && !playingAudio[soundType][i].isPause) { ReturnAudioSource(playingAudio[soundType][i].source); playingAudio[soundType].RemoveAt(i); } } } } }
public void Play(Define.SoundType type, string path, float volume = 1f) { AudioClip source = null; switch (type) { case Define.SoundType.BGM: source = GameManager.Resource.Load <AudioClip>($"SoundSources/BGM/{path}"); if (source == null) { Debug.Log($"'{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/BGM 폴더를 확인해주세요."); return; } audio[(int)type].clip = source; audio[(int)type].volume = volume; audio[(int)type].Play(); break; case Define.SoundType.FX: source = GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}"); if (source == null) { Debug.Log($"'{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/FX 폴더를 확인해주세요."); return; } audio[(int)type].PlayOneShot(source, volume); break; case Define.SoundType.LoopFX: source = GameManager.Resource.Load <AudioClip>($"SoundSources/FX/{path}"); if (source == null) { Debug.Log($"'{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/FX 폴더를 확인해주세요."); return; } audio[(int)type].clip = source; audio[(int)type].volume = volume; audio[(int)type].Play(); break; } }
public void Play(Define.SoundType type, string path, float volume = 1f) { if (LoadAudioAndClip(type, path, out var audio, out var source) == false) { return; } switch (type) { case Define.SoundType.BGM: case Define.SoundType.LoopFX: audio.clip = source; audio.volume = volume; audio.Play(); break; case Define.SoundType.FX: audio.PlayOneShot(source, volume); break; } }
private bool LoadAudioAndClip(Define.SoundType type, string path, out AudioSource audio, out AudioClip clip) { audio = null; clip = null; if ((int)type >= audios.Length) { Debug.LogError($"유효하지 않은 타입입니다: {type}"); return(false); } audio = audios[(int)type]; clip = LoadAudioClip(type, path); if (clip == null) { Debug.LogError($"'{type}' 타입의 '{path}' 사운드 정보를 찾을 수 없습니다. Resources/SoundSources/ 폴더를 확인해주세요."); return(false); } return(true); }
public void PlayBGM(Define.SoundType soundType, bool bLoop = true) { if (soundStore.ContainsKey(soundType)) { if (!playingBGM.ContainsKey(soundType)) { playingBGM.Add(soundType, new SoundPack(soundType, GetAudioSource())); } if (playingBGM[soundType].source.isPlaying) { return; } AudioClip source = soundStore[soundType]; playingBGM[soundType].source.clip = source; playingBGM[soundType].source.volume = bgmVolume; playingBGM[soundType].source.loop = bLoop; playingBGM[soundType].source.Play(); } }
public void SetSoundVolume(float volume) { if (soundVolume == volume) { return; } soundVolume = volume; for (int type = 0; type < soundTypeCount; type++) { Define.SoundType soundType = (Define.SoundType)type; if (!playingAudio.ContainsKey(soundType)) { continue; } for (int i = 0, max = playingAudio[soundType].Count; i < max; i++) { playingAudio[soundType][i].source.volume = volume; } } }
public void Stop(Define.SoundType type) { audio[(int)type].Stop(); }