using System; using System.Collections; using SUISS.Core; using UnityEngine; public class CinematicEffect : SingletonMonobehaviour { protected override void Awake() { base.Awake(); this.HideInstant(); } public Coroutine ShowAnimated() { this.StopCurrentRoutine(); return base.StartCoroutine(this._fadeRoutine = this.ShowRoutine()); } public Coroutine HideAnimated() { this.StopCurrentRoutine(); return base.StartCoroutine(this._fadeRoutine = this.HideRoutine()); } public void ShowInstant() { this.StopCurrentRoutine(); this._camera.enabled = true; this._canvasGroup.alpha = 1f; } public void HideInstant() { this.StopCurrentRoutine(); this._camera.enabled = false; this._canvasGroup.alpha = 0f; } private IEnumerator ShowRoutine() { this._camera.enabled = true; this._canvasGroup.alpha = 0f; float time = 0f; while (time < this._fadeDurationInSeconds) { time += Time.deltaTime; this._canvasGroup.alpha = this._fadeCurve.Evaluate(time / this._fadeDurationInSeconds); yield return null; } yield break; } private IEnumerator HideRoutine() { this._canvasGroup.alpha = 1f; float time = this._fadeDurationInSeconds; while (time > 0f) { time -= Time.deltaTime; this._canvasGroup.alpha = this._fadeCurve.Evaluate(time / this._fadeDurationInSeconds); yield return null; } this._camera.enabled = false; yield break; } private void StopCurrentRoutine() { if (this._fadeRoutine != null) { base.StopCoroutine(this._fadeRoutine); } } [SerializeField] private Camera _camera; [SerializeField] private CanvasGroup _canvasGroup; [SerializeField] private AnimationCurve _fadeCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); [SerializeField] private float _fadeDurationInSeconds = 0.7f; private IEnumerator _fadeRoutine; }