Exemple #1
0
        private void OnAfterFadeOut()
        {
            DisableCanvasGroup();

            FadeOutCompleted?.Invoke();

            fadeOutCoroutine = null;
        }
Exemple #2
0
    IEnumerator FadeOutRoutine(float fadeOutTime, float alphaMin, float alphaMax)
    {
        // fade out
        for (float elapsedTime = 0f; elapsedTime <= fadeOutTime; elapsedTime += Time.deltaTime)
        {
            _canvasToFade.alpha = Mathf.Lerp(alphaMax, alphaMin, elapsedTime / fadeOutTime);
            yield return(null);
        }
        _canvasToFade.alpha = alphaMin;

        FadeOutCompleted.Invoke();
    }
        private IEnumerator FadeOut()
        {
            EnableCanvasGroup();

            while (Alpha > 0.01f)
            {
                Alpha -= 1 * speed * Time.deltaTime;
                yield return(null);
            }

            DisableCanvasGroup();

            FadeOutCompleted?.Invoke();

            fadeOutCoroutine = null;
        }
        /// <summary>
        /// Manages the fadein/fadeout logic
        /// </summary>
        /// <param name="elapsed"></param>
        public void Update(TimeSpan elapsed)
        {
            switch (_currentFadeState)
            {
            case FadeState.FadeIn:

                _elapsed += elapsed;

                if (_elapsed >= _fadeDuration)
                {
                    _currentFadeState = FadeState.Static;
                    CurrentAlpha      = 1f;
                    OverlayColor      = _originalColor.WithAlpha(CurrentAlpha);
                    FadeInCompleted?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    CurrentAlpha = (float)(_elapsed.TotalSeconds / _fadeDuration.TotalSeconds);
                    OverlayColor = _originalColor.WithAlpha(CurrentAlpha);
                }

                break;

            case FadeState.FadeOut:

                _elapsed += elapsed;

                if (_elapsed >= _fadeDuration)
                {
                    _currentFadeState = FadeState.Static;
                    CurrentAlpha      = 0f;
                    OverlayColor      = _originalColor.WithAlpha(CurrentAlpha);
                    FadeOutCompleted?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    CurrentAlpha = 1f - ((float)(_elapsed.TotalSeconds / _fadeDuration.TotalSeconds));
                    OverlayColor = _originalColor.WithAlpha(CurrentAlpha);
                }

                break;
            }
        }
Exemple #5
0
 private void OnFadeOutCompleted()
 {
     FadeOutCompleted?.Invoke();
 }