private IEnumerator FadeCoroutine(float timeToTake, float startA, float endA, bool destroyOnComplete)
    {
        imageBlack.gameObject.SetActive(true);
        imageBlack.enabled = true;

        Color baseColor = imageBlack.color;

        float startTime = Time.time;

        while (true)
        {
            float t = (Time.time - startTime) / timeToTake;

            if (t >= 1)
            {
                break;
            }
            else
            {
                imageBlack.color = LerpA(baseColor, startA, endA, t);
            }

            yield return(new WaitForFixedUpdate());
        }

        imageBlack.color = LerpA(baseColor, startA, endA, 1);

        FadeCompleted?.Invoke();
        if (destroyOnComplete)
        {
            Destroy(gameObject);
        }
    }
示例#2
0
        /// <summary>
        /// Fade a form out at the defined speed and
        /// close it when the fade has completed.
        /// After the form has closed, call the FadeComplete delegate.
        /// </summary>
        public static void FadeOutAndClose(Form form, float fadeSpeed, FadeCompleted finished)
        {
            Fader fader = new Fader(form);

            fader.shouldClose = true;
            fader.fadeOut(fadeSpeed, finished);
        }
示例#3
0
        private void Update()
        {
            if (!m_enabled)
            {
                return;
            }

            m_alpha += m_fadeSpeed * (Time.deltaTime > 0 ? Time.deltaTime : Time.unscaledDeltaTime) * m_sign;

            if (FadeUpdate != null)
            {
                FadeUpdate.Invoke(m_sign, m_alpha);
            }

            if ((m_sign == 1 && m_alpha >= 1) || (m_sign == -1 && m_alpha <= 0))
            {
                m_alpha = m_sign == 1 ? 1 : 0;

                if (m_alpha <= 0)
                {
                    m_enabled = false;
                }

                if (FadeCompleted != null)
                {
                    FadeCompleted.Invoke();
                }
            }
        }
示例#4
0
 public void FadeIn(float duration, FadeCompleted callBack = null)
 {
     timeToFade    = duration;
     this.callBack = callBack;
     StopAllCoroutines();
     StartCoroutine(FadeIn());
 }
示例#5
0
 private async void Fade_Completed(object sender, AnimationSetCompletedEventArgs e)
 {
     if (sender is AnimationSet animSet)
     {
         FadeCompleted?.Invoke(sender, e);
         animSet.Completed -= FadeCompleted;
         _animations.Remove(animSet);
         await ShowControlAsync();
     }
 }
示例#6
0
        /// <summary>
        /// Fade the form in at the defined speed.
        /// </summary>
        private void fadeIn(float fadeSpeed, FadeCompleted finished)
        {
            form.Opacity = 0;
            form.Show();

            fadeFinished   = finished;
            this.fadeSpeed = fadeSpeed;
            fadeDirection  = FadeDirection.In;

            beginFade();
        }
示例#7
0
        /// <summary>
        /// Fade the form in at the defined speed as a dialog
        /// based on parent form.
        /// </summary>
        private DialogResult showDialog(float fadeSpeed, FadeCompleted finished)
        {
            dialogResult = form.ShowDialog(parent);

            fadeFinished   = finished;
            form.Opacity   = 0;
            this.fadeSpeed = fadeSpeed;
            fadeDirection  = FadeDirection.In;

            return(beginFade());
        }
示例#8
0
        /// <summary>
        /// Fade the form out at the defined speed.
        /// </summary>
        private void fadeOut(float fadeSpeed, FadeCompleted finished)
        {
            if (form.Opacity < 0.1)
            {
                finished?.Invoke();
                return;
            }

            fadeFinished   = finished;
            form.Opacity   = 100;
            this.fadeSpeed = fadeSpeed;
            fadeDirection  = FadeDirection.Out;

            beginFade();
        }
示例#9
0
        /// <summary>
        /// Fade a form out at the defined speed.
        /// </summary>
        public static void FadeOut(Form form, float fadeSpeed, FadeCompleted finished)
        {
            Fader fader = new Fader(form);

            fader.fadeOut(fadeSpeed, finished);
        }
示例#10
0
        /// <summary>
        /// Fades a dialog in using parent form and defined fade speed
        /// and call the finished delegate.)
        /// </summary>
        public static DialogResult ShowDialog(Form form, Form parent, float fadeSpeed, FadeCompleted finished)
        {
            Fader fader = new Fader(form, parent);

            return(fader.showDialog(fadeSpeed, finished));
        }
示例#11
0
 protected virtual void OnFadeCompleted(FadeEventArgs e)
 {
     FadeCompleted?.Invoke(this, e);
 }