//Add a fade in operation by method public void AddFadeIn(float duration) { FadeOperation fadeIn = new FadeOperation(FadeOption.FadeIn, duration); fadeIn.ConfigureFade(canvasGroup); fadeOperations.Add(fadeIn); }
//Add a fade in operation by method public void AddFadeOut(float duration) { FadeOperation fadeOut = new FadeOperation(FadeOption.FadeOut, duration); fadeOut.ConfigureFade(canvasGroup); fadeOperations.Add(fadeOut); }
void Update() { if (fadeOperations.Count == 0) { OpsHasFinished = true; return; } OpsHasFinished = false; FadeOperation fadeOp = fadeOperations [0]; fadeOp.Update(); if (fadeOp.fadeDone) { UpdateFadeStatus(fadeOp); fadeOperations.Remove(fadeOp); //if there are more operations go to the next otherwise stop if (fadeOperations.Count > 0) { fadeOperations[0].ConfigureFade(canvasGroup); } } }
void UpdateFadeStatus(FadeOperation fadeOp) { if (fadeOp.fadeOption == FadeOption.FadeIn) { isFadeIn = true; } else { isFadeIn = false; } }
void targetForm_Load(object sender, EventArgs e) { //Check to see if the form is about to be shown //Make sure that we are dealing with a layered window EnsureLayeredWindow(); //Set the fade oparetion _fadeOperation = FadeOperation.FadeIn; //Start the transition _timer.Enabled = true; }
void targetForm_FormClosing(object sender, FormClosingEventArgs e) { if (!e.Cancel && e.CloseReason == CloseReason.UserClosing) { //Make sure that we are not already in a fading process. //This can happen if the fade in operation is not finished before the user closes the form if (_isFading) { _timer.Enabled = false; e.Cancel = false; } else { //Set the fade operation _fadeOperation = FadeOperation.FadeOut; //Start the transition _timer.Enabled = true; e.Cancel = true; } } }
void Update() { if (currentOperation != null) { currentOperation.elapsedTime += Time.deltaTime; Color imgColor = img.color; switch (currentOperation.fadeDirection) { case FadeDirection.FadeIn: imgColor.a = currentOperation.elapsedTime / currentOperation.duration; break; case FadeDirection.FadeOut: imgColor.a = 1 - currentOperation.elapsedTime / currentOperation.duration; break; } img.color = imgColor; if (currentOperation.elapsedTime >= currentOperation.duration) { currentOperation.complete = true; currentOperation = null; } } }
public FadeOperation SetFade(FadeDirection direction, float duration) { currentOperation = new FadeOperation(direction, duration); return(currentOperation); }
public static IEnumerator FadeInOut(FadeOperation _op) { yield return(new WaitForEndOfFrame()); }