/// <summary> /// Stop current track /// </summary> private IEnumerator StopMusicCoroutine() { yield return(DropVolume()); AudioSourceBGM.volume = 0; AudioSourceBGM.Stop(); }
private void PlayBGM(AudioData audioDat) { if (audioDat.SoundClip == null) { #if UNITY_EDITOR Debug.LogWarning($"Audio clip with name {audioDat.Name} is null!"); #endif return; } if (AudioSourceBGM.isPlaying) { if (AudioSourceBGM.clip != audioDat.SoundClip) { AudioMixer.GetFloat(BGM_VOLUME, out float vol); _ltBGMCache = LeanTween.value(gameObject, (float val) => { AudioMixer.SetFloat(BGM_VOLUME, val); }, vol, -80, BGM_TRANSITION_DELAY).setOnComplete(() => { if (!IsBGMOn) { vol = -80; } AudioMixer.SetFloat(BGM_VOLUME, -80f); //-80 disini itu volume = 0 di Audio Mixer AudioSourceBGM.Stop(); AudioSourceBGM.volume = audioDat.Volume; AudioSourceBGM.clip = audioDat.SoundClip; AudioSourceBGM.Play(); _ltBGMCache = LeanTween.value(gameObject, (float val) => { AudioMixer.SetFloat(BGM_VOLUME, val); }, -80f, vol, BGM_TRANSITION_DELAY).setOnComplete(() => { AudioMixer.SetFloat(BGM_VOLUME, vol); }); }); } } else { AudioSourceBGM.volume = audioDat.Volume; AudioSourceBGM.clip = audioDat.SoundClip; AudioSourceBGM.Play(); } }