133 lines
3.1 KiB
C#
133 lines
3.1 KiB
C#
using UnityEngine;
|
|
|
|
public class RainEffectController : MonoBehaviour
|
|
{
|
|
public RainEffect rain;
|
|
|
|
public RainEffect rain2;
|
|
|
|
public ShowerEffect shower;
|
|
|
|
public AudioSource rainAudio;
|
|
|
|
public Texture2D singleRainTexture;
|
|
|
|
public Texture2D multipleRainTexture;
|
|
|
|
private float def_ShowerAlpha;
|
|
|
|
private float def_Intensity;
|
|
|
|
private float def_Size;
|
|
|
|
private float def_IntervalMin;
|
|
|
|
private float def_IntervalMax;
|
|
|
|
private float def_FadeSpeed;
|
|
|
|
private int currentMode;
|
|
|
|
private void Awake()
|
|
{
|
|
def_ShowerAlpha = 0f;
|
|
def_Intensity = 0.6f;
|
|
def_Size = 0.7f;
|
|
def_IntervalMin = 0.6f;
|
|
def_IntervalMax = 1.4f;
|
|
def_FadeSpeed = 0.5f;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Alpha1))
|
|
{
|
|
currentMode = 0;
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.Alpha2))
|
|
{
|
|
currentMode = 1;
|
|
}
|
|
if (Input.GetKeyDown(KeyCode.Alpha3))
|
|
{
|
|
currentMode = 2;
|
|
}
|
|
if (Physics.Raycast(base.transform.position, Vector3.up, 10f))
|
|
{
|
|
InHome();
|
|
}
|
|
else
|
|
{
|
|
OutSide();
|
|
}
|
|
}
|
|
|
|
private void InHome()
|
|
{
|
|
rain.Intensity = Mathf.Lerp(rain.Intensity, 0f, Time.deltaTime * 10f);
|
|
shower.alpha = Mathf.Lerp(shower.alpha, 0f, Time.deltaTime * 5f);
|
|
rainAudio.volume = Mathf.Lerp(rainAudio.volume, 0.2f, Time.deltaTime * 2f);
|
|
rain2.enabled = false;
|
|
}
|
|
|
|
private void OutSide()
|
|
{
|
|
switch (currentMode)
|
|
{
|
|
case 0:
|
|
shower.alpha = def_ShowerAlpha;
|
|
rain.Intensity = def_Intensity * 0.8f;
|
|
rain.Size = def_Size * 1.2f;
|
|
rain.IntervalMin = def_IntervalMin / 1.1f;
|
|
rain.IntervalMax = def_IntervalMax / 1.6f;
|
|
rain.FadeSpeedMin = def_FadeSpeed * 0.8f;
|
|
rain.FadeSpeedMax = def_FadeSpeed * 1.5f;
|
|
rain.NormalMap = singleRainTexture;
|
|
rainAudio.volume = Mathf.Lerp(rainAudio.volume, 0.3f, Time.deltaTime * 4f);
|
|
rain2.enabled = true;
|
|
break;
|
|
case 1:
|
|
shower.alpha = 0.01f;
|
|
rain.Intensity = def_Intensity * 0.6f;
|
|
rain.Size = def_Size * 0.98f;
|
|
rain.IntervalMin = def_IntervalMin / 1.1f;
|
|
rain.IntervalMax = def_IntervalMax / 1.6f;
|
|
rain.FadeSpeedMin = def_FadeSpeed * 0.8f;
|
|
rain.FadeSpeedMax = def_FadeSpeed * 1.5f;
|
|
rain.NormalMap = multipleRainTexture;
|
|
rainAudio.volume = Mathf.Lerp(rainAudio.volume, 0.7f, Time.deltaTime * 4f);
|
|
rain2.enabled = true;
|
|
break;
|
|
case 2:
|
|
shower.alpha = 0.05f;
|
|
rain.Intensity = def_Intensity * 0.5f;
|
|
rain.Size = def_Size * 0.6f;
|
|
rain.IntervalMin = def_IntervalMin / 5f;
|
|
rain.IntervalMax = def_IntervalMax / 5f;
|
|
rain.FadeSpeedMin = def_FadeSpeed * 1.8f;
|
|
rain.FadeSpeedMax = def_FadeSpeed * 2.5f;
|
|
rain.NormalMap = multipleRainTexture;
|
|
rainAudio.volume = Mathf.Lerp(rainAudio.volume, 1f, Time.deltaTime * 4f);
|
|
rain2.enabled = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
Rect clientRect = new Rect(40f, 50f, 320f, 120f);
|
|
clientRect = GUI.Window(0, clientRect, DoMyWindow, "Rain Effect v1.2");
|
|
}
|
|
|
|
private void DoMyWindow(int windowID)
|
|
{
|
|
GUILayout.Label("<size=15>Press 1, 2, 3 Key to change strength of rain</size>");
|
|
GUILayout.Label("<size=15>Or change by this button below</size>");
|
|
if (GUILayout.Button("Change rain strength", GUILayout.Height(30f)))
|
|
{
|
|
currentMode = (currentMode + 1) % 3;
|
|
}
|
|
GUI.DragWindow(new Rect(0f, 0f, 10000f, 10000f));
|
|
}
|
|
}
|