1
0
Fork 0

[v80] Use vanilla RefreshLightsList

Vanilla v80 changed three things about this patch:
- allPoweredLightsAnimators list became nullable, breaking the patch.
- implemented looking up the List<> of children, rendering the patch
  obsolete.
- added new logic for objects tagged with "IndirectLightSource", making
  the patch incomplete.

All in all, the patch is not needed anymore.
This commit is contained in:
ivan tkachenko 2026-04-01 06:04:37 +03:00
parent 7fb63e4718
commit f55e2e8436
1 changed files with 2 additions and 38 deletions

View File

@ -14,47 +14,11 @@ namespace MuzikaGromche
// - (maybe more?) // - (maybe more?)
// In order to fix that, replace singular GetComponentInChildren<Light> with plural GetComponentsInChildren<Light> version. // In order to fix that, replace singular GetComponentInChildren<Light> with plural GetComponentsInChildren<Light> version.
[HarmonyPatch(nameof(RoundManager.RefreshLightsList))] [HarmonyPatch(nameof(RoundManager.RefreshLightsList))]
[HarmonyPrefix] [HarmonyPostfix]
static bool OnRefreshLightsList(RoundManager __instance) static void OnRefreshLightsList(RoundManager __instance)
{ {
RefreshLightsListPatched(__instance);
var behaviour = __instance.gameObject.GetComponent<PoweredLightsBehaviour>() ?? __instance.gameObject.AddComponent<PoweredLightsBehaviour>(); var behaviour = __instance.gameObject.GetComponent<PoweredLightsBehaviour>() ?? __instance.gameObject.AddComponent<PoweredLightsBehaviour>();
behaviour.Refresh(); behaviour.Refresh();
// Skip the original method
return false;
}
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));
}
} }
} }