using HarmonyLib; using System.Collections.Generic; using UnityEngine; namespace MuzikaGromche { [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 with plural GetComponentsInChildren version. [HarmonyPatch(nameof(RoundManager.RefreshLightsList))] [HarmonyPostfix] static void OnRefreshLightsList(RoundManager __instance) { var behaviour = __instance.gameObject.GetComponent() ?? __instance.gameObject.AddComponent(); behaviour.Refresh(); } } internal class PoweredLightsBehaviour : MonoBehaviour { private struct LightData { public Light Light; public Color InitialColor; } private readonly List AllPoweredLights = []; public static PoweredLightsBehaviour Instance { get; private set; } = null!; void Awake() { if (Instance == null) { Instance = this; } } public void Refresh() { AllPoweredLights.Clear(); foreach (var light in RoundManager.Instance.allPoweredLights) { AllPoweredLights.Add(new LightData { Light = light, InitialColor = light.color, }); } } public void SetLightColor(SetLightsColorEvent e) { foreach (var data in AllPoweredLights) { var color = e.GetColor(data.InitialColor); data.Light.color = color; } } public void ResetLightColor() { foreach (var data in AllPoweredLights) { data.Light.color = data.InitialColor; } } } }