示例#1
0
        public void PlayCollection(AudioClipCollection clipCollection, float volume = 1f)
        {
            if (volume <= 0f)
            {
                Debug.LogError("[PersistentBackgroundMusic] Volume must be higher than 0f.");
                return;
            }

            _currentSource.loop = false;
            ClipCollection      = clipCollection;
            var clip = clipCollection.GetClip();

            if (CrossFade)
            {
                CrossFadeClip(clip, volume);
                return;
            }

            _currentSource.clip = clip;
            if (FadeIn)
            {
                _currentSource.FadeIn(FadeInDuration, volume);
            }
            else
            {
                _currentSource.volume = volume;
                _currentSource.Play();
            }
        }
示例#2
0
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
     idleTrack.FadeIn(.5f, 1f);
     idleTrack.Play();
     PlayingIdleTrack = true;
 }
示例#3
0
        /// <summary>
        /// Play a given AudioSource. Does not need to be in the audioSources list.
        /// Will always be run on active instance, so it is safe to use in UnityEvents even if inactive.
        /// </summary>
        public void Play(AudioSource source)
        {
            if (inst != this)
            {
                inst.Play(source);
                return;
            }

            if (isPlaying)
            {
                Stop();
            }

            isPlaying     = true;
            currentSource = source;

            if (fadeIn)
            {
                source.FadeIn();
            }
            else
            {
                source.ClearFade();
                source.Play();
                started = true;
            }
        }
示例#4
0
        public void PlayBGMWithFade(string clipName, float fadeTime = DEFAULT_FADETIME, Action callback = null)
        {
            AudioClip clip = TSMUtil.GetAudioClipFromLoadedList(clipName, bgmAudioClips);

            if (bgmAudioSourceList.Find(source => source.clip == clip))
            {
                return;
            }

            AudioSource audioSouce = bgmAudioSourceList.FirstOrDefault(source => !source.isPlaying);

            if (audioSouce != null)

            {
                if (fadeTime == 0f)
                {
                    fadeTime = DEFAULT_FADETIME;
                }

                StopBGMWithFade(fadeTime);
                audioSouce.clip = clip;

                callback += () => { currentFadeInCoroutine = null; };
                currentFadeInCoroutine = StartCoroutine(audioSouce.FadeIn(fadeTime, callback));
            }
        }
        /// <summary>
        /// Plays a one off audio clip.
        /// </summary>
        /// <param name="clip">clip to play</param>
        /// <param name="volume">volume of the clip</param>
        /// <param name="looping">if the clip should loop</param>
        public void PlayOneShot(AudioClip clip, float volume = 1f, bool looping = false)
        {
            _currentSource.loop = looping;
            if (CrossFade && _currentSource.clip != null)
            {
                CrossFadeClip(clip, volume);
            }

            var startVolume = FadeIn || AlwaysFadeIn ? 0.01f : volume;

            _currentSource.PlayOneShot(clip, startVolume);
            if (FadeIn || AlwaysFadeIn)
            {
                _currentSource.FadeIn(FadeInDuration, volume);
            }
        }
示例#6
0
 public void PassToCombatTrack()
 {
     combatTrack.FadeIn(.5f, 1f);
     idleTrack.FadeOut(.5f);
     combatTrack.Play();
     PlayingIdleTrack   = false;
     PlayingCombatTrack = true;
 }
        public static bool PlayWithFadeIn(this AudioSource self, AudioClip clip, float volume, float duration)
        {
            if (clip == null || volume <= 0.0f)
            {
                return(false);
            }

            self.clip   = clip;
            self.volume = 0.0f;
            self.Play();
            self.FadeIn(volume, duration);
            return(true);
        }
示例#8
0
        private void OnSourceStop(AudioSource source)
        {
            if (!ClipCollection.IsEmpty)
            {
                source.clip = ClipCollection.GetClip();

                if (FadeIn && FadeOut || AlwaysFadeIn)
                {
                    source.FadeIn(FadeInDuration, source.volume);
                }
                else
                {
                    source.Play();
                }
            }
        }
示例#9
0
 /// <summary>
 /// BGMのフェードイン
 /// </summary>
 /// <param name="fadeTime">fade time</param>
 public void FadeInBGM(float fadeTime, float endVolume = 1.0f)
 {
     StartCoroutine(_bgmSource.FadeIn(fadeTime, endVolume));
 }
 public static IEnumerator FadeInAsCoroutine(this AudioSource self, float volume, float duration)
 {
     self.FadeIn(volume, duration);
     yield return(new WaitForSeconds(duration));
 }