private IEnumerator FadeToSolid(FadeCallback _callback = null) { // To store the time we are currently at for the lerp function float currentTime = 0; // Loop until currentTime exceeds fadeTime while (currentTime < fadeTime) { // Add the deltaTime to the currentTime and get the lerp factor currentTime += Time.deltaTime; float factor = Mathf.Clamp01(currentTime / fadeTime); // Update the image colour by the interpolated value of solid and clear image.color = Color.Lerp(faded, solid, factor); // Wait until the next frame yield return(null); } // force the image colour to be the solid colour in case of floating point // check errors image.color = solid; // Run the callback for the fade being completed _callback?.Invoke(); }
public void fade(float _duration, Color _to, float _startWait = 0.0f, float _endWait = 0.0f, FadeCallback _callback = null) { m_fadeDuration = _duration; m_to = _to; m_startWait = _startWait; m_endWait = _endWait; m_callback = _callback; m_startTimer = 0; m_endTimer = 0; m_timer = 0; m_fading = true; }
public void StartGhostFade(bool fadeIn, bool isDialogueAction = false) { FadeCallback callback = BeginGhostFadeLoop; if (isDialogueAction) { callback += Dialogue.Actions.CompletePendingAction; } if (fadeIn) { StartFadeIn(minFade, callback); } else { StartFadeOut(minFade, callback); } }
/// <summary> /// 페이드 한다. /// </summary> /// <param name="from">시작 색상</param> /// <param name="to">끝 색상</param> /// <param name="duration">페이드에 걸리는 시간</param> /// <param name="onComplate">페이드 완료 콜백</param> public void Fade(Color from, Color to, float duration = 1, FadeCallback onComplate = null) { image.DOKill(false); if (canvas.enabled != true) { canvas.enabled = true; } image.color = from; image.DOColor(to, duration).OnComplete(() => { if (onComplate != null) { onComplate(); } if (to.a <= 0) { canvas.enabled = false; } }); color = to; }
IEnumerator Fade(bool fadeIn, float fadeRate, FadeCallback fadeCallback) { Fadable[] children = GetFadableChildren(); Color color = this.color; float alphaPercent = GetAlphaPercent(color.a); while ((fadeIn && alphaPercent < 1f) || (!fadeIn && alphaPercent > 0f)) { float delta = Time.deltaTime / fadeRate; alphaPercent += fadeIn ? delta : -delta; CopyAlphaToChildren(children, alphaPercent); color.a = GetAlphaValue(alphaPercent); this.color = color; yield return(null); } if (fadeCallback != null) { fadeCallback(); } }
/// <summary> /// 투명에서 검은색으로 페이드아웃 된다. /// </summary> public static void FadeOut(float duration = 1, FadeCallback onComplate = null) { instance.Fade(Color.clear, Color.black, duration, onComplate); }
/// <summary> /// 투명으로 페이드인 된다. /// </summary> public static void FadeIn(float duration = 1, FadeCallback onComplate = null) { instance.Fade(instance.color, Color.clear, duration, onComplate); }
protected virtual Coroutine StartFade(float startAlpha, bool fadeIn, float fadeRate, FadeCallback fadeCallback, bool interruptCoroutines) { if (interruptCoroutines) { StopFade(); } Color color = this.color; color.a = Mathf.Min(startAlpha, maxAlpha); this.color = color; return(StartCoroutine(Fade(fadeIn, fadeRate, fadeCallback))); }
public virtual Coroutine StartFadeOut(float fadeRate = DEFAULT_FADE_RATE, FadeCallback fadeCallback = null, bool interruptCoroutines = true) { return(StartFade(1f, false, fadeRate, fadeCallback, interruptCoroutines)); }
public void FadeDown(FadeCallback _callback = null) { StartCoroutine(FadeToSolid(_callback)); }