522 lines
15 KiB
C#
522 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
[Serializable]
|
|
public class WeatherSM
|
|
{
|
|
public enum Volume_Weather_State
|
|
{
|
|
Init = 0,
|
|
FadeIn = 1,
|
|
Steady = 2,
|
|
FadeOut = 3
|
|
}
|
|
|
|
public SkyMasterManager SkyManager;
|
|
|
|
public Volume_Weather_State currentState;
|
|
|
|
public int Season;
|
|
|
|
public bool FadedOut;
|
|
|
|
public bool FadingOut;
|
|
|
|
public float StartTime;
|
|
|
|
public float FadeInTime = 10f;
|
|
|
|
public int seed;
|
|
|
|
public float FadeOutTime = 10f;
|
|
|
|
public float state_start_time;
|
|
|
|
public Material CloudDomeL1Mat;
|
|
|
|
public Material CloudDomeL2Mat;
|
|
|
|
public Material SnowMat;
|
|
|
|
public Material SnowMatTerrain;
|
|
|
|
public WindZoneMode windMode;
|
|
|
|
public List<Transform> SnowParticle = new List<Transform>();
|
|
|
|
public List<ParticleSystem[]> SnowParticleP = new List<ParticleSystem[]>();
|
|
|
|
public List<Transform> RainParticle = new List<Transform>();
|
|
|
|
public List<ParticleSystem[]> RainParticleP = new List<ParticleSystem[]>();
|
|
|
|
public List<Transform> RefractRainParticle = new List<Transform>();
|
|
|
|
public List<ParticleSystem[]> RefractRainParticleP = new List<ParticleSystem[]>();
|
|
|
|
public List<int> RainParticleRate = new List<int>();
|
|
|
|
public List<int> RainParticleMax = new List<int>();
|
|
|
|
public List<bool> RainParticleReset = new List<bool>();
|
|
|
|
public List<float> RainTransp = new List<float>();
|
|
|
|
public List<int> SnowParticleRate = new List<int>();
|
|
|
|
public List<int> SnowParticleMax = new List<int>();
|
|
|
|
public List<bool> SnowParticleReset = new List<bool>();
|
|
|
|
public List<float> SnowTransp = new List<float>();
|
|
|
|
public List<Transform> ParticleClouds = new List<Transform>();
|
|
|
|
public List<ParticleSystem[]> ParticlesCloudsP = new List<ParticleSystem[]>();
|
|
|
|
public List<int> CloudParticleRate = new List<int>();
|
|
|
|
public List<int> CloudParticleMax = new List<int>();
|
|
|
|
public List<bool> CloudParticleReset = new List<bool>();
|
|
|
|
public List<float> CloudTranspMax = new List<float>();
|
|
|
|
public GameObject VolumeCloud;
|
|
|
|
public VolumeClouds_SM VolumeScript;
|
|
|
|
public bool Snow;
|
|
|
|
public string SnowCoverageVariable;
|
|
|
|
public bool Rain;
|
|
|
|
public bool Refractive_Rain;
|
|
|
|
public bool Volume_Rain;
|
|
|
|
public bool has_fog;
|
|
|
|
public bool has_volume_fog;
|
|
|
|
public int volume_fog_peset;
|
|
|
|
public float prevSeverity;
|
|
|
|
public void Update()
|
|
{
|
|
if (!(SkyManager != null))
|
|
{
|
|
return;
|
|
}
|
|
if (currentState == Volume_Weather_State.Init)
|
|
{
|
|
prevSeverity = SkyManager.WeatherSeverity;
|
|
if (VolumeCloud != null)
|
|
{
|
|
VolumeCloud.SetActive(value: true);
|
|
VolumeScript = VolumeCloud.GetComponentsInChildren<VolumeClouds_SM>(includeInactive: true)[0];
|
|
VolumeScript.SmoothIn = true;
|
|
VolumeScript.FadeOutOnBoundary = true;
|
|
VolumeScript.destroy_on_end = true;
|
|
VolumeScript.clone_on_end = true;
|
|
if (SkyManager.windZone != null)
|
|
{
|
|
VolumeScript.Wind_holder = SkyManager.windZone.gameObject;
|
|
VolumeScript.wind = SkyManager.windZone.transform.forward * SkyManager.windZone.windMain * SkyManager.AmplifyWind;
|
|
}
|
|
}
|
|
currentState = Volume_Weather_State.FadeIn;
|
|
state_start_time = Time.fixedTime;
|
|
}
|
|
else if (SkyManager.windZone != null && VolumeScript != null)
|
|
{
|
|
VolumeScript.wind = SkyManager.windZone.transform.forward * SkyManager.windZone.windMain * SkyManager.AmplifyWind;
|
|
}
|
|
if (currentState == Volume_Weather_State.FadeIn)
|
|
{
|
|
for (int i = 0; i < ParticleClouds.Count; i++)
|
|
{
|
|
Make_Particles_Appear(ParticleClouds[i].gameObject, ParticlesCloudsP[i], null, CloudParticleMax[i], CloudParticleReset[i], CloudParticleRate[i], CloudTranspMax[i]);
|
|
}
|
|
if (Snow)
|
|
{
|
|
for (int j = 0; j < SnowParticle.Count; j++)
|
|
{
|
|
Make_Particles_Appear(SnowParticle[j].gameObject, SnowParticleP[j], null, (int)((float)SkyManager.Snow_max_part * SkyManager.WeatherSeverity / 10f), reset_pcount: true, 10, 1f);
|
|
}
|
|
if (SkyManager.SnowCoverage < SkyManager.MaxSnowCoverage)
|
|
{
|
|
SkyManager.SnowCoverage += SkyManager.SnowCoverageRate * Time.deltaTime;
|
|
Shader.SetGlobalFloat(SnowCoverageVariable, SkyManager.SnowCoverage);
|
|
}
|
|
if (SkyManager.SnowCoverageTerrain < SkyManager.MaxSnowCoverage)
|
|
{
|
|
SkyManager.SnowCoverageTerrain += SkyManager.SnowTerrainRate * Time.deltaTime * SkyManager.SnowTerrRateFactor;
|
|
if (SnowMatTerrain != null)
|
|
{
|
|
SnowMatTerrain.SetFloat(SnowCoverageVariable, SkyManager.SnowCoverageTerrain / SkyManager.divideSnowTerrain);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int k = 0; k < SnowParticle.Count; k++)
|
|
{
|
|
Make_Particles_Dissappear(SnowParticle[k].gameObject, SnowParticleP[k], null, 20, 10, pull_downward: false, on_lowest: true);
|
|
}
|
|
if (SkyManager.SnowCoverage > 0f)
|
|
{
|
|
SkyManager.SnowCoverage -= SkyManager.SnowCoverageRate * Time.deltaTime;
|
|
Shader.SetGlobalFloat(SnowCoverageVariable, SkyManager.SnowCoverage);
|
|
}
|
|
if (SkyManager.SnowCoverageTerrain > 0f)
|
|
{
|
|
SkyManager.SnowCoverageTerrain -= SkyManager.SnowTerrainRate * Time.deltaTime * SkyManager.SnowTerrRateFactor;
|
|
if (SnowMatTerrain != null)
|
|
{
|
|
SnowMatTerrain.SetFloat(SnowCoverageVariable, SkyManager.SnowCoverageTerrain / SkyManager.divideSnowTerrain);
|
|
}
|
|
}
|
|
}
|
|
if (Rain)
|
|
{
|
|
if (Refractive_Rain)
|
|
{
|
|
for (int l = 0; l < RefractRainParticle.Count; l++)
|
|
{
|
|
if (l < RefractRainParticleP.Count)
|
|
{
|
|
Make_Particles_Appear(RefractRainParticle[l].gameObject, RefractRainParticleP[l], null, (int)((float)SkyManager.Refract_Rain_max_part * SkyManager.WeatherSeverity / 10f), reset_pcount: true, 12, 1f);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int m = 0; m < RainParticle.Count; m++)
|
|
{
|
|
if (m < RainParticleP.Count)
|
|
{
|
|
Make_Particles_Appear(RainParticle[m].gameObject, RainParticleP[m], null, (int)((float)SkyManager.Refract_Rain_max_part * SkyManager.WeatherSeverity / 10f), reset_pcount: true, 10, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int n = 0; n < RefractRainParticle.Count; n++)
|
|
{
|
|
if (n < RefractRainParticleP.Count)
|
|
{
|
|
Make_Particles_Dissappear(RefractRainParticle[n].gameObject, RefractRainParticleP[n], null, 20, 10, pull_downward: false, on_lowest: true);
|
|
}
|
|
}
|
|
for (int num = 0; num < RainParticle.Count; num++)
|
|
{
|
|
if (num < RainParticleP.Count)
|
|
{
|
|
Make_Particles_Dissappear(RainParticle[num].gameObject, RainParticleP[num], null, 20, 10, pull_downward: false, on_lowest: true);
|
|
}
|
|
}
|
|
}
|
|
if (FadeInTime != 0f && Time.fixedTime - state_start_time > FadeInTime)
|
|
{
|
|
currentState = Volume_Weather_State.Steady;
|
|
state_start_time = Time.fixedTime;
|
|
FadedOut = false;
|
|
}
|
|
}
|
|
if (currentState == Volume_Weather_State.FadeOut)
|
|
{
|
|
if (VolumeScript != null)
|
|
{
|
|
VolumeScript.FadeOutOnBoundary = true;
|
|
VolumeScript.DestroyOnfadeOut = true;
|
|
VolumeScript.SmoothIn = false;
|
|
VolumeScript.SmoothOut = true;
|
|
}
|
|
if (Rain)
|
|
{
|
|
for (int num2 = 0; num2 < RefractRainParticle.Count; num2++)
|
|
{
|
|
if (num2 < RefractRainParticleP.Count)
|
|
{
|
|
Make_Particles_Dissappear(RefractRainParticle[num2].gameObject, RefractRainParticleP[num2], null, 20, 10, pull_downward: false, on_lowest: true);
|
|
}
|
|
}
|
|
for (int num3 = 0; num3 < RainParticle.Count; num3++)
|
|
{
|
|
if (num3 < RainParticleP.Count)
|
|
{
|
|
Make_Particles_Dissappear(RainParticle[num3].gameObject, RainParticleP[num3], null, 20, 10, pull_downward: false, on_lowest: true);
|
|
}
|
|
}
|
|
}
|
|
if (Snow)
|
|
{
|
|
for (int num4 = 0; num4 < SnowParticle.Count; num4++)
|
|
{
|
|
Make_Particles_Dissappear(SnowParticle[num4].gameObject, SnowParticleP[num4], null, 20, 10, pull_downward: false, on_lowest: true);
|
|
}
|
|
}
|
|
if (FadeOutTime != 0f && Time.fixedTime - state_start_time > FadeOutTime)
|
|
{
|
|
FadedOut = true;
|
|
currentState = Volume_Weather_State.Steady;
|
|
state_start_time = Time.fixedTime;
|
|
}
|
|
}
|
|
if (currentState != Volume_Weather_State.Steady)
|
|
{
|
|
return;
|
|
}
|
|
state_start_time = Time.fixedTime;
|
|
if (FadedOut)
|
|
{
|
|
return;
|
|
}
|
|
if (SkyManager.WeatherSeverity != prevSeverity)
|
|
{
|
|
if (Rain)
|
|
{
|
|
if (Refractive_Rain)
|
|
{
|
|
for (int num5 = 0; num5 < RefractRainParticle.Count; num5++)
|
|
{
|
|
if (num5 < RefractRainParticleP.Count)
|
|
{
|
|
for (int num6 = 0; num6 < RefractRainParticleP[num5].Length; num6++)
|
|
{
|
|
ParticleSystem.MainModule main = RefractRainParticleP[num5][num6].main;
|
|
main.maxParticles = (int)((float)SkyManager.Refract_Rain_max_part * SkyManager.WeatherSeverity / 10f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int num7 = 0; num7 < RainParticle.Count; num7++)
|
|
{
|
|
if (num7 < RainParticleP.Count)
|
|
{
|
|
for (int num8 = 0; num8 < RainParticleP[num7].Length; num8++)
|
|
{
|
|
ParticleSystem.MainModule main2 = RainParticleP[num7][num8].main;
|
|
main2.maxParticles = (int)((float)SkyManager.Refract_Rain_max_part * SkyManager.WeatherSeverity / 10f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
prevSeverity = SkyManager.WeatherSeverity;
|
|
}
|
|
if (Snow)
|
|
{
|
|
if (SkyManager.SnowCoverage < SkyManager.MaxSnowCoverage)
|
|
{
|
|
SkyManager.SnowCoverage += SkyManager.SnowCoverageRate * Time.deltaTime;
|
|
Shader.SetGlobalFloat(SnowCoverageVariable, SkyManager.SnowCoverage);
|
|
}
|
|
if (SkyManager.SnowCoverageTerrain < SkyManager.MaxSnowCoverage)
|
|
{
|
|
SkyManager.SnowCoverageTerrain += SkyManager.SnowTerrainRate * Time.deltaTime * SkyManager.SnowTerrRateFactor;
|
|
if (SnowMatTerrain != null)
|
|
{
|
|
SnowMatTerrain.SetFloat(SnowCoverageVariable, SkyManager.SnowCoverageTerrain / SkyManager.divideSnowTerrain);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (SkyManager.SnowCoverage > 0f)
|
|
{
|
|
SkyManager.SnowCoverage -= SkyManager.SnowCoverageRate * Time.deltaTime;
|
|
Shader.SetGlobalFloat(SnowCoverageVariable, SkyManager.SnowCoverage);
|
|
}
|
|
if (SkyManager.SnowCoverageTerrain > 0f)
|
|
{
|
|
SkyManager.SnowCoverageTerrain -= SkyManager.SnowTerrainRate * Time.deltaTime * SkyManager.SnowTerrRateFactor;
|
|
if (SnowMatTerrain != null)
|
|
{
|
|
SnowMatTerrain.SetFloat(SnowCoverageVariable, SkyManager.SnowCoverageTerrain / SkyManager.divideSnowTerrain);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Make_Fog_Dissappear(float speed)
|
|
{
|
|
if (RenderSettings.fog)
|
|
{
|
|
RenderSettings.fogDensity = Mathf.Lerp(RenderSettings.fogDensity, 0f, speed * Time.deltaTime);
|
|
}
|
|
}
|
|
|
|
private void Make_Fog_Appear(Color Fog_Color, float density, FogMode mode, float speed, int Season)
|
|
{
|
|
float num = 255f;
|
|
if (true)
|
|
{
|
|
if (!RenderSettings.fog)
|
|
{
|
|
RenderSettings.fog = true;
|
|
RenderSettings.fogDensity = 0f;
|
|
}
|
|
if (Season != 0 && Season == 3)
|
|
{
|
|
Fog_Color = new Color(100f / num, 80f / num, 100f / num, 255f / num);
|
|
density = 0.01f;
|
|
mode = FogMode.ExponentialSquared;
|
|
}
|
|
Color b = Fog_Color;
|
|
RenderSettings.fogColor = Color.Lerp(RenderSettings.fogColor, b, speed * Time.deltaTime);
|
|
RenderSettings.fogDensity = Mathf.Lerp(RenderSettings.fogDensity, density, speed * Time.deltaTime);
|
|
RenderSettings.fogMode = mode;
|
|
}
|
|
else if (RenderSettings.fog)
|
|
{
|
|
RenderSettings.fog = false;
|
|
}
|
|
}
|
|
|
|
private void Make_Particles_Appear(GameObject Particle_OBJ, ParticleSystem[] ParticleOBJ_Ps, ParticleSystem ParticleOBJ_P, int max_particles, bool reset_pcount, int rate, float Transp)
|
|
{
|
|
if (!(Particle_OBJ != null))
|
|
{
|
|
return;
|
|
}
|
|
if (!Particle_OBJ.activeInHierarchy)
|
|
{
|
|
Particle_OBJ.SetActive(value: true);
|
|
if (ParticleOBJ_Ps != null)
|
|
{
|
|
for (int i = 0; i < ParticleOBJ_Ps.Length; i++)
|
|
{
|
|
ParticleOBJ_Ps[i].Stop();
|
|
ParticleOBJ_Ps[i].Clear();
|
|
ParticleSystem.MainModule main = ParticleOBJ_Ps[i].main;
|
|
if (reset_pcount)
|
|
{
|
|
main.maxParticles = 0;
|
|
}
|
|
main.startColor = new Color(ParticleOBJ_Ps[i].main.startColor.color.r, ParticleOBJ_Ps[i].main.startColor.color.g, ParticleOBJ_Ps[i].main.startColor.color.b, 0f);
|
|
}
|
|
}
|
|
if (ParticleOBJ_P != null)
|
|
{
|
|
ParticleOBJ_P.Stop();
|
|
ParticleOBJ_P.Clear();
|
|
if (reset_pcount)
|
|
{
|
|
ParticleSystem.MainModule main2 = ParticleOBJ_P.main;
|
|
main2.maxParticles = 0;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (reset_pcount)
|
|
{
|
|
if (ParticleOBJ_Ps != null)
|
|
{
|
|
for (int j = 0; j < ParticleOBJ_Ps.Length; j++)
|
|
{
|
|
ParticleSystem.MainModule main3 = ParticleOBJ_Ps[j].main;
|
|
if (main3.maxParticles < max_particles)
|
|
{
|
|
main3.maxParticles += rate;
|
|
if (main3.startColor.color.a < Transp)
|
|
{
|
|
main3.startColor = new Color(ParticleOBJ_Ps[j].main.startColor.color.r, ParticleOBJ_Ps[j].main.startColor.color.g, ParticleOBJ_Ps[j].main.startColor.color.b, ParticleOBJ_Ps[j].main.startColor.color.a + 0.08f * (float)rate * Time.deltaTime);
|
|
}
|
|
}
|
|
if (!ParticleOBJ_Ps[j].isPlaying)
|
|
{
|
|
ParticleOBJ_Ps[j].Play();
|
|
}
|
|
}
|
|
}
|
|
if (ParticleOBJ_P != null)
|
|
{
|
|
ParticleSystem.MainModule main4 = ParticleOBJ_P.main;
|
|
if (main4.maxParticles < max_particles)
|
|
{
|
|
main4.maxParticles += rate;
|
|
}
|
|
if (!ParticleOBJ_P.isPlaying)
|
|
{
|
|
ParticleOBJ_P.Play();
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
if (ParticleOBJ_Ps != null)
|
|
{
|
|
for (int k = 0; k < ParticleOBJ_Ps.Length; k++)
|
|
{
|
|
ParticleSystem.MainModule main5 = ParticleOBJ_Ps[k].main;
|
|
main5.maxParticles = max_particles;
|
|
ParticleOBJ_Ps[k].Play();
|
|
}
|
|
}
|
|
if (ParticleOBJ_P != null)
|
|
{
|
|
ParticleSystem.MainModule main6 = ParticleOBJ_P.main;
|
|
main6.maxParticles = max_particles;
|
|
ParticleOBJ_P.Play();
|
|
}
|
|
}
|
|
|
|
private void Make_Particles_Dissappear(GameObject Particle_OBJ, ParticleSystem[] ParticleOBJ_Ps, ParticleSystem ParticleOBJ_P, int min_particles, int rate, bool pull_downward, bool on_lowest)
|
|
{
|
|
if (!(Particle_OBJ != null) || !Particle_OBJ.activeInHierarchy)
|
|
{
|
|
return;
|
|
}
|
|
if (ParticleOBJ_Ps != null)
|
|
{
|
|
int num = 0;
|
|
for (int i = 0; i < ParticleOBJ_Ps.Length; i++)
|
|
{
|
|
ParticleSystem.MainModule main = ParticleOBJ_Ps[i].main;
|
|
main.maxParticles -= rate;
|
|
if (pull_downward)
|
|
{
|
|
main.gravityModifier = -10f;
|
|
}
|
|
if (main.maxParticles < min_particles || SkyManager.instaKillParticles)
|
|
{
|
|
ParticleOBJ_Ps[i].Stop();
|
|
ParticleOBJ_Ps[i].Clear();
|
|
if (on_lowest)
|
|
{
|
|
Particle_OBJ.SetActive(value: false);
|
|
}
|
|
num++;
|
|
}
|
|
}
|
|
if (!on_lowest && num >= ParticleOBJ_Ps.Length)
|
|
{
|
|
Particle_OBJ.SetActive(value: false);
|
|
}
|
|
}
|
|
if (ParticleOBJ_P != null)
|
|
{
|
|
ParticleSystem.MainModule main2 = ParticleOBJ_P.main;
|
|
main2.maxParticles -= rate;
|
|
if (pull_downward)
|
|
{
|
|
main2.gravityModifier = -10f;
|
|
}
|
|
if (main2.maxParticles < min_particles)
|
|
{
|
|
ParticleOBJ_P.Stop();
|
|
ParticleOBJ_P.Clear();
|
|
Particle_OBJ.SetActive(value: false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|