protected override void Awake() { base.Awake(); canvasGroup = GetComponent <CanvasGroup>(); image = GetComponent <Image>(); FadeStarted = new FadeEvent(); FadeEnded = new FadeEvent(); Debug.Log("Awake executed in Edit Mode!"); }
void FadeToDark() { fader.alpha = Mathf.Lerp(fader.alpha, 1f, _fadeTime * Time.deltaTime); if (fader.alpha > 0.98) { if (_fadeInEvent != null) { _fadeInEvent(); _fadeInEvent = null; } fader.alpha = 1f; } }
IEnumerator FadeSequence(FadeEvent e) { float p = 0; Material mat = (e.renderer == null) ? e.sprite.material : e.renderer.material; Color startCol = ((e.useCurrentAsStartCol) ? mat.color : e.startCol); while (p < 1) { p += Time.deltaTime / e.duration; mat.color = Color.Lerp(startCol, e.targetCol, p); yield return(null); } }
private void ResetEvents() { OnFadeEnd = () => { this.Enabled = false; hasFadeStarted = false; ResetEvents(); }; OnFadeStart = () => { hasFadeStarted = true; }; }
void SetupBaseComponents() { canvasGroup = GetComponent <CanvasGroup>(); image = GetComponent <Image>(); if (FadeStarted == null) { FadeStarted = new FadeEvent(); } if (FadeEnded == null) { FadeEnded = new FadeEvent(); } }
void HandleFadeEvent(BaseEvent anEvent) { FadeEvent fadeEvent = (FadeEvent)anEvent; myIsFadingIn = fadeEvent.myShouldFadeIn; myFadeTime = fadeEvent.myFadeTime; if (myIsFadingIn == true) { myFadeDeltaTime = myFadeTime; } else { myFadeDeltaTime = 0; } }
void OnFadeEvent(FadeEvent eventdata) { //print("on"); if (Fading != null) { StopCoroutine(Fading); } FadeColor = eventdata.newColor; FadeTime = eventdata.time; if (!gameObject.activeInHierarchy) { return; } IsFading = true; if (sprite) { Fading = StartCoroutine(FadeToSprite(FadeColor, FadeTime)); } else if (txt) { Fading = StartCoroutine(FadeToText(FadeColor, FadeTime)); } else if (imgurd) { Fading = StartCoroutine(FadeToImage(FadeColor, FadeTime)); } else if (pro) { Fading = StartCoroutine(FadeToTextMeshPro(FadeColor, FadeTime)); } else if (progui) { Fading = StartCoroutine(FadeToTextMeshProUI(FadeColor, FadeTime)); } }
//------------------------------------------------------------------------/ // Procedures: Cross Fade //------------------------------------------------------------------------/ private void SetFade(FadeEvent e) { continueInputEnabled = false; if (e.duration > 0.0f) { Invoke(Continue, e.duration); } else if (e.endOnAction) { this.Log("Continuing next frame (if there's no transitions queued up) ..."); InvokeNextFrame(() => { if (transitions.Empty()) { Continue(); } }); } else { this.Log("Indefinite fade set..."); } }
public void ExitFading(FadeEvent fadeEvent = null) { _toLight = true; _fadeOutEvent = fadeEvent; }
public void BeginFading(FadeEvent fadeEvent = null) { _toLight = false; gameObject.SetActive(true); _fadeInEvent = fadeEvent; }
private void OnCrossFadeEvent(FadeEvent e) { ProcessTransitionEvent(e, () => SetFade(e), null); }
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(); } }
public void FadeIn(float t = 1, bool ignoreTimeScale = false, bool isClickable = false, FadeEvent onEnd = null) { Debug.Log("FadeIn"); StartCoroutine(FadeInCorou(t, ignoreTimeScale, isClickable, onEnd)); }