Пример #1
0
        /// <summary>
        /// Stop current track
        /// </summary>
        private IEnumerator StopMusicCoroutine()
        {
            yield return(DropVolume());

            AudioSourceBGM.volume = 0;
            AudioSourceBGM.Stop();
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
 /// <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();
     }
 }
Пример #4
0
    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();
        }
    }
Пример #5
0
 public void ResumeBGM()
 {
     AudioSourceBGM.UnPause();
 }
Пример #6
0
 public void PauseBGM()
 {
     AudioSourceBGM.Pause();
 }