Beispiel #1
0
        private void playBGMDefaultAdvance(string audioSource, string musicName, AudioLoop.LoopType loopType, float start, float end)
        {
            var                audioSourceData = audioSources.GetAudio(audioSource);
            AudioSource        audio           = audioSourceData.audio;
            AudioLoopCallbacks callback        = audioSourceData.callback;

            ClipDetail clipDetail = audioLibrary.GetBGMClip(musicName);

            if (!audio)
            {
                var source = setNewAudioSource(audioSource, true);
                audio    = source.audio;
                callback = source.callback;
            }

            if (audio.isPlaying)
            {
                stopBGMPlayed(audio, clipDetail, callback, true);
            }

            audio.loop   = true;
            audio.clip   = clipDetail.clip;
            audio.volume = globalBGMVolume * clipDetail.localVolume;
            audioLoopFunction.SetAudioSource(ref audio, ref callback);
            audioLoopFunction.PlayLoops(loopType, start, end);
        }
Beispiel #2
0
        private void stopBGMPlayed(AudioSource audio, ClipDetail clipDetail, AudioLoopCallbacks callback, bool immediatly)
        {
            if (!audio)
            {
                return;
            }

            if (immediatly)
            {
                audio.volume = 0;
                audio.Stop();
                audio.clip = null;
                callback?.Unsubscribe();
            }
            else
            {
                DOVirtual.Float(1, 0, timeFade, (x) =>
                {
                    audio.volume = globalBGMVolume * clipDetail.localVolume * x;
                }).OnComplete(() =>
                {
                    audio.volume = 0;
                    audio.Stop();
                    audio.clip = null;
                    callback?.Unsubscribe();
                });
            }
        }
Beispiel #3
0
        private void playBGMTransitionAdvance(string audioSource, string musicName, AudioLoop.LoopType loopType, float start, float end)
        {
            var                audioSourceData = audioSources.GetAudio(audioSource);
            AudioSource        audio           = audioSourceData.audio;
            AudioLoopCallbacks callback        = audioSourceData.callback;

            if (!audio)
            {
                var source = setNewAudioSource(audioSource, true);
                audio    = source.audio;
                callback = source.callback;
            }

            if (audio.isPlaying)
            {
                ClipDetail clipDetail = audioLibrary.GetBGMClip(audio.clip);
                DOVirtual.Float(1, 0, timeFade, (x) =>
                {
                    audio.volume = globalBGMVolume * clipDetail.localVolume * x;
                }).OnComplete(() => playBGMInTransitionAdvance(audio, musicName, loopType, start, end));
            }
            else
            {
                playBGMInTransitionAdvance(audio, musicName, loopType, start, end);
            }
        }
Beispiel #4
0
        private void playBGMDefault(string audioSource, string musicName, bool loop)
        {
            var                audioSourceData = audioSources.GetAudio(audioSource);
            AudioSource        audio           = audioSourceData.audio;
            AudioLoopCallbacks callback        = audioSourceData.callback;

            ClipDetail clipDetail = audioLibrary.GetBGMClip(musicName);

            if (!audio)
            {
                var source = setNewAudioSource(audioSource, false);
                audio    = source.audio;
                callback = source.callback;
            }

            if (audio.isPlaying)
            {
                stopBGMPlayed(audio, clipDetail, callback, true);
            }

            audio.loop   = loop;
            audio.clip   = clipDetail.clip;
            audio.volume = globalBGMVolume * clipDetail.localVolume;
            audio.Play();
        }
Beispiel #5
0
        private void playBGMInTransitionAdvance(AudioSource audio, string musicName, AudioLoop.LoopType loopType, float start, float end)
        {
            ClipDetail clipDetail = audioLibrary.GetBGMClip(musicName);

            audio.loop   = true;
            audio.clip   = clipDetail.clip;
            audio.volume = 0;
            audio.Play();
            DOVirtual.Float(0, 1, timeFade, (x) =>
            {
                audio.volume = globalBGMVolume * clipDetail.localVolume * x;
            });
        }
Beispiel #6
0
        private void playBGMInTransition(AudioSource audio, string musicName, bool loop)
        {
            ClipDetail clipDetail = audioLibrary.GetBGMClip(musicName);

            audio.loop   = loop;
            audio.clip   = clipDetail.clip;
            audio.volume = 0;
            audio.Play();
            DOVirtual.Float(0, 1, timeFade, (x) =>
            {
                audio.volume = globalBGMVolume * clipDetail.localVolume * x;
            });
        }
Beispiel #7
0
        private void playSFX(string audioSource, string musicName)
        {
            AudioSource audio = audioSources.GetAudio(audioSource).audio;

            if (!audio)
            {
                var source = setNewAudioSource(audioSource, false);
                audio = source.audio;
            }

            ClipDetail clipDetail = audioLibrary.GetSFXClip(musicName);

            audio.PlayOneShot(clipDetail.clip, globalSFXVolume * clipDetail.localVolume);
        }
Beispiel #8
0
        private void stopBGMPlayed(string audioSource, bool immediatly)
        {
            var                audioSourceData = audioSources.GetAudio(audioSource);
            AudioSource        audio           = audioSourceData.audio;
            AudioLoopCallbacks callback        = audioSourceData.callback;

            Debug.Log(audio + " " + audioSourceData);

            if (!audio || !audio.isPlaying)
            {
                return;
            }

            if (immediatly)
            {
                audio.volume = 0;
                audio.Stop();
                audio.clip = null;
                callback?.Unsubscribe();
            }
            else
            {
                ClipDetail clipDetail = audioLibrary.GetBGMClip(audio.clip);

                DOVirtual.Float(1f, 0f, timeFade, (x) =>
                {
                    audio.volume = globalBGMVolume * clipDetail.localVolume * x;
                }).OnComplete(() =>
                {
                    audio.volume = 0;
                    audio.Stop();
                    audio.clip = null;
                    callback?.Unsubscribe();
                });
            }
        }