| using System; |
| using System; |
| . | |
| using System.Collections.Generic; |
| using UnityEngine; |
| using UnityEngine; |
| . | |
| using UnityEngine.Serialization; |
| |
| |
| . | public class LightFlicker : MonoBehaviour |
| public class LightFlicker : MonoBehaviour, IMonoUpdater |
| { |
| { |
| private void Awake() |
| private void Awake() |
| { |
| { |
| this.m_light = base.GetComponent<Light>(); |
| this.m_light = base.GetComponent<Light>(); |
| this.m_baseIntensity = this.m_light.intensity; |
| this.m_baseIntensity = this.m_light.intensity; |
| this.m_basePosition = base.transform.localPosition; |
| this.m_basePosition = base.transform.localPosition; |
| this.m_flickerOffset = UnityEngine.Random.Range(0f, 10f); |
| this.m_flickerOffset = UnityEngine.Random.Range(0f, 10f); |
| . | |
| if (Settings.ReduceFlashingLights) |
| |
| { |
| |
| this.m_light.intensity = 0f; |
| |
| } |
| } |
| } |
| |
| |
| private void OnEnable() |
| private void OnEnable() |
| { |
| { |
| this.m_time = 0f; |
| this.m_time = 0f; |
| . | if (this.m_light) |
| LightFlicker.Instances.Add(this); |
| { |
| } |
| this.m_light.intensity = 0f; |
| |
| } |
| private void OnDisable() |
| |
| { |
| |
| LightFlicker.Instances.Remove(this); |
| } |
| } |
| |
| |
| . | private void Update() |
| public void CustomUpdate(float deltaTime, float time) |
| { |
| { |
| if (!this.m_light) |
| if (!this.m_light) |
| { |
| { |
| return; |
| return; |
| } |
| } |
| if (Settings.ReduceFlashingLights) |
| if (Settings.ReduceFlashingLights) |
| { |
| { |
| . | if (this.m_flashingLightingsAccessibility == LightFlicker.LightFlashSettings.Off) |
| if (this.m_flashingLightsSetting == LightFlicker.LightFlashSettings.Off) |
| { |
| { |
| this.m_light.intensity = 0f; |
| this.m_light.intensity = 0f; |
| return; |
| return; |
| } |
| } |
| . | if (this.m_flashingLightingsAccessibility == LightFlicker.LightFlashSettings.AlwaysOn) |
| if (this.m_flashingLightsSetting == LightFlicker.LightFlashSettings.AlwaysOn) |
| { |
| { |
| this.m_light.intensity = 1f; |
| this.m_light.intensity = 1f; |
| return; |
| return; |
| } |
| } |
| } |
| } |
| . | this.m_time += Time.deltaTime; |
| this.m_time += deltaTime; |
| float num = this.m_flickerOffset + Time.time * this.m_flickerSpeed; |
| float num = this.m_flickerOffset + Time.time * this.m_flickerSpeed; |
| . | float num2; |
| if (Settings.ReduceFlashingLights && this.m_flashingLightsSetting == LightFlicker.LightFlashSettings.OnIncludeFade) |
| if (Settings.ReduceFlashingLights && this.m_flashingLightingsAccessibility == LightFlicker.LightFlashSettings.OnIncludeFade) |
| |
| { |
| { |
| . | num2 = 1f; |
| this.m_targetIntensity = 1f; |
| } |
| } |
| else |
| else |
| { |
| { |
| . | num2 = 1f + Mathf.Sin(num) * Mathf.Sin(num * 0.56436f) * Mathf.Cos(num * 0.758348f) * this.m_flickerIntensity; |
| this.m_targetIntensity = 1f + Mathf.Sin(num) * Mathf.Sin(num * 0.56436f) * Mathf.Cos(num * 0.758348f) * this.m_flickerIntensity; |
| } |
| } |
| if (this.m_fadeInDuration > 0f) |
| if (this.m_fadeInDuration > 0f) |
| { |
| { |
| . | num2 *= Utils.LerpStep(0f, this.m_fadeInDuration, this.m_time); |
| this.m_targetIntensity *= Utils.LerpStep(0f, this.m_fadeInDuration, this.m_time); |
| } |
| } |
| if (this.m_ttl > 0f) |
| if (this.m_ttl > 0f) |
| { |
| { |
| if (this.m_time > this.m_ttl) |
| if (this.m_time > this.m_ttl) |
| { |
| { |
| UnityEngine.Object.Destroy(base.gameObject); |
| UnityEngine.Object.Destroy(base.gameObject); |
| return; |
| return; |
| } |
| } |
| . | float num3 = this.m_ttl - this.m_fadeDuration; |
| float num2 = this.m_ttl - this.m_fadeDuration; |
| num2 *= 1f - Utils.LerpStep(num3, this.m_ttl, this.m_time); |
| this.m_targetIntensity *= 1f - Utils.LerpStep(num2, this.m_ttl, this.m_time); |
| } |
| } |
| . | this.m_light.intensity = this.m_baseIntensity * num2; |
| if (Settings.ReduceFlashingLights && this.m_flashingLightsSetting == LightFlicker.LightFlashSettings.SmoothedFlicker) |
| |
| { |
| |
| float num3 = ((this.m_time > this.m_ttl - this.m_fadeDuration && this.m_ttl > 0f) ? 0.075f : 0.15f); |
| |
| this.m_smoothedIntensity = Utils.LerpSmooth(this.m_smoothedIntensity, this.m_targetIntensity, deltaTime, num3); |
| |
| } |
| |
| else |
| |
| { |
| |
| this.m_smoothedIntensity = this.m_targetIntensity; |
| |
| } |
| |
| float num4 = (Settings.ReduceFlashingLights ? this.m_accessibilityBrightnessMultiplier : 1f); |
| |
| this.m_light.intensity = this.m_baseIntensity * this.m_smoothedIntensity * num4; |
| Vector3 vector = new Vector3(Mathf.Sin(num) * Mathf.Sin(num * 0.56436f), Mathf.Sin(num * 0.56436f) * Mathf.Sin(num * 0.688742f), Mathf.Cos(num * 0.758348f) * Mathf.Cos(num * 0.4563696f)) * this.m_movement; |
| Vector3 vector = new Vector3(Mathf.Sin(num) * Mathf.Sin(num * 0.56436f), Mathf.Sin(num * 0.56436f) * Mathf.Sin(num * 0.688742f), Mathf.Cos(num * 0.758348f) * Mathf.Cos(num * 0.4563696f)) * this.m_movement; |
| base.transform.localPosition = this.m_basePosition + vector; |
| base.transform.localPosition = this.m_basePosition + vector; |
| } |
| } |
| |
| |
| . | |
| public static List<IMonoUpdater> Instances { get; } = new List<IMonoUpdater>(); |
| |
| |
| public float m_flickerIntensity = 0.1f; |
| public float m_flickerIntensity = 0.1f; |
| |
| |
| public float m_flickerSpeed = 10f; |
| public float m_flickerSpeed = 10f; |
| |
| |
| public float m_movement = 0.1f; |
| public float m_movement = 0.1f; |
| |
| |
| public float m_ttl; |
| public float m_ttl; |
| |
| |
| public float m_fadeDuration = 0.2f; |
| public float m_fadeDuration = 0.2f; |
| |
| |
| public float m_fadeInDuration; |
| public float m_fadeInDuration; |
| |
| |
| . | public LightFlicker.LightFlashSettings m_flashingLightingsAccessibility; |
| [FormerlySerializedAs("m_flashingLightingsAccessibility")] |
| |
| [Header("Accessibility")] |
| |
| public LightFlicker.LightFlashSettings m_flashingLightsSetting; |
| |
| |
| |
| [Range(0f, 1f)] |
| |
| public float m_accessibilityBrightnessMultiplier = 1f; |
| |
| |
| private Light m_light; |
| private Light m_light; |
| |
| |
| private float m_baseIntensity = 1f; |
| private float m_baseIntensity = 1f; |
| |
| |
| private Vector3 m_basePosition = Vector3.zero; |
| private Vector3 m_basePosition = Vector3.zero; |
| |
| |
| private float m_time; |
| private float m_time; |
| |
| |
| private float m_flickerOffset; |
| private float m_flickerOffset; |
| |
| |
| . | |
| private float m_smoothedIntensity; |
| |
| |
| |
| private float m_targetIntensity; |
| |
| |
| public enum LightFlashSettings |
| public enum LightFlashSettings |
| { |
| { |
| . | |
| [InspectorName("Unchanged")] |
| Default, |
| Default, |
| . | |
| [InspectorName("Remove Flicker, Keep Fade")] |
| OnIncludeFade, |
| OnIncludeFade, |
| . | |
| [InspectorName("Disable light")] |
| Off, |
| Off, |
| . | AlwaysOn |
| AlwaysOn, |
| |
| SmoothedFlicker |
| } |
| } |
| } |
| } |
| |
| |