[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:
parent
7fb63e4718
commit
f55e2e8436
|
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue