Example #1
0
        public IEnumerator FadeOut(float seconds)
        {
            if (!_fadingOut)
            {
                _fadingOut = true;
                var totalSeconds = seconds;

                float introSourceVolume = 0;
                if (_introSource != null)
                {
                    introSourceVolume = _introSource.volume;
                }
                float loopSourceVolume = 0;
                if (_loopSource != null)
                {
                    loopSourceVolume = _loopSource.volume;
                }

                if (_loopSource != null && _data.CacheExecution)
                {
                    var name = _data.Name;
                    K_EXECUTION_POINT[name] = new LastExecutionData(_loopSource.time, seconds);
                }

                while (seconds > 0 && ((_introSource != null) || (_loopSource != null)))
                {
                    seconds -= Time.deltaTime;

                    var step = seconds / totalSeconds;
                    step = FloatAnimator.EasyInEasyOut(step, .5f);

                    if (_introSource != null)
                    {
                        _introSource.volume = introSourceVolume * step;
                    }
                    if (_loopSource != null)
                    {
                        _loopSource.volume = loopSourceVolume * step;
                    }

                    yield return(null);
                }

                if (_introSource != null)
                {
                    GameObject.Destroy(_introSource.gameObject);
                }
                if (_loopSource != null)
                {
                    GameObject.Destroy(_loopSource.gameObject);
                }

                _fadingOut = false;
            }
        }
Example #2
0
        public IEnumerator FadeIn(AudioSource source, float seconds)
        {
            float accTime = 0;

            while (accTime < seconds && !_fadingOut)
            {
                accTime += Time.deltaTime;
                if (accTime > seconds)
                {
                    accTime = seconds;
                }

                source.volume = FloatAnimator.EasyInEasyOut(accTime / seconds, .5f);
                yield return(null);
            }
        }