335 lines
11 KiB
C#
335 lines
11 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
public class WeatherRandomizerSKYMASTER : MonoBehaviour
|
|
{
|
|
private SkyMasterManager skyManager;
|
|
|
|
private WaterHandlerSM waterManager;
|
|
|
|
public bool enableGUI;
|
|
|
|
public bool affectWater;
|
|
|
|
public bool affectFog;
|
|
|
|
public bool affectFogParams;
|
|
|
|
public FullVolumeCloudsSkyMaster volumeClouds;
|
|
|
|
public CloudScript volumeClouds2SCRIPT;
|
|
|
|
public WeatherScript WeatherPatternSCRIPT;
|
|
|
|
public CloudScript volumeClouds2SCRIPT_REFL;
|
|
|
|
public bool tempBased;
|
|
|
|
public float humidity = 30f;
|
|
|
|
public float temperature = 18f;
|
|
|
|
public float HighHumidity = 55f;
|
|
|
|
public float highTemperature = 10f;
|
|
|
|
public bool changedWeather;
|
|
|
|
public float changedWeatherTime;
|
|
|
|
public float weatherChangeDelay = 14f;
|
|
|
|
private float change_time;
|
|
|
|
public float changeWeatherInterval = 300f;
|
|
|
|
public string currentWeather;
|
|
|
|
public float cloudDensityChangeSpeed = 1f;
|
|
|
|
private int weatherChoice = -1;
|
|
|
|
private float prevFresnelBias;
|
|
|
|
private float prevShoreBlendOffset;
|
|
|
|
private void Start()
|
|
{
|
|
skyManager = GetComponent<SkyMasterManager>();
|
|
if (skyManager.water != null)
|
|
{
|
|
waterManager = skyManager.water.GetComponent<WaterHandlerSM>();
|
|
prevFresnelBias = waterManager.FresnelBias;
|
|
prevShoreBlendOffset = waterManager.ShoreBlendOffset;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Time.fixedTime - change_time > changeWeatherInterval)
|
|
{
|
|
weatherChoice = Random.Range(0, 8);
|
|
change_time = Time.fixedTime;
|
|
}
|
|
float num = 0.1f;
|
|
if (affectWater && waterManager != null)
|
|
{
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm)
|
|
{
|
|
waterManager.waterScaleOffset.y = Mathf.Lerp(waterManager.waterScaleOffset.y, 3.5f, num * Time.deltaTime);
|
|
}
|
|
else
|
|
{
|
|
waterManager.waterScaleOffset.y = Mathf.Lerp(waterManager.waterScaleOffset.y, 0f, num * Time.deltaTime);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.SnowStorm)
|
|
{
|
|
waterManager.FresnelBias = Mathf.Lerp(waterManager.FresnelBias, -67f, num * Time.deltaTime);
|
|
if (waterManager.FresnelBias < -64f)
|
|
{
|
|
waterManager.ReflectColor = Color.Lerp(waterManager.ReflectColor, new Color(31f / 51f, 44f / 51f, 44f / 51f), num * Time.deltaTime);
|
|
waterManager.UseSkyGradient = false;
|
|
}
|
|
waterManager.ShoreBlendOffset = Mathf.Lerp(waterManager.ShoreBlendOffset, 0.1f, num * Time.deltaTime);
|
|
}
|
|
else
|
|
{
|
|
waterManager.FresnelBias = Mathf.Lerp(waterManager.FresnelBias, prevFresnelBias, num * Time.deltaTime);
|
|
waterManager.UseSkyGradient = true;
|
|
waterManager.ShoreBlendOffset = Mathf.Lerp(waterManager.ShoreBlendOffset, prevShoreBlendOffset, num * Time.deltaTime);
|
|
}
|
|
}
|
|
if (affectFog)
|
|
{
|
|
SeasonalTerrainSKYMASTER seasonalTerrainSKYMASTER = skyManager.Terrain_controller;
|
|
if (seasonalTerrainSKYMASTER == null)
|
|
{
|
|
seasonalTerrainSKYMASTER = skyManager.Mesh_Terrain_controller;
|
|
}
|
|
if (seasonalTerrainSKYMASTER != null)
|
|
{
|
|
seasonalTerrainSKYMASTER.UseFogCurves = true;
|
|
seasonalTerrainSKYMASTER.SkyFogOn = true;
|
|
seasonalTerrainSKYMASTER.HeightFogOn = true;
|
|
if (affectFogParams)
|
|
{
|
|
seasonalTerrainSKYMASTER.fogGradientDistance = 0f;
|
|
seasonalTerrainSKYMASTER.VFogDistance = 12f;
|
|
}
|
|
if (weatherChoice == 0)
|
|
{
|
|
seasonalTerrainSKYMASTER.fogDensity = Mathf.Lerp(seasonalTerrainSKYMASTER.fogDensity, 0.1f, num * Time.deltaTime);
|
|
seasonalTerrainSKYMASTER.AddFogHeightOffset = Mathf.Lerp(seasonalTerrainSKYMASTER.AddFogHeightOffset, 700f, num * Time.deltaTime);
|
|
}
|
|
if (weatherChoice == 1 || weatherChoice == 5)
|
|
{
|
|
seasonalTerrainSKYMASTER.fogDensity = Mathf.Lerp(seasonalTerrainSKYMASTER.fogDensity, 0.5f, num * Time.deltaTime);
|
|
seasonalTerrainSKYMASTER.AddFogHeightOffset = Mathf.Lerp(seasonalTerrainSKYMASTER.AddFogHeightOffset, 700f, num * Time.deltaTime);
|
|
}
|
|
if (weatherChoice == 2 || weatherChoice == 3 || weatherChoice == 4 || weatherChoice == 6)
|
|
{
|
|
seasonalTerrainSKYMASTER.fogDensity = Mathf.Lerp(seasonalTerrainSKYMASTER.fogDensity, 2f, num * Time.deltaTime);
|
|
seasonalTerrainSKYMASTER.AddFogHeightOffset = Mathf.Lerp(seasonalTerrainSKYMASTER.AddFogHeightOffset, 700f, num * Time.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
float num2 = 0.05f * cloudDensityChangeSpeed * Time.deltaTime;
|
|
if (!tempBased)
|
|
{
|
|
if (weatherChoice == 0)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Cloudy;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.85f, num2);
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 3f, num2);
|
|
}
|
|
skyManager.WeatherSeverity = 0f;
|
|
currentWeather = "Sunny";
|
|
}
|
|
if (weatherChoice == 1)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Rain;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.25f, num2 * 2f);
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 14f, num2);
|
|
}
|
|
skyManager.WeatherSeverity = 4f;
|
|
currentWeather = "Rain";
|
|
}
|
|
if (weatherChoice == 2)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Rain;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.2f, num2 * 4.5f);
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 20f, num2);
|
|
}
|
|
skyManager.WeatherSeverity = 10f;
|
|
currentWeather = "Heavy Rain";
|
|
}
|
|
if (weatherChoice == 3)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.HeavyStorm;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.15f, num2 * 5f);
|
|
skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.17f, num2 * 5f);
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 20f, num2);
|
|
}
|
|
skyManager.WeatherSeverity = 4f;
|
|
currentWeather = "Storm";
|
|
}
|
|
if (weatherChoice == 4)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.HeavyStorm;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.1f, num2 * 5f);
|
|
skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.1f, num2 * 5f);
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 20f, num2);
|
|
}
|
|
skyManager.WeatherSeverity = 10f;
|
|
currentWeather = "Heavy Storm";
|
|
}
|
|
if (weatherChoice == 5)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.SnowStorm;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.25f, num2 * 2f);
|
|
skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.25f, num2 * 2f);
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 17f, num2);
|
|
}
|
|
skyManager.WeatherSeverity = 2f;
|
|
currentWeather = "Snow Storm";
|
|
}
|
|
if (weatherChoice == 6)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.SnowStorm;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.15f, num2);
|
|
skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.15f, num2);
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 19f, num2);
|
|
}
|
|
skyManager.WeatherSeverity = 10f;
|
|
currentWeather = "Heavy Snow Storm";
|
|
}
|
|
if (weatherChoice == 7)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.LightningStorm;
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.ClearDayCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.15f, num2);
|
|
skyManager.VolShaderCloudsH.StormCoverage = Mathf.Lerp(skyManager.VolShaderCloudsH.ClearDayCoverage, -0.15f, num2);
|
|
skyManager.VolShaderCloudsH.EnableLightning = true;
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 20f, num2);
|
|
volumeClouds.EnableLightning = true;
|
|
}
|
|
skyManager.WeatherSeverity = 10f;
|
|
currentWeather = "Lightning Storm";
|
|
}
|
|
else
|
|
{
|
|
if (skyManager.VolShaderCloudsH != null)
|
|
{
|
|
skyManager.VolShaderCloudsH.EnableLightning = false;
|
|
}
|
|
if (volumeClouds != null)
|
|
{
|
|
volumeClouds.EnableLightning = false;
|
|
}
|
|
}
|
|
}
|
|
if (!tempBased)
|
|
{
|
|
return;
|
|
}
|
|
humidity = Random.Range(0, 100);
|
|
temperature = Random.Range(-20, 50);
|
|
bool flag = false;
|
|
if (changedWeather && Time.fixedTime - changedWeatherTime > weatherChangeDelay)
|
|
{
|
|
changedWeather = false;
|
|
}
|
|
if (true)
|
|
{
|
|
volumeClouds2SCRIPT.scale = 0.14f;
|
|
volumeClouds2SCRIPT.coverage = 0.55f + humidity * 0.008f;
|
|
volumeClouds2SCRIPT.coverageHigh = 0f;
|
|
if (temperature < highTemperature)
|
|
{
|
|
if (!changedWeather && skyManager.currentWeatherName != SkyMasterManager.Volume_Weather_types.Rain)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Rain;
|
|
changedWeather = true;
|
|
changedWeatherTime = Time.fixedTime;
|
|
Debug.Log("Changing weather to Heavy or Light Rain");
|
|
}
|
|
skyManager.WeatherSeverity = humidity - HighHumidity;
|
|
}
|
|
else
|
|
{
|
|
if (!changedWeather && skyManager.currentWeatherName != SkyMasterManager.Volume_Weather_types.Cloudy)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Cloudy;
|
|
changedWeather = true;
|
|
changedWeatherTime = Time.fixedTime;
|
|
Debug.Log("Changing weather to Cloudy");
|
|
}
|
|
skyManager.WeatherSeverity = 0f;
|
|
}
|
|
}
|
|
if (flag)
|
|
{
|
|
volumeClouds2SCRIPT.coverage = 0f;
|
|
volumeClouds2SCRIPT.coverageHigh = 3f * (humidity / 100f);
|
|
volumeClouds2SCRIPT.highCloudsScale = 0.008f;
|
|
if (!changedWeather && skyManager.currentWeatherName != SkyMasterManager.Volume_Weather_types.Cloudy)
|
|
{
|
|
skyManager.currentWeatherName = SkyMasterManager.Volume_Weather_types.Cloudy;
|
|
changedWeather = true;
|
|
changedWeatherTime = Time.fixedTime;
|
|
Debug.Log("Changing weather to Cloudy");
|
|
}
|
|
skyManager.WeatherSeverity = 0f;
|
|
}
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
if (enableGUI && currentWeather != "")
|
|
{
|
|
GUI.TextField(new Rect(520f, 195f, 360f, 22f), "Random Weather = " + currentWeather + " ,Time to Next:" + (changeWeatherInterval - (Time.fixedTime - change_time)).ToString("F1"));
|
|
}
|
|
}
|
|
}
|
|
}
|