From 93a61da2f81f2784f9c769ea6304784cc8d83912 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Sat, 15 Feb 2025 01:43:38 -0500 Subject: [PATCH] Do the thing where the screen fades out on black holes only --- .../Components/Volumes/BlackHoleWarpVolume.cs | 1 + NewHorizons/Handlers/FadeHandler.cs | 46 +++++++++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs b/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs index 941bff2b..ba31f97e 100644 --- a/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs +++ b/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs @@ -21,6 +21,7 @@ namespace NewHorizons.Components.Volumes public override void VanishPlayer(OWRigidbody playerBody, RelativeLocationData entryLocation) { Locator.GetPlayerAudioController().PlayOneShotInternal(AudioType.BH_BlackHoleEmission); + FadeHandler.FadeOut(0.2f, false); Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, PlayerState.AtFlightConsole()); PlayerSpawnHandler.TargetSpawnID = TargetSpawnID; } diff --git a/NewHorizons/Handlers/FadeHandler.cs b/NewHorizons/Handlers/FadeHandler.cs index d77184c6..ab2dddc6 100644 --- a/NewHorizons/Handlers/FadeHandler.cs +++ b/NewHorizons/Handlers/FadeHandler.cs @@ -11,27 +11,43 @@ namespace NewHorizons.Handlers /// public static class FadeHandler { - public static void FadeOut(float length) => Delay.StartCoroutine(FadeOutCoroutine(length)); + public static void FadeOut(float length) => Delay.StartCoroutine(FadeOutCoroutine(length, true)); + + public static void FadeOut(float length, bool fadeSound) => Delay.StartCoroutine(FadeOutCoroutine(length, fadeSound)); public static void FadeIn(float length) => Delay.StartCoroutine(FadeInCoroutine(length)); - private static IEnumerator FadeOutCoroutine(float length) + private static IEnumerator FadeOutCoroutine(float length, bool fadeSound) { - LoadManager.s_instance._fadeCanvas.enabled = true; - float startTime = Time.unscaledTime; - float endTime = Time.unscaledTime + length; - - while (Time.unscaledTime < endTime) + // Make sure its not already faded + if (!LoadManager.s_instance._fadeCanvas.enabled) { - var t = Mathf.Clamp01((Time.unscaledTime - startTime) / length); - LoadManager.s_instance._fadeImage.color = Color.Lerp(Color.clear, Color.black, t); - AudioListener.volume = 1f - t; + LoadManager.s_instance._fadeCanvas.enabled = true; + float startTime = Time.unscaledTime; + float endTime = Time.unscaledTime + length; + + while (Time.unscaledTime < endTime) + { + var t = Mathf.Clamp01((Time.unscaledTime - startTime) / length); + LoadManager.s_instance._fadeImage.color = Color.Lerp(Color.clear, Color.black, t); + if (fadeSound) + { + AudioListener.volume = 1f - t; + } + yield return new WaitForEndOfFrame(); + } + + LoadManager.s_instance._fadeImage.color = Color.black; + if (fadeSound) + { + AudioListener.volume = 0; + } yield return new WaitForEndOfFrame(); } - - LoadManager.s_instance._fadeImage.color = Color.black; - AudioListener.volume = 0; - yield return new WaitForEndOfFrame(); + else + { + yield return new WaitForSeconds(length); + } } private static IEnumerator FadeInCoroutine(float length) @@ -58,7 +74,7 @@ namespace NewHorizons.Handlers private static IEnumerator FadeThenCoroutine(float length, Action action) { - yield return FadeOutCoroutine(length); + yield return FadeOutCoroutine(length, true); action?.Invoke(); }