111 lines
2.0 KiB
C#
111 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
[AddComponentMenu("Enviro/Surface Animator Multiple")]
|
|
public class EnviroSurfaceAnimatorMultiple : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public bool isRaining;
|
|
|
|
[HideInInspector]
|
|
public MeshRenderer[] mRenderer;
|
|
|
|
public bool useRipples;
|
|
|
|
public Texture2D[] RippleFrames;
|
|
|
|
public float RippleAnimationSpeed = 30f;
|
|
|
|
public bool useWaveAnimation;
|
|
|
|
public Vector2 waveSpeed;
|
|
|
|
private List<Material> mats = new List<Material>();
|
|
|
|
private float curWaveSpeedx;
|
|
|
|
private float curWaveSpeedy;
|
|
|
|
private float curWetness;
|
|
|
|
private float curSnow;
|
|
|
|
private bool gotcha;
|
|
|
|
public void Start()
|
|
{
|
|
mRenderer = GetComponentsInChildren<MeshRenderer>();
|
|
}
|
|
|
|
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()
|
|
{
|
|
if (!gotcha)
|
|
{
|
|
for (int i = 0; i < mRenderer.Length; i++)
|
|
{
|
|
mats.Add(mRenderer[i].material);
|
|
}
|
|
gotcha = true;
|
|
}
|
|
GetParameters();
|
|
if (useRipples && isRaining)
|
|
{
|
|
int num = (int)(Time.time * RippleAnimationSpeed);
|
|
num %= RippleFrames.Length;
|
|
for (int j = 0; j < mats.Count; j++)
|
|
{
|
|
mats[j].SetTexture("_Ripple", RippleFrames[num]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int k = 0; k < mats.Count; k++)
|
|
{
|
|
mats[k].SetTexture("_Ripple", null);
|
|
}
|
|
}
|
|
for (int l = 0; l < mats.Count; l++)
|
|
{
|
|
mats[l].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 m = 0; m < mats.Count; m++)
|
|
{
|
|
mats[m].SetTextureOffset("_WetNormal", value);
|
|
}
|
|
}
|
|
for (int n = 0; n < mats.Count; n++)
|
|
{
|
|
mats[n].SetFloat("_Raining", curWetness);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int num2 = 0; num2 < mats.Count; num2++)
|
|
{
|
|
mats[num2].SetFloat("_Raining", -0.01f);
|
|
}
|
|
}
|
|
}
|
|
}
|