private IEnumerator CinematicFading(float fadeTime, FadeType type, Cinematic origin) { float time = 0; animFader.gameObject.SetActive(true); animFader.color = type == FadeType.Out ? Color.black : Color.clear; if (type == FadeType.InOut) { fadeTime /= 2; } while (time < fadeTime) { time += Time.deltaTime; animFader.color = type == FadeType.Out ? Color.black * (1 - time / fadeTime) : Color.black * time / fadeTime; if (type == FadeType.InOut && time >= fadeTime) { type = FadeType.Out; time = 0; origin.SendMessage("OnTransition"); } yield return(null); } if (origin != null) { origin.SendMessage("OnComplete"); } }
/// <summary> /// Enables the cinematic fader with options /// </summary> /// <param name="fadeTime">The duration of the fade</param> /// <param name="type">The fade type</param> /// <param name="origin">The origin cinematic to respond</param> public void CinematicFade(float fadeTime, FadeType type, Cinematic origin) { if (type != FadeType.InOut) { origin.SendMessage("OnTransition"); } StartCoroutine(CinematicFading(fadeTime, type, origin)); }