Do the thing where the screen fades out on black holes only

This commit is contained in:
xen-42 2025-02-15 01:43:38 -05:00
parent 698e35733a
commit 93a61da2f8
2 changed files with 32 additions and 15 deletions

View File

@ -21,6 +21,7 @@ namespace NewHorizons.Components.Volumes
public override void VanishPlayer(OWRigidbody playerBody, RelativeLocationData entryLocation) public override void VanishPlayer(OWRigidbody playerBody, RelativeLocationData entryLocation)
{ {
Locator.GetPlayerAudioController().PlayOneShotInternal(AudioType.BH_BlackHoleEmission); Locator.GetPlayerAudioController().PlayOneShotInternal(AudioType.BH_BlackHoleEmission);
FadeHandler.FadeOut(0.2f, false);
Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, PlayerState.AtFlightConsole()); Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, PlayerState.AtFlightConsole());
PlayerSpawnHandler.TargetSpawnID = TargetSpawnID; PlayerSpawnHandler.TargetSpawnID = TargetSpawnID;
} }

View File

@ -11,27 +11,43 @@ namespace NewHorizons.Handlers
/// </summary> /// </summary>
public static class FadeHandler 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)); 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; // Make sure its not already faded
float startTime = Time.unscaledTime; if (!LoadManager.s_instance._fadeCanvas.enabled)
float endTime = Time.unscaledTime + length;
while (Time.unscaledTime < endTime)
{ {
var t = Mathf.Clamp01((Time.unscaledTime - startTime) / length); LoadManager.s_instance._fadeCanvas.enabled = true;
LoadManager.s_instance._fadeImage.color = Color.Lerp(Color.clear, Color.black, t); float startTime = Time.unscaledTime;
AudioListener.volume = 1f - t; 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(); yield return new WaitForEndOfFrame();
} }
else
LoadManager.s_instance._fadeImage.color = Color.black; {
AudioListener.volume = 0; yield return new WaitForSeconds(length);
yield return new WaitForEndOfFrame(); }
} }
private static IEnumerator FadeInCoroutine(float length) private static IEnumerator FadeInCoroutine(float length)
@ -58,7 +74,7 @@ namespace NewHorizons.Handlers
private static IEnumerator FadeThenCoroutine(float length, Action action) private static IEnumerator FadeThenCoroutine(float length, Action action)
{ {
yield return FadeOutCoroutine(length); yield return FadeOutCoroutine(length, true);
action?.Invoke(); action?.Invoke();
} }