Exemplo n.º 1
0
 public void PlayBG(BGAudio audio)
 {
     _source.clip = GetClip(audio.ToString());
     SetVolume(audio.ToString(), _source);
     _source.loop = true;
     _source.Play();
 }
Exemplo n.º 2
0
 public void PlayBG(BGAudio audio)
 {
     mBGAudioSource.clip = GetAudioClip(audio);
     SetVolume(audio.ToString(), mBGAudioSource);
     mBGAudioSource.loop = true;
     mBGAudioSource.Play();
 }
Exemplo n.º 3
0
        private IEnumerator BGAudioFadeOutRoutine(BGAudio bgAudio)
        {
            bgAudio.volumeTween.PlayBackward(true);

            yield return(new WaitForSeconds(bgAudio.volumeTween.playbackTime));

            RemoveBGAudio(bgAudio);
        }
Exemplo n.º 4
0
        public void StopBGAudio(string path, float fadeOutTime)
        {
            BGAudio bgAudio = currentlyPlayingBG.Find(_bgAudio => _bgAudio.path == FixPath(path));

            if (bgAudio != null)
            {
                StopBGAudio(bgAudio, fadeOutTime);
            }
        }
 public void PlayNextClip()
 {
     if (_index < audioClips.Length) {
         _cutoff = float.MaxValue;
         if (audioClips [Mathf.Clamp(_index, 0, int.MaxValue)].earlyCutoff > 0) {
             _cutoff = audioSource.clip.length - audioClips [Mathf.Clamp(_index, 0, int.MaxValue)].earlyCutoff;
         }
         _index++;
         GetComponent<AudioSource> ().loop = false;
         _queuedClip = audioClips [_index];
     }
 }
Exemplo n.º 6
0
        private void RemoveBGAudio(BGAudio bgAudio)
        {
            if (!currentlyPlayingBG.Contains(bgAudio))
            {
                return;
            }

            Destroy(bgAudio.volumeTween);
            Destroy(bgAudio.audioSource);

            currentlyPlayingBG.Remove(bgAudio);
        }
Exemplo n.º 7
0
 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
         return;
     }
     else
     {
         instance = this;
     }
     DontDestroyOnLoad(this.gameObject);
 }
Exemplo n.º 8
0
        public BGAudio PlayBGAudio(
            string path,
            bool repeat             = false,
            float volume            = 1f,
            float fadeInTime        = 0f,
            SystemLanguage language = SystemLanguage.English,
            int clipIndex           = -1)
        {
            AudioClip audioClip = GetAudioClip(path, language, clipIndex);

            if (audioClip == null)
            {
                return(null);
            }

            AudioSource audioSource = gameObject.AddComponent <AudioSource>();

            audioSource.clip = audioClip;
            audioSource.loop = repeat;
            audioSource.outputAudioMixerGroup = bgOutputGroup;

            VolumeTween volumeTween = gameObject.AddComponent <VolumeTween>();

            volumeTween.audioSource  = audioSource;
            volumeTween.playbackTime = fadeInTime;
            volumeTween.to           = volume;
            volumeTween.curve        = new AnimationCurve(new Keyframe(0f, 0f), new Keyframe(1f, 1f));

            volumeTween.PlayForward(true);

            BGAudio bgAudio = new BGAudio()
            {
                path        = FixPath(path),
                audioSource = audioSource,
                volumeTween = volumeTween,
                audioClip   = audioClip,
            };

            audioSource.Play();

            if (!repeat)
            {
                bgAudio.playbackRoutine = StartCoroutine(BGAudioRoutine(bgAudio));
            }

            currentlyPlayingBG.Add(bgAudio);

            return(bgAudio);
        }
Exemplo n.º 9
0
        public void StopBGAudio(BGAudio bgAudio, float fadeOutTime = 0f)
        {
            if (bgAudio == null || !currentlyPlayingBG.Contains(bgAudio) || !this)
            {
                return;
            }

            bgAudio.volumeTween.playbackTime = fadeOutTime;

            if (bgAudio.playbackRoutine != null)
            {
                StopCoroutine(bgAudio.playbackRoutine);
            }

            StartCoroutine(BGAudioFadeOutRoutine(bgAudio));
        }
    // Update is called once per frame
    void Update()
    {
        currentTime = audioSource.time;
        if (_queuedClip != null) {
            if (!audioSource.isPlaying || (audioSource.isPlaying && _cutoff < audioSource.time)) {
                // If we ever get here when a skip has been requested, we need to do something a bit special.
                if (_skip) {
                    Debug.Log ("AAAAAAAA");
                } else {
                    audioSource.clip = _queuedClip.audioClip;
                    audioSource.loop = _queuedClip.loop;
                    audioSource.Play ();
                    if (!_queuedClip.loop) {
                        timer.timeRemaining = _queuedClip.audioClip.length - _queuedClip.earlyCutoff;
                        timer.StartTimer ();
                        timer.destroyMe = false;
                    }
                    _queuedClip = null;
                }
            }
        }

        if (_skip) {
            _cutoff = audioClips [_index].audioClip.length - audioClips [_index].earlyCutoff;
            timer.timeRemaining = audioClips [_index].audioClip.length - audioSource.time - audioClips [_index].earlyCutoff;
            timer.StartTimer ();
            _skip = false;
        }
    }
Exemplo n.º 11
0
        private IEnumerator BGAudioRoutine(BGAudio bgAudio)
        {
            yield return(new WaitForSeconds(bgAudio.audioClip.length - bgAudio.volumeTween.playbackTime));

            StartCoroutine(BGAudioFadeOutRoutine(bgAudio));
        }
Exemplo n.º 12
0
 public AudioClip GetAudioClip(BGAudio aduio)
 {
     return(GetAudioClip(aduio.ToString()));
 }