using System.Collections.Generic; using UnityEngine; using System.Reflection; namespace MoreMountains.Tools { /// /// A class used to control the intensity of a light /// [AddComponentMenu("More Mountains/Tools/Property Controllers/LightController")] public class LightController : MonoBehaviour { [Header("Binding")] [MMInformation("Use this component to control the properties of one or more lights at runtime. Plays well with a FloatController. " + "This component will try to auto set the TargetLight if there's a Light component on this object.", MoreMountains.Tools.MMInformationAttribute.InformationType.Info, false)] /// the light to control public Light TargetLight; /// the lights to control public List TargetLights; [Header("Light Settings")] /// the new intensity public float Intensity = 1f; /// the multiplier to apply public float Multiplier = 1f; /// the new range public float Range = 1f; [Header("Color")] /// the new color public Color LightColor; /// /// On Start, we initialize our light /// protected virtual void Start() { Initialization(); } /// /// Grabs the light, sets initial range and color /// protected virtual void Initialization() { if (TargetLight == null) { TargetLight = this.gameObject.GetComponent(); } if (TargetLight != null) { TargetLight.range = Range; TargetLight.color = LightColor; } if (TargetLights.Count > 0) { foreach (Light light in TargetLights) { if (light != null) { light.range = Range; light.color = LightColor; } } } } /// /// On Update we apply our light settings /// protected virtual void Update() { ApplyLightSettings(); } /// /// Applys the new intensity, range and color to the light /// protected virtual void ApplyLightSettings() { if (TargetLight != null) { TargetLight.intensity = Intensity * Multiplier; TargetLight.range = Range; TargetLight.color = LightColor; } if (TargetLights.Count > 0) { foreach (Light light in TargetLights) { if (light != null) { light.intensity = Intensity * Multiplier; light.range = Range; light.color = LightColor; } } } } } }