using System; using UnityEngine; public class WeatherOverlay : MonoBehaviour { protected virtual void Awake() { if (this.parentCamera == null) { if (base.transform.parent != null) { this.parentCamera = base.transform.parent.GetComponent(); } if (this.parentCamera == null) { UnityEngine.Debug.LogError("WeatherOverlay: Failed to find parentCamera, please assign it manually"); } } this._cachedRenderer = base.GetComponent(); this._cachedRenderer.sortingOrder = this.sortingOrder; this._cachedRenderer.enabled = false; base.transform.localPosition = new Vector3(0f, 0f, base.transform.localPosition.z); } protected virtual void Update() { float num = this.parentCamera.orthographicSize * 2f; base.transform.localScale = new Vector3(num * this.parentCamera.aspect, num, 1f); } public virtual float Brightness { get { return this._brightness; } set { float num = Mathf.Clamp(value, -1f, 1f); if (this._brightness != num) { this._brightness = num; if (this._brightness > 0f) { this._cachedRenderer.material = this.lightningMaterial; this._cachedRenderer.enabled = true; this.lightningMaterial.color = new Color(1f, 1f, 1f, this._brightness * this.brightnessMult); } else if (this._brightness < 0f) { this._cachedRenderer.material = this.darkMaterial; this._cachedRenderer.enabled = true; this.darkMaterial.color = new Color(0f, 0f, 0f, -this._brightness * this.brightnessMult); } else { this._cachedRenderer.enabled = false; } } } } public Camera parentCamera; public int sortingOrder = 200; public float brightnessMult = 0.2f; public Material darkMaterial; public Material lightningMaterial; private float _brightness; private Renderer _cachedRenderer; }