1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-09 14:13:31 +08:00

UXAssist: fix Night Light again

This commit is contained in:
2025-04-19 18:38:48 +08:00
parent d867bca1ba
commit 8d7f8e8c8a

View File

@@ -233,7 +233,6 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
private static bool _mechaOnEarth; private static bool _mechaOnEarth;
private static AnimationState _sail; private static AnimationState _sail;
private static Light _sunlight; private static Light _sunlight;
private static StarData _lastStar;
protected override void OnEnable() protected override void OnEnable()
{ {
@@ -247,8 +246,8 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
_sunlight.transform.localEulerAngles = new Vector3(0f, 180f); _sunlight.transform.localEulerAngles = new Vector3(0f, 180f);
_sunlight = null; _sunlight = null;
} }
_lastStar = null;
_sail = null; _sail = null;
_mechaOnEarth = false;
_nightlightInitialized = false; _nightlightInitialized = false;
} }
@@ -259,8 +258,8 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
_sunlight.transform.localEulerAngles = new Vector3(0f, 180f); _sunlight.transform.localEulerAngles = new Vector3(0f, 180f);
_sunlight = null; _sunlight = null;
} }
_lastStar = null;
_sail = null; _sail = null;
_mechaOnEarth = false;
_nightlightInitialized = false; _nightlightInitialized = false;
} }
@@ -271,6 +270,20 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
GameMain.mainPlayer.transform.right * NightLightAngleY.Value / 10f); GameMain.mainPlayer.transform.right * NightLightAngleY.Value / 10f);
} }
[HarmonyPostfix]
[HarmonyPatch(typeof(GameData), nameof(GameData.ArriveStar))]
public static void GameData_ArriveStar_Postfix()
{
_sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GameData), nameof(GameData.LeaveStar))]
public static void GameData_LeaveStar_Prefix()
{
_sunlight = null;
}
[HarmonyPostfix] [HarmonyPostfix]
[HarmonyPatch(typeof(GameMain), nameof(GameMain.LateUpdate))] [HarmonyPatch(typeof(GameMain), nameof(GameMain.LateUpdate))]
public static void GameMain_LateUpdate_Postfix(GameMain __instance) public static void GameMain_LateUpdate_Postfix(GameMain __instance)
@@ -281,33 +294,27 @@ public class FactoryPatch : PatchImpl<FactoryPatch>
{ {
if (!GameMain.mainPlayer.controller.model.gameObject.activeInHierarchy) return; if (!GameMain.mainPlayer.controller.model.gameObject.activeInHierarchy) return;
if (_sail == null) _sail = GameMain.mainPlayer.animator.sails[GameMain.mainPlayer.animator.sailAnimIndex]; if (_sail == null) _sail = GameMain.mainPlayer.animator.sails[GameMain.mainPlayer.animator.sailAnimIndex];
_sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight;
_nightlightInitialized = true; _nightlightInitialized = true;
} }
var sailing = _sail && _sail.enabled; var sailing = _sail && _sail.enabled;
if (_mechaOnEarth) if (_mechaOnEarth)
{ {
if (sailing) if (!sailing)
{ {
_mechaOnEarth = false; UpdateSunlightAngle();
if (!_sunlight) return; return;
_sunlight.transform.localEulerAngles = new Vector3(0f, 180f);
_sunlight = null;
} }
_mechaOnEarth = false;
if (!_sunlight) return;
_sunlight.transform.localEulerAngles = new Vector3(0f, 180f);
_sunlight = null;
return;
} }
else
{ if (sailing) return;
if (sailing) return; _mechaOnEarth = true;
var localStar = GameMain.localStar;
if (!_sunlight || _lastStar != localStar)
{
_sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight;
if (!_sunlight) return;
_lastStar = localStar;
}
_mechaOnEarth = true;
}
UpdateSunlightAngle();
} }
[HarmonyTranspiler] [HarmonyTranspiler]