/// <summary> /// Stop current track /// </summary> private IEnumerator StopMusicCoroutine() { yield return(DropVolume()); AudioSourceBGM.volume = 0; AudioSourceBGM.Stop(); }
/// <summary> /// Do all process to change current track /// </summary> private IEnumerator ChangeMusicCoroutine() { yield return(DropVolume()); IsSongPlaying = false; AudioSourceBGM.volume = 0; AudioSourceBGM.clip = nextTrackClip; AudioSourceBGM.loop = isToLoopTrack; AudioSourceBGM.Play(); IsSongPlaying = true; if (PausePanelController.Instance && nextTrackInfo != null) { PausePanelController.Instance.SetTrackInfo(nextTrackInfo); } yield return(GainVolume()); if (!isToLoopTrack && isToChangeOnTrackEnd && PausePanelController.Instance) { yield return(new WaitForSecondsRealtime(AudioSourceBGM.clip.length)); int index = Random.Range(0, allNotLoopedSongs.Length); AudioClip nextClip = allNotLoopedSongs[index]; Track nextRandomTrack = Tracks.Find(t => t.FileName.Equals(nextClip.name)); ChangeMusic(nextClip, false, string.Empty, false, true, nextRandomTrack); } }
/// <summary> /// Pause or unpause current track /// </summary> /// <param name="isToPause"> Is to pause current track ? </param> public void PauseMusic(bool isToPause) { if (isToPause) { AudioSourceBGM.Pause(); } else { AudioSourceBGM.UnPause(); } }
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(); } }
public void ResumeBGM() { AudioSourceBGM.UnPause(); }
public void PauseBGM() { AudioSourceBGM.Pause(); }