using System.Collections.Generic; using UnityEngine; namespace YAMO.Scripts { [ExecuteAlways] public class LightGroupController : MonoBehaviour { [Tooltip("List of lights to control. If empty and Auto Find is true, will populate from children.")] public List lights = new List(); [Tooltip("Master intensity value. Controls the brightness of all lights directly.")] public float masterIntensity = 1.0f; [Tooltip("If true, automatically finds all Light components in children on Awake and OnValidate.")] public bool autoFindLights = false; private void Awake() { if (autoFindLights) { FindLightsInChildren(); } } private void Update() { // In Edit Mode, we want to update constantly to react to inspector changes // In Play Mode, we also update to support animation UpdateLightIntensities(); } private void OnValidate() { // Called when a value is changed in the inspector if (autoFindLights) { FindLightsInChildren(); } UpdateLightIntensities(); } /// /// Finds all Light components in children and adds them to the list. /// public void FindLightsInChildren() { // Avoid clearing if we just want to ensure we have them, // but for simplicity, let's refresh the list if requested. // We check for nulls or missing items. var childLights = GetComponentsInChildren(); if (lights.Count != childLights.Length) { lights.Clear(); lights.AddRange(childLights); } } /// /// Updates the intensity of all lights to the master intensity. /// public void UpdateLightIntensities() { foreach (var light in lights) { if (light != null) { light.intensity = masterIntensity; } } } } }