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); } }
/// <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); }
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(); } } }
public void FadeIn(float duration, FadeCompleted callBack = null) { timeToFade = duration; this.callBack = callBack; StopAllCoroutines(); StartCoroutine(FadeIn()); }
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(); } }
/// <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(); }
/// <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()); }
/// <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(); }
/// <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); }
/// <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)); }
protected virtual void OnFadeCompleted(FadeEventArgs e) { FadeCompleted?.Invoke(this, e); }