using UnityEngine; [AddComponentMenu("Enviro/Surface Animator")] public class EnviroSurfaceAnimator : MonoBehaviour { [HideInInspector] public bool isRaining; public MeshRenderer mRenderer; public bool useRipples; public Texture2D[] RippleFrames; public float RippleAnimationSpeed = 30f; public bool useWaveAnimation; public Vector2 waveSpeed; private Material[] mats; private float curWaveSpeedx; private float curWaveSpeedy; private float curWetness; private float curSnow; public void Start() { if (mRenderer == null) { mRenderer.GetComponentInChildren(); } mats = mRenderer.materials; } private void GetParameters() { curWetness = EnviroSky.instance.Weather.wetness; curSnow = EnviroSky.instance.Weather.SnowStrenght; if (curWetness <= 0.1f) { isRaining = false; } else { isRaining = true; } } public void Update() { mats = mRenderer.materials; GetParameters(); if (useRipples && isRaining) { int num = (int)(Time.time * RippleAnimationSpeed); num %= RippleFrames.Length; for (int i = 0; i < mats.Length; i++) { mats[i].SetTexture("_Ripple", RippleFrames[num]); } } else { for (int j = 0; j < mats.Length; j++) { mats[j].SetTexture("_Ripple", null); } } for (int k = 0; k < mats.Length; k++) { mats[k].SetFloat("_SnowStrenght", curSnow); } if (isRaining) { if (useWaveAnimation) { Vector2 value = default(Vector2); value.x = Time.time * waveSpeed.x; value.y = Time.time * waveSpeed.y; for (int l = 0; l < mats.Length; l++) { mats[l].SetTextureOffset("_WetNormal", value); } } for (int m = 0; m < mats.Length; m++) { mats[m].SetFloat("_Raining", curWetness); } } else { for (int n = 0; n < mats.Length; n++) { mats[n].SetFloat("_Raining", -0.01f); } } } }