1
0
Fork 0

Fix multiple Light components per animator

Add them all to the allPoweredLights list,
not just the whatever first one was found.
This commit is contained in:
ivan tkachenko 2025-08-02 01:41:49 +03:00
parent 0eb02698eb
commit 4d84a2d001
3 changed files with 52 additions and 0 deletions

View File

@ -3,6 +3,7 @@
## MuzikaGromche 13.37.9001 ## MuzikaGromche 13.37.9001
- Fixed more missing flickering behaviours for some animators controllers. - Fixed more missing flickering behaviours for some animators controllers.
- Fixed some powered lights not fully turning off or flickering when there are multiple Light components per container.
## MuzikaGromche 13.37.1337 - Photosensitivity Warning Edition ## MuzikaGromche 13.37.1337 - Photosensitivity Warning Edition

View File

@ -543,6 +543,7 @@ namespace MuzikaGromche
harmony.PatchAll(typeof(JesterPatch)); harmony.PatchAll(typeof(JesterPatch));
harmony.PatchAll(typeof(EnemyAIPatch)); harmony.PatchAll(typeof(EnemyAIPatch));
harmony.PatchAll(typeof(PoweredLightsAnimatorsPatch)); harmony.PatchAll(typeof(PoweredLightsAnimatorsPatch));
harmony.PatchAll(typeof(AllPoweredLightsPatch));
} }
else else
{ {

View File

@ -144,4 +144,54 @@ namespace MuzikaGromche
PoweredLightsAnimators.Patch(__instance); PoweredLightsAnimators.Patch(__instance);
} }
} }
[HarmonyPatch(typeof(RoundManager))]
static class AllPoweredLightsPatch
{
// Vanilla method assumes that GameObjects with tag "PoweredLight" only contain a single Light component each.
// This is, however, not true for certains double-light setups, such as:
// - double PointLight (even though one of them is 'Point' another is 'Spot') inside CeilingFanAnimContainer in BedroomTile/BedroomTileB;
// - MineshaftSpotlight when it has not only `Point Light` but also `IndirectLight` in BirthdayRoomTile;
// - (maybe more?)
// In order to fix that, replace singular GetComponentInChildren<Light> with plural GetComponentsInChildren<Light> version.
[HarmonyPatch(nameof(RoundManager.RefreshLightsList))]
[HarmonyPrefix]
private static bool OnRefreshLightsList(RoundManager __instance)
{
RefreshLightsListPatched(__instance);
// Skip the original method
return false;
}
private static void RefreshLightsListPatched(RoundManager self)
{
// Reusable list to reduce allocations
List<Light> lights = [];
self.allPoweredLights.Clear();
self.allPoweredLightsAnimators.Clear();
GameObject[] gameObjects = GameObject.FindGameObjectsWithTag("PoweredLight");
if (gameObjects == null)
{
return;
}
foreach (var gameObject in gameObjects)
{
Animator animator = gameObject.GetComponentInChildren<Animator>();
if (!(animator == null))
{
self.allPoweredLightsAnimators.Add(animator);
// Patched section: Use list instead of singular GetComponentInChildren<Light>
gameObject.GetComponentsInChildren(includeInactive: true, lights);
self.allPoweredLights.AddRange(lights);
}
}
foreach (var animator in self.allPoweredLightsAnimators)
{
animator.SetFloat("flickerSpeed", UnityEngine.Random.Range(0.6f, 1.4f));
}
}
}
} }