using UnityEngine; [DisallowMultipleComponent] [ExecuteInEditMode] [RequireComponent(typeof(MeshRenderer))] public class AGGlobalWind : MonoBehaviour { public bool EnableGlobalWind = true; private float WindToggle; [Range(0f, 1f)] public float WindTreeAmplitude = 0.2f; [Range(0f, 10f)] public float WindTreeSpeed = 4f; [Range(0f, 3f)] public float WindTreeScale = 0.5f; [Range(0f, 1f)] public float WindTreeStiffness = 0.5f; [Range(0f, 1f)] [Space(20f)] public float WindGrassAmplitude = 0.5f; [Range(0f, 10f)] public float WindGrassSpeed = 4f; [Range(0f, 3f)] public float WindGrassScale = 0.5f; [Range(0f, 1f)] public float WindGrassStiffness = 0.5f; private void Awake() { if (Application.isPlaying) { base.gameObject.GetComponent().enabled = false; } else { base.gameObject.GetComponent().enabled = true; } } private void Update() { if (EnableGlobalWind) { WindToggle = 1f; } else { WindToggle = 0f; } Shader.SetGlobalVector("AGW_WindDirection", base.gameObject.transform.forward); Shader.SetGlobalFloat("AGW_WindToggle", WindToggle); Shader.SetGlobalFloat("AGW_WindAmplitude", WindTreeAmplitude); Shader.SetGlobalFloat("AGW_WindSpeed", WindTreeSpeed); Shader.SetGlobalFloat("AGW_WindScale", WindTreeScale); Shader.SetGlobalFloat("AGW_WindTreeStiffness", WindTreeStiffness); Shader.SetGlobalFloat("AGW_WindGrassAmplitude", WindGrassAmplitude); Shader.SetGlobalFloat("AGW_WindGrassSpeed", WindGrassSpeed); Shader.SetGlobalFloat("AGW_WindGrassScale", WindGrassScale); Shader.SetGlobalFloat("AGW_WindGrassStiffness", WindGrassStiffness); } }