IEnumerator FadeInCorou(float t = 1, bool ignoreTimeScale = false, bool isClickable = false, FadeEvent onEnd = null) { Color color = pnl.color; color.a = 1; pnl.color = color; pnl.raycastTarget = !isClickable; pnl.gameObject.SetActive(true); float tt = t; do { yield return(null); float time = ignoreTimeScale ? Time.unscaledDeltaTime : Time.deltaTime; t -= time; color.a -= time / tt; pnl.color = color; } while (t > 0); pnl.gameObject.SetActive(false); if (onEnd != null) { onEnd.Invoke(); } }
/// <summary> /// Method Called by animation event when screen has completely faded to black; /// Triggers FadeOut Event /// </summary> public void HandleFadeOut() { FadeOutCompletedEvent?.Invoke(); if (automatic) { FadeIn(); } }
/// <summary> /// Method Called by animation event when screen has completely faded to black; /// Triggers FadeOut Event /// </summary> public IEnumerator HandleFadeOut() { yield return(new WaitForSeconds(ANIM_LENGTH / speed)); FadeOutCompletedEvent?.Invoke(); if (automatic) { FadeIn(); } }
void FadeOutEnd() { fading = false; Debug.Log("FadeOutEnd"); if (OnFadeOutEnd != null) { OnFadeOutEnd.Invoke(); } }
//Only update if trying to fade protected override void OnUpdate() { var deltaTime = Time.DeltaTime; var fadeObject = UI.FadeObject; if (!hasFadeStarted) { OnFadeStart?.Invoke(); } //Update texture info depending on fade component info Color c = fadeObject.Image.color; c.a = fadeObject.FadeValue; fadeObject.Image.color = c; //Update fade component info switch (fadeObject.Type) { case FadeIn: if (fadeObject.FadeValue <= 0) { OnFadeEnd?.Invoke(); } fadeObject.FadeValue -= fadeObject.Speed * deltaTime; break; case FadeOut: if (fadeObject.FadeValue >= 1) { OnFadeEnd?.Invoke(); } fadeObject.FadeValue += fadeObject.Speed * deltaTime; break; } UI.FadeObject = fadeObject; }
public bool Unfade(float duration) { if (Status != FadeStatus.Faded) { return(false); } TimeElapsed = 0.0f; TotalTime = duration; sourceColor = currentColor; targetColor = Color.clear; currentColor = sourceColor; Status = FadeStatus.Unfading; OnUnfadeStart?.Invoke(); return(true); }
public bool FadeToColor(Color color, float duration) { if (Status != FadeStatus.None) { return(false); } TimeElapsed = 0.0f; TotalTime = duration; sourceColor = Color.clear; targetColor = color; currentColor = sourceColor; Status = FadeStatus.Fading; this.gameObject.SetActive(true); OnFadeStart?.Invoke(); return(true); }
void Update() { if (Status == FadeStatus.None) { this.gameObject.SetActive(false); } else { float nearClip = Camera.main.nearClipPlane; this.transform.localPosition = new Vector3(0.0f, 0.0f, nearClip + nearClip / 100.0f); if (Status == FadeStatus.Fading || Status == FadeStatus.Unfading) { TimeElapsed = Mathf.Min(TimeElapsed + Time.deltaTime, TotalTime); float complete = TimeElapsed / TotalTime; if (TimeElapsed == TotalTime) { if (Status == FadeStatus.Fading) { currentColor = targetColor; Status = FadeStatus.Faded; OnFadeComplete?.Invoke(); } else { currentColor = Color.clear; Status = FadeStatus.None; OnUnfadeComplete?.Invoke(); } } else { currentColor = Color.Lerp(sourceColor, targetColor, complete); fadeImage.color = currentColor; } } } }