Files
2026-02-21 16:45:37 +08:00

1390 lines
46 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
[ExecuteInEditMode]
[AddComponentMenu("Enviro/Sky System")]
public class EnviroSky : MonoBehaviour
{
public delegate void HourPassed();
public delegate void DayPassed();
public delegate void YearPassed();
public delegate void WeatherChanged(EnviroWeatherPrefab weatherType);
public delegate void ZoneWeatherChanged(EnviroWeatherPrefab weatherType, EnviroZone zone);
public delegate void SeasonChanged(SeasonVariables.Seasons season);
public delegate void isNightE();
public delegate void isDay();
private static EnviroSky _instance;
[Tooltip("Assign your player gameObject here. Required Field! or enable AssignInRuntime!")]
public GameObject Player;
[Tooltip("Assign your main camera here. Required Field! or enable AssignInRuntime!")]
public Camera PlayerCamera;
[Tooltip("If enabled Enviro will search for your Player and Camera by Tag!")]
public bool AssignInRuntime;
[Tooltip("Your Player Tag")]
public string PlayerTag = string.Empty;
[Tooltip("Your CameraTag")]
public string CameraTag = "MainCamera";
public EnviroPositioning Position;
public ObjectVariables Components;
public AudioVariables Audio;
public TimeVariables GameTime;
public LightVariables Lighting;
public Sky Sky;
public EnviroWeather Weather;
public SeasonVariables Seasons;
public CloudVariables Clouds;
public FogSettings Fog;
public LightShaftsSettings LightShafts;
public SatellitesVariables Satellites;
public EnviroQualitySettings Quality;
[HideInInspector]
public List<Transform> mySatellites = new List<Transform>();
[HideInInspector]
public bool started;
private bool isNight = true;
[HideInInspector]
public EnviroFog atmosphericFog;
[HideInInspector]
public EnviroLightShafts lightShaftsScript;
[HideInInspector]
public GameObject EffectsHolder;
[HideInInspector]
public AudioSource AudioSourceWeather;
[HideInInspector]
public AudioSource AudioSourceWeather2;
[HideInInspector]
public AudioSource AudioSourceAmbient;
[HideInInspector]
public AudioSource AudioSourceThunder;
[HideInInspector]
public List<EnviroVegetationInstance> EnviroVegetationInstances = new List<EnviroVegetationInstance>();
[HideInInspector]
public float currentHour;
[HideInInspector]
public float currentDay;
[HideInInspector]
public float currentYear;
[HideInInspector]
public float currentTimeInHours;
private Transform DomeTransform;
private Material VolumeCloudShader1;
private Material VolumeCloudShadowShader1;
private Material VolumeCloudShader2;
private Material VolumeCloudShadowShader2;
private Transform SunTransform;
private Light SunLight;
private Transform MoonTransform;
private Renderer MoonRenderer;
private Material MoonShader;
private Light MoonLight;
private float lastHourUpdate;
private float starsRot;
private float lastHour;
private const float pi = (float)Math.PI;
private Vector3 K = new Vector3(686f, 678f, 666f);
private const float n = 1.0003f;
private const float N = 2.545E+25f;
private const float pn = 0.035f;
public static EnviroSky instance
{
get
{
if (_instance == null)
{
_instance = UnityEngine.Object.FindObjectOfType<EnviroSky>();
}
return _instance;
}
}
private float OrbitRadius
{
get
{
return DomeTransform.localScale.x;
}
}
public event HourPassed OnHourPassed;
public event DayPassed OnDayPassed;
public event YearPassed OnYearPassed;
public event WeatherChanged OnWeatherChanged;
public event ZoneWeatherChanged OnZoneWeatherChanged;
public event SeasonChanged OnSeasonChanged;
public event isNightE OnNightTime;
public event isDay OnDayTime;
private void Start()
{
started = false;
lastHourUpdate = GameTime.Hours;
currentTimeInHours = GetInHours(GameTime.Hours, GameTime.Days, GameTime.Years);
RemoveSatellites();
CreateSatellites();
lastHourUpdate = currentTimeInHours;
Weather.currentActiveWeatherID = Weather.zones[0].zoneWeatherPrefabs[0].GetComponent<EnviroWeatherPrefab>();
Weather.lastActiveWeatherID = Weather.zones[0].zoneWeatherPrefabs[0].GetComponent<EnviroWeatherPrefab>();
Weather.nextUpdate = currentTimeInHours + 1f;
Weather.currentAudioSource = AudioSourceWeather;
InvokeRepeating("UpdateEnviroment", 0f, Quality.UpdateInterval);
if (PlayerCamera != null && Player != null && !AssignInRuntime)
{
Init();
CreateEffects();
started = true;
}
}
private void OnEnable()
{
DomeTransform = base.transform;
if (AssignInRuntime)
{
started = false;
}
else if (PlayerCamera != null && Player != null)
{
Init();
CreateEffects();
started = true;
}
}
private void Init()
{
atmosphericFog = PlayerCamera.gameObject.GetComponent<EnviroFog>();
if (atmosphericFog == null)
{
atmosphericFog = PlayerCamera.gameObject.AddComponent<EnviroFog>();
atmosphericFog.fogMaterial = Fog.fogMaterial;
atmosphericFog.fogShader = Fog.fogMaterial.shader;
}
lightShaftsScript = PlayerCamera.gameObject.GetComponent<EnviroLightShafts>();
if (lightShaftsScript == null)
{
lightShaftsScript = PlayerCamera.gameObject.AddComponent<EnviroLightShafts>();
lightShaftsScript.sunShaftsMaterial = LightShafts.lightShaftsMaterial;
lightShaftsScript.sunShaftsShader = LightShafts.lightShaftsMaterial.shader;
lightShaftsScript.simpleClearMaterial = LightShafts.clearMaterial;
lightShaftsScript.simpleClearShader = LightShafts.clearMaterial.shader;
}
RemoveSatellites();
CreateSatellites();
RenderSettings.fogMode = Fog.Fogmode;
RenderSettings.skybox = Components.sky;
RenderSettings.ambientMode = Lighting.ambientMode;
if (PlayerCamera != null)
{
PlayerCamera.clearFlags = CameraClearFlags.Skybox;
}
InitClouds();
if ((bool)Components.Sun)
{
SunTransform = Components.Sun.transform;
SunLight = Components.Sun.GetComponent<Light>();
}
else
{
Debug.LogError("Please set Sun object in inspector!");
}
if ((bool)Components.Moon)
{
MoonTransform = Components.Moon.transform;
MoonRenderer = Components.Moon.GetComponent<Renderer>();
MoonShader = MoonRenderer.sharedMaterial;
MoonLight = Components.Moon.GetComponent<Light>();
}
else
{
Debug.LogError("Please set Moon object in inspector!");
}
}
public void AssignAndStart(GameObject player, Camera Camera)
{
Player = player;
PlayerCamera = Camera;
Init();
CreateEffects();
started = true;
}
public void ChangeFocus(GameObject player, Camera Camera)
{
Player = player;
PlayerCamera = Camera;
atmosphericFog = PlayerCamera.gameObject.GetComponent<EnviroFog>();
if (atmosphericFog == null)
{
atmosphericFog = PlayerCamera.gameObject.AddComponent<EnviroFog>();
atmosphericFog.fogMaterial = Fog.fogMaterial;
atmosphericFog.fogShader = Fog.fogMaterial.shader;
}
lightShaftsScript = PlayerCamera.gameObject.GetComponent<EnviroLightShafts>();
if (lightShaftsScript == null)
{
lightShaftsScript = PlayerCamera.gameObject.AddComponent<EnviroLightShafts>();
lightShaftsScript.sunShaftsMaterial = LightShafts.lightShaftsMaterial;
lightShaftsScript.sunShaftsShader = LightShafts.lightShaftsMaterial.shader;
lightShaftsScript.simpleClearMaterial = LightShafts.clearMaterial;
lightShaftsScript.simpleClearShader = LightShafts.clearMaterial.shader;
}
}
public void InitClouds()
{
if ((bool)Components.VolumeCloudsLayer1 && (bool)Components.VolumeCloudsLayer2)
{
VolumeCloudShader1 = Components.VolumeCloudsLayer1.GetComponent<Renderer>().sharedMaterial;
VolumeCloudShader2 = Components.VolumeCloudsLayer2.GetComponent<Renderer>().sharedMaterial;
MeshFilter component = Components.VolumeCloudsLayer1.GetComponent<MeshFilter>();
MeshFilter component2 = Components.VolumeCloudsLayer2.GetComponent<MeshFilter>();
if (component != null && component.sharedMesh != null)
{
UnityEngine.Object.DestroyImmediate(component.sharedMesh);
}
if (component2 != null && component2.sharedMesh != null)
{
UnityEngine.Object.DestroyImmediate(component2.sharedMesh);
}
CreateVolumeCloudMesh(Clouds.Quality);
CreateVolumeCloudMesh(1);
}
else if (Components.VolumeCloudsLayer1 == null)
{
Debug.LogError("Please set VolumeCloudsLayer1 object in inspector!");
}
if ((bool)Components.VolumeCloudsShadowsLayer1)
{
VolumeCloudShadowShader1 = Components.VolumeCloudsShadowsLayer1.GetComponent<Renderer>().sharedMaterial;
}
else if (Components.VolumeCloudsShadowsLayer1 == null)
{
Debug.LogError("Please set VolumeCloudsShadowsLayer1 object in inspector!");
}
if ((bool)Components.VolumeCloudsShadowsLayer2)
{
VolumeCloudShadowShader2 = Components.VolumeCloudsShadowsLayer2.GetComponent<Renderer>().sharedMaterial;
}
else if (Components.VolumeCloudsShadowsLayer2 == null)
{
Debug.LogError("Please set VolumeCloudsShadowsLayer2 object in inspector!");
}
}
public virtual void NotifyHourPassed()
{
if (this.OnHourPassed != null)
{
this.OnHourPassed();
}
}
public virtual void NotifyDayPassed()
{
if (this.OnDayPassed != null)
{
this.OnDayPassed();
}
}
public virtual void NotifyYearPassed()
{
if (this.OnYearPassed != null)
{
this.OnYearPassed();
}
}
public virtual void NotifyWeatherChanged(EnviroWeatherPrefab type)
{
if (this.OnWeatherChanged != null)
{
this.OnWeatherChanged(type);
}
}
public virtual void NotifyZoneWeatherChanged(EnviroWeatherPrefab type, EnviroZone zone)
{
if (this.OnZoneWeatherChanged != null)
{
this.OnZoneWeatherChanged(type, zone);
}
}
public virtual void NotifySeasonChanged(SeasonVariables.Seasons season)
{
if (this.OnSeasonChanged != null)
{
this.OnSeasonChanged(season);
}
}
public virtual void NotifyIsNight()
{
if (this.OnNightTime != null)
{
this.OnNightTime();
}
}
public virtual void NotifyIsDay()
{
if (this.OnDayTime != null)
{
this.OnDayTime();
}
}
public void CreateEffects()
{
if (!(EffectsHolder == null))
{
return;
}
EffectsHolder = new GameObject();
EffectsHolder.name = "Enviro Effects";
EffectsHolder.transform.position = Player.transform.position;
CreateWeatherEffectHolder();
GameObject gameObject = UnityEngine.Object.Instantiate(Audio.SFXHolderPrefab, Vector3.zero, Quaternion.identity);
gameObject.transform.parent = EffectsHolder.transform;
EnviroAudioSource[] componentsInChildren = gameObject.GetComponentsInChildren<EnviroAudioSource>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
switch (componentsInChildren[i].myFunction)
{
case EnviroAudioSource.AudioSourceFunction.Weather1:
AudioSourceWeather = componentsInChildren[i].audiosrc;
break;
case EnviroAudioSource.AudioSourceFunction.Weather2:
AudioSourceWeather2 = componentsInChildren[i].audiosrc;
break;
case EnviroAudioSource.AudioSourceFunction.Ambient:
AudioSourceAmbient = componentsInChildren[i].audiosrc;
break;
case EnviroAudioSource.AudioSourceFunction.Thunder:
AudioSourceThunder = componentsInChildren[i].audiosrc;
break;
}
}
}
public int RegisterMe(EnviroVegetationInstance me)
{
EnviroVegetationInstances.Add(me);
return EnviroVegetationInstances.Count - 1;
}
public void ChangeSeason(SeasonVariables.Seasons season)
{
Seasons.currentSeasons = season;
NotifySeasonChanged(season);
}
private void UpdateSeason()
{
if (currentDay >= 0f && currentDay < Seasons.SpringInDays)
{
Seasons.currentSeasons = SeasonVariables.Seasons.Spring;
if (Seasons.lastSeason != Seasons.currentSeasons)
{
NotifySeasonChanged(SeasonVariables.Seasons.Spring);
}
Seasons.lastSeason = Seasons.currentSeasons;
}
else if (currentDay >= Seasons.SpringInDays && currentDay < Seasons.SpringInDays + Seasons.SummerInDays)
{
Seasons.currentSeasons = SeasonVariables.Seasons.Summer;
if (Seasons.lastSeason != Seasons.currentSeasons)
{
NotifySeasonChanged(SeasonVariables.Seasons.Summer);
}
Seasons.lastSeason = Seasons.currentSeasons;
}
else if (currentDay >= Seasons.SpringInDays + Seasons.SummerInDays && currentDay < Seasons.SpringInDays + Seasons.SummerInDays + Seasons.AutumnInDays)
{
Seasons.currentSeasons = SeasonVariables.Seasons.Autumn;
if (Seasons.lastSeason != Seasons.currentSeasons)
{
NotifySeasonChanged(SeasonVariables.Seasons.Autumn);
}
Seasons.lastSeason = Seasons.currentSeasons;
}
else if (currentDay >= Seasons.SpringInDays + Seasons.SummerInDays + Seasons.AutumnInDays && currentDay <= Seasons.SpringInDays + Seasons.SummerInDays + Seasons.AutumnInDays + Seasons.WinterInDays)
{
Seasons.currentSeasons = SeasonVariables.Seasons.Winter;
if (Seasons.lastSeason != Seasons.currentSeasons)
{
NotifySeasonChanged(SeasonVariables.Seasons.Winter);
}
Seasons.lastSeason = Seasons.currentSeasons;
}
}
public float GetInHours(float hours, float days, float years)
{
return hours + days * 24f + years * (Seasons.SpringInDays + Seasons.SummerInDays + Seasons.AutumnInDays + Seasons.WinterInDays) * 24f;
}
private void UpdateEnviroment()
{
if (Seasons.calcSeasons)
{
UpdateSeason();
}
if (EnviroVegetationInstances.Count <= 0)
{
return;
}
for (int i = 0; i < EnviroVegetationInstances.Count; i++)
{
if (EnviroVegetationInstances[i] != null)
{
EnviroVegetationInstances[i].UpdateInstance();
}
}
}
private void CreateSatellites()
{
for (int i = 0; i < Satellites.additionalSatellites.Count; i++)
{
GameObject gameObject = UnityEngine.Object.Instantiate(Satellites.additionalSatellites[i].prefab, base.transform.position + new Vector3(0f, Satellites.additionalSatellites[i].orbit, 0f), Quaternion.identity);
gameObject.transform.parent = base.transform;
mySatellites.Add(gameObject.transform);
}
}
private void RemoveSatellites()
{
for (int i = 0; i < mySatellites.Count; i++)
{
UnityEngine.Object.DestroyImmediate(mySatellites[i].gameObject);
}
mySatellites = new List<Transform>();
}
private void UpdateQuality()
{
switch (Quality.CloudsQuality)
{
case EnviroQualitySettings.CloudQuality.None:
Components.VolumeCloudsLayer1.SetActive(false);
Components.VolumeCloudsLayer2.SetActive(false);
Components.VolumeCloudsShadowsLayer1.SetActive(false);
Components.VolumeCloudsShadowsLayer2.SetActive(false);
break;
case EnviroQualitySettings.CloudQuality.OneLayer:
Components.VolumeCloudsLayer1.SetActive(true);
Components.VolumeCloudsLayer2.SetActive(false);
if (Quality.CloudsShadowCast)
{
Components.VolumeCloudsShadowsLayer1.SetActive(true);
Components.VolumeCloudsShadowsLayer2.SetActive(false);
}
else
{
Components.VolumeCloudsShadowsLayer1.SetActive(false);
Components.VolumeCloudsShadowsLayer2.SetActive(false);
}
break;
case EnviroQualitySettings.CloudQuality.TwoLayer:
Components.VolumeCloudsLayer1.SetActive(true);
Components.VolumeCloudsLayer2.SetActive(true);
if (Quality.CloudsShadowCast)
{
Components.VolumeCloudsShadowsLayer1.SetActive(true);
Components.VolumeCloudsShadowsLayer2.SetActive(true);
}
else
{
Components.VolumeCloudsShadowsLayer1.SetActive(false);
Components.VolumeCloudsShadowsLayer2.SetActive(false);
}
break;
}
if (atmosphericFog != null)
{
atmosphericFog.distanceFog = Fog.distanceFog;
atmosphericFog.heightFog = Fog.heightFog;
atmosphericFog.height = Fog.height;
atmosphericFog.heightDensity = Fog.heightDensity;
atmosphericFog.useRadialDistance = Fog.useRadialDistance;
atmosphericFog.startDistance = Fog.startDistance;
if (Fog.AdvancedFog)
{
atmosphericFog.enabled = true;
}
else
{
atmosphericFog.enabled = false;
}
}
if (lightShaftsScript != null)
{
lightShaftsScript.resolution = LightShafts.resolution;
lightShaftsScript.screenBlendMode = LightShafts.screenBlendMode;
lightShaftsScript.useDepthTexture = LightShafts.useDepthTexture;
lightShaftsScript.sunThreshold = LightShafts.thresholdColor.Evaluate(GameTime.Hours / 24f);
lightShaftsScript.sunShaftBlurRadius = LightShafts.blurRadius;
lightShaftsScript.sunShaftIntensity = LightShafts.intensity;
lightShaftsScript.maxRadius = LightShafts.maxRadius;
lightShaftsScript.sunColor = LightShafts.lighShaftsColor.Evaluate(GameTime.Hours / 24f);
if (LightShafts.lightShafts)
{
lightShaftsScript.enabled = true;
}
else
{
lightShaftsScript.enabled = false;
}
}
}
private Vector3 CalculatePosition()
{
Vector3 result = default(Vector3);
result.x = Player.transform.position.x;
result.z = Player.transform.position.z;
result.y = Position.fixedSkyHeight;
return result;
}
private void UpdateSatellites()
{
for (int i = 0; i < mySatellites.Count; i++)
{
float angle = (currentTimeInHours - lastHour) * Satellites.additionalSatellites[i].speed;
mySatellites[i].RotateAround(base.transform.position, Satellites.additionalSatellites[i].coords, angle);
Vector3 b = (mySatellites[i].position - base.transform.position).normalized * Satellites.additionalSatellites[i].orbit + base.transform.position;
mySatellites[i].position = Vector3.Slerp(mySatellites[i].position, b, Time.deltaTime * 5f);
}
lastHour = currentTimeInHours;
}
private void Update()
{
if (!started)
{
if (!AssignInRuntime || !(PlayerTag != string.Empty) || !(CameraTag != string.Empty) || !Application.isPlaying)
{
started = false;
return;
}
Player = GameObject.FindGameObjectWithTag(PlayerTag);
PlayerCamera = GameObject.FindGameObjectWithTag(CameraTag).GetComponent<Camera>();
if (!(Player != null) || !(PlayerCamera != null))
{
started = false;
return;
}
Init();
CreateEffects();
started = true;
}
UpdateTime();
ValidateParameters();
UpdateQuality();
UpdateAmbientLight();
UpdateWeather();
if (EffectsHolder != null)
{
EffectsHolder.transform.position = Player.transform.position;
}
if (Fog.AdvancedFog)
{
UpdateAdvancedFog();
}
float f = (float)Math.PI / 180f * GameTime.Latitude;
float num = Mathf.Sin(f);
float num2 = Mathf.Cos(f);
float num3 = (float)Math.PI / 180f * GameTime.Longitude;
float f2 = 0.4093f * Mathf.Sin((float)Math.PI / 184f * (GameTime.Days - 81f));
float num4 = Mathf.Sin(f2);
float num5 = Mathf.Cos(f2);
float num6 = (int)(GameTime.Longitude / 15f);
float num7 = (float)Math.PI / 12f * num6;
float num8 = GameTime.Hours + 0.17f * Mathf.Sin(0.03369f * (GameTime.Days - 80f)) - 0.129f * Mathf.Sin((float)Math.PI * 2f / 355f * (GameTime.Days - 8f)) + 12f / (float)Math.PI * (num7 - num3);
float f3 = (float)Math.PI / 12f * num8;
float num9 = Mathf.Sin(f3);
float num10 = Mathf.Cos(f3);
float f4 = num * num4 - num2 * num5 * num10;
float num11 = Mathf.Asin(f4);
float y = (0f - num5) * num9;
float x = num2 * num4 - num * num5 * num10;
float num12 = Mathf.Atan2(y, x);
float num13 = (float)Math.PI / 2f - num11;
float phi = num12;
SunTransform.position = DomeTransform.position + DomeTransform.rotation * SphericalToCartesian(OrbitRadius, num13, phi);
SunTransform.LookAt(DomeTransform.position);
MoonTransform.position = DomeTransform.position + DomeTransform.rotation * SphericalToCartesian(OrbitRadius, num13 + (float)Math.PI, phi);
MoonTransform.LookAt(DomeTransform.position);
if (isNight)
{
Sky.currentStarsIntensity = Mathf.Lerp(Sky.currentStarsIntensity, Sky.StarsIntensity, Time.deltaTime * 20f);
}
else
{
Sky.currentStarsIntensity = Mathf.Lerp(Sky.currentStarsIntensity, 0f, Time.deltaTime * 20f);
}
SetupSunAndMoonColor(num13);
SetupShader(num13);
if (PlayerCamera != null)
{
if (!Position.FixedHeight)
{
base.transform.position = PlayerCamera.transform.position;
}
else
{
base.transform.position = CalculatePosition();
}
base.transform.localScale = new Vector3(PlayerCamera.farClipPlane - PlayerCamera.farClipPlane * 0.1f, PlayerCamera.farClipPlane - PlayerCamera.farClipPlane * 0.1f, PlayerCamera.farClipPlane - PlayerCamera.farClipPlane * 0.1f);
}
if (!isNight && (GameTime.Hours >= GameTime.NightTimeInHours || GameTime.Hours <= GameTime.MorningTimeInHours) && AudioSourceAmbient != null)
{
switch (Seasons.currentSeasons)
{
case SeasonVariables.Seasons.Spring:
AudioSourceAmbient.clip = Audio.SpringNightAmbient;
break;
case SeasonVariables.Seasons.Summer:
AudioSourceAmbient.clip = Audio.SummerNightAmbient;
break;
case SeasonVariables.Seasons.Autumn:
AudioSourceAmbient.clip = Audio.AutumnNightAmbient;
break;
case SeasonVariables.Seasons.Winter:
AudioSourceAmbient.clip = Audio.WinterNightAmbient;
break;
}
AudioSourceAmbient.loop = true;
AudioSourceAmbient.Play();
isNight = true;
NotifyIsNight();
}
else if (isNight && GameTime.Hours <= GameTime.NightTimeInHours && GameTime.Hours >= GameTime.MorningTimeInHours && AudioSourceAmbient != null)
{
switch (Seasons.currentSeasons)
{
case SeasonVariables.Seasons.Spring:
AudioSourceAmbient.clip = Audio.SpringDayAmbient;
break;
case SeasonVariables.Seasons.Summer:
AudioSourceAmbient.clip = Audio.SummerDayAmbient;
break;
case SeasonVariables.Seasons.Autumn:
AudioSourceAmbient.clip = Audio.AutumnDayAmbient;
break;
case SeasonVariables.Seasons.Winter:
AudioSourceAmbient.clip = Audio.WinterDayAmbient;
break;
}
AudioSourceAmbient.loop = true;
AudioSourceAmbient.Play();
isNight = false;
NotifyIsDay();
}
}
private Vector3 BetaRay()
{
Vector3 vector = Sky.waveLenght * 1E-09f;
Vector3 result = default(Vector3);
result.x = 8f * Mathf.Pow((float)Math.PI, 3f) * Mathf.Pow(Mathf.Pow(1.0003f, 2f) - 1f, 2f) * 6.105f / (7.635E+25f * Mathf.Pow(vector.x, 4f) * 5.755f) * 2000f;
result.y = 8f * Mathf.Pow((float)Math.PI, 3f) * Mathf.Pow(Mathf.Pow(1.0003f, 2f) - 1f, 2f) * 6.105f / (7.635E+25f * Mathf.Pow(vector.y, 4f) * 5.755f) * 2000f;
result.z = 8f * Mathf.Pow((float)Math.PI, 3f) * Mathf.Pow(Mathf.Pow(1.0003f, 2f) - 1f, 2f) * 6.105f / (7.635E+25f * Mathf.Pow(vector.z, 4f) * 5.755f) * 2000f;
return result;
}
private Vector3 BetaMie()
{
float num = 0.2f * Sky.turbidity * 10f;
Vector3 result = default(Vector3);
result.x = 434f * num * (float)Math.PI * Mathf.Pow((float)Math.PI * 2f / Sky.waveLenght.x, 2f) * K.x;
result.y = 434f * num * (float)Math.PI * Mathf.Pow((float)Math.PI * 2f / Sky.waveLenght.y, 2f) * K.y;
result.z = 434f * num * (float)Math.PI * Mathf.Pow((float)Math.PI * 2f / Sky.waveLenght.z, 2f) * K.z;
result.x = Mathf.Pow(result.x, -1f);
result.y = Mathf.Pow(result.y, -1f);
result.z = Mathf.Pow(result.z, -1f);
return result;
}
private Vector3 GetMieG()
{
return new Vector3(1f - Sky.g * Sky.g, 1f + Sky.g * Sky.g, 2f * Sky.g);
}
private void SetupShader(float setup)
{
RenderSettings.skybox.SetVector("_SunDir", -SunLight.transform.forward);
RenderSettings.skybox.SetMatrix("_Sun", SunTransform.worldToLocalMatrix);
RenderSettings.skybox.SetColor("_scatteringColor", Sky.scatteringColor.Evaluate(GameTime.Hours / 24f));
RenderSettings.skybox.SetColor("_sunDiskColor", Sky.SunDiskColor.Evaluate(GameTime.Hours / 24f));
RenderSettings.skybox.SetColor("_weatherColor", Sky.weatherMod);
RenderSettings.skybox.SetVector("_waveLenght", Sky.waveLenght);
RenderSettings.skybox.SetVector("_Bm", BetaMie() * Sky.mie);
RenderSettings.skybox.SetVector("_Br", BetaRay() * Sky.rayleigh);
RenderSettings.skybox.SetVector("_mieG", GetMieG());
RenderSettings.skybox.SetFloat("_SunIntensity", Sky.SunIntensity);
RenderSettings.skybox.SetFloat("_SunDiskSize", Sky.SunDiskScale);
RenderSettings.skybox.SetFloat("_SunDiskIntensity", Sky.SunDiskIntensity);
RenderSettings.skybox.SetFloat("_SunDiskSize", Sky.SunDiskScale);
RenderSettings.skybox.SetFloat("_Exposure", Sky.SkyExposure);
RenderSettings.skybox.SetFloat("_SkyLuminance", Sky.SkyLuminence);
RenderSettings.skybox.SetFloat("_scatteringPower", Sky.scatteringCurve.Evaluate(GameTime.Hours / 24f));
RenderSettings.skybox.SetFloat("_SkyCorrection", Sky.SkyCorrection);
RenderSettings.skybox.SetFloat("_StarsIntensity", Sky.currentStarsIntensity);
if (Sky.StarsBlinking > 0f)
{
starsRot += Sky.StarsBlinking * Time.deltaTime;
Quaternion q = Quaternion.Euler(starsRot, starsRot, starsRot);
Matrix4x4 value = Matrix4x4.TRS(Vector3.zero, q, new Vector3(1f, 1f, 1f));
RenderSettings.skybox.SetMatrix("_NoiseMatrix", value);
}
if (VolumeCloudShader1 != null && Quality.CloudsQuality == EnviroQualitySettings.CloudQuality.OneLayer)
{
VolumeCloudShader1.SetFloat("_Scale", PlayerCamera.farClipPlane * Clouds.Scaling);
VolumeCloudShader1.SetColor("_BaseColor", Clouds.FirstColor);
VolumeCloudShader1.SetColor("_ShadingColor", Clouds.SecondColor);
VolumeCloudShader1.SetFloat("_CloudCover", Clouds.Coverage);
VolumeCloudShader1.SetFloat("_Density", Clouds.Density);
VolumeCloudShader1.SetFloat("_CloudAlpha", Clouds.Alpha);
VolumeCloudShader1.SetFloat("_Speed1Layer", Clouds.Speed1);
VolumeCloudShader1.SetFloat("_Speed2Layer", Clouds.Speed2);
VolumeCloudShader1.SetVector("_WindDir", Clouds.WindDir);
VolumeCloudShader1.SetFloat("_Exposure", Sky.SkyExposure);
VolumeCloudShader1.SetFloat("_ambient", Clouds.AmbientLightIntensity);
VolumeCloudShader1.SetFloat("_direct", Clouds.DirectLightIntensity);
VolumeCloudShader1.SetFloat("_nightColorMod", Clouds.DirectLightIntensityTimed.Evaluate(GameTime.Hours / 24f));
}
if (VolumeCloudShader1 != null && VolumeCloudShader2 != null && Quality.CloudsQuality == EnviroQualitySettings.CloudQuality.TwoLayer)
{
VolumeCloudShader1.SetFloat("_Scale", PlayerCamera.farClipPlane * Clouds.Scaling);
VolumeCloudShader1.SetColor("_BaseColor", Clouds.FirstColor);
VolumeCloudShader1.SetColor("_ShadingColor", Clouds.SecondColor);
VolumeCloudShader1.SetFloat("_CloudCover", Clouds.Coverage);
VolumeCloudShader1.SetFloat("_Density", Clouds.Density);
VolumeCloudShader1.SetFloat("_CloudAlpha", Clouds.Alpha);
VolumeCloudShader1.SetFloat("_Speed1Layer", Clouds.Speed1);
VolumeCloudShader1.SetFloat("_Speed2Layer", Clouds.Speed2);
VolumeCloudShader1.SetVector("_WindDir", Clouds.WindDir);
VolumeCloudShader1.SetFloat("_direct", Clouds.DirectLightIntensity);
VolumeCloudShader1.SetFloat("_ambient", Clouds.AmbientLightIntensity);
VolumeCloudShader1.SetFloat("_nightColorMod", Clouds.DirectLightIntensityTimed.Evaluate(GameTime.Hours / 24f));
VolumeCloudShader2.SetFloat("_Scale", PlayerCamera.farClipPlane * Clouds.Scaling);
VolumeCloudShader2.SetColor("_BaseColor", Clouds.FirstColor);
VolumeCloudShader2.SetColor("_ShadingColor", Clouds.SecondColor);
VolumeCloudShader2.SetFloat("_CloudCover", Clouds.Coverage);
VolumeCloudShader2.SetFloat("_Density", Clouds.Density);
VolumeCloudShader2.SetFloat("_CloudAlpha", Clouds.Alpha);
VolumeCloudShader2.SetFloat("_Speed1Layer", Clouds.Speed1);
VolumeCloudShader2.SetFloat("_Speed2Layer", Clouds.Speed2);
VolumeCloudShader2.SetVector("_WindDir", Clouds.WindDir);
VolumeCloudShader2.SetFloat("_Offset", Clouds.LayerOffset);
VolumeCloudShader2.SetFloat("_direct", Clouds.DirectLightIntensity);
VolumeCloudShader2.SetFloat("_ambient", Clouds.AmbientLightIntensity);
VolumeCloudShader2.SetFloat("_nightColorMod", Clouds.DirectLightIntensityTimed.Evaluate(GameTime.Hours / 24f));
}
if (VolumeCloudShadowShader1 != null && Quality.CloudsShadowCast && Quality.CloudsQuality == EnviroQualitySettings.CloudQuality.OneLayer)
{
VolumeCloudShadowShader1.SetFloat("_Scale", PlayerCamera.farClipPlane * Clouds.Scaling);
VolumeCloudShadowShader1.SetFloat("_CloudCover", Clouds.Coverage);
VolumeCloudShadowShader1.SetFloat("_CloudAlpha", Clouds.Alpha);
VolumeCloudShadowShader1.SetFloat("_Speed1Layer", Clouds.Speed1);
VolumeCloudShadowShader1.SetFloat("_Speed2Layer", Clouds.Speed2);
VolumeCloudShadowShader1.SetVector("_WindDir", Clouds.WindDir);
}
if (VolumeCloudShadowShader2 != null && Quality.CloudsShadowCast && Quality.CloudsQuality == EnviroQualitySettings.CloudQuality.TwoLayer)
{
VolumeCloudShadowShader1.SetFloat("_Scale", PlayerCamera.farClipPlane * Clouds.Scaling);
VolumeCloudShadowShader1.SetFloat("_CloudCover", Clouds.Coverage);
VolumeCloudShadowShader1.SetFloat("_CloudAlpha", Clouds.Alpha);
VolumeCloudShadowShader1.SetFloat("_Speed1Layer", Clouds.Speed1);
VolumeCloudShadowShader1.SetFloat("_Speed2Layer", Clouds.Speed2);
VolumeCloudShadowShader1.SetVector("_WindDir", Clouds.WindDir);
VolumeCloudShadowShader2.SetFloat("_Scale", PlayerCamera.farClipPlane * Clouds.Scaling);
VolumeCloudShadowShader2.SetFloat("_CloudCover", Clouds.Coverage);
VolumeCloudShadowShader2.SetFloat("_CloudAlpha", Clouds.Alpha);
VolumeCloudShadowShader2.SetFloat("_Speed1Layer", Clouds.Speed1);
VolumeCloudShadowShader2.SetFloat("_Speed2Layer", Clouds.Speed2);
VolumeCloudShadowShader2.SetVector("_WindDir", Clouds.WindDir);
VolumeCloudShadowShader2.SetFloat("_Offset", Clouds.LayerOffset);
}
if (MoonShader != null)
{
MoonShader.SetFloat("_Phase", Lighting.MoonPhase);
}
}
private void UpdateAdvancedFog()
{
Fog.fogMaterial.SetVector("_SunDir", -SunLight.transform.forward);
Fog.fogMaterial.SetMatrix("_SunMatrix", SunTransform.worldToLocalMatrix);
Fog.fogMaterial.SetColor("_scatteringColor", Sky.scatteringColor.Evaluate(GameTime.Hours / 24f));
Fog.fogMaterial.SetColor("_sunDiskColor", Sky.SunDiskColor.Evaluate(GameTime.Hours / 24f));
Fog.fogMaterial.SetColor("_weatherColor", Sky.weatherMod);
Fog.fogMaterial.SetVector("_waveLenght", Sky.waveLenght);
Fog.fogMaterial.SetVector("_Bm", BetaMie() * Sky.mie);
Fog.fogMaterial.SetVector("_Br", BetaRay() * Sky.rayleigh);
Fog.fogMaterial.SetVector("_mieG", GetMieG());
Fog.fogMaterial.SetFloat("_SunIntensity", Sky.SunIntensity);
Fog.fogMaterial.SetFloat("_SunDiskSize", Sky.SunDiskScale);
Fog.fogMaterial.SetFloat("_SunDiskIntensity", Sky.SunDiskIntensity);
Fog.fogMaterial.SetFloat("_SunDiskSize", Sky.SunDiskScale);
Fog.fogMaterial.SetFloat("_Exposure", Sky.SkyExposure);
Fog.fogMaterial.SetFloat("_SkyLuminance", Sky.SkyLuminence);
Fog.fogMaterial.SetFloat("_scatteringPower", Sky.scatteringCurve.Evaluate(GameTime.Hours / 24f));
Fog.fogMaterial.SetFloat("_SkyCorrection", Sky.SkyCorrection);
Fog.fogMaterial.SetFloat("_SkyFogHeight", Fog.skyFogHeight);
Fog.fogMaterial.SetFloat("_SkyFogStrenght", Fog.skyFogStrength);
Fog.fogMaterial.SetFloat("_scatteringStrenght", Fog.scatteringStrenght);
Fog.fogMaterial.SetFloat("_distanceFogIntensity", Fog.distanceFogIntensity);
Fog.fogMaterial.SetVector("_NoiseData", new Vector4(Fog.noiseScale, Fog.heightDensity, Fog.noiseIntensity, 0f));
Fog.fogMaterial.SetVector("_NoiseVelocity", new Vector4(Fog.heightFogVelocity.x, Fog.heightFogVelocity.y, 0f, 0f));
}
private void FixedUpdate()
{
if (started)
{
UpdateSatellites();
}
}
private void UpdateTime()
{
float num = GameTime.DayLengthInMinutes * 60f;
float num2 = num / 24f;
float num3 = Time.deltaTime / num2;
float num4 = Time.deltaTime / (30f * num) * 2f;
if (GameTime.ProgressTime)
{
GameTime.Hours += num3;
Lighting.MoonPhase += num4;
if (Lighting.MoonPhase < -1f)
{
Lighting.MoonPhase += 2f;
}
else if (Lighting.MoonPhase > 1f)
{
Lighting.MoonPhase -= 2f;
}
if (GameTime.Hours >= lastHourUpdate + 1f)
{
lastHourUpdate = GameTime.Hours;
NotifyHourPassed();
}
if (GameTime.Hours >= 24f)
{
GameTime.Hours = 0f;
NotifyHourPassed();
lastHourUpdate = 0f;
GameTime.Days += 1f;
NotifyDayPassed();
}
if (GameTime.Days >= Seasons.SpringInDays + Seasons.SummerInDays + Seasons.AutumnInDays + Seasons.WinterInDays)
{
GameTime.Years += 1f;
GameTime.Days = 0f;
NotifyYearPassed();
}
currentHour = GameTime.Hours;
currentDay = GameTime.Days;
currentYear = GameTime.Years;
currentTimeInHours = GetInHours(currentHour, currentDay, currentYear);
}
}
private void UpdateAmbientLight()
{
RenderSettings.ambientIntensity = Lighting.ambientIntensity.Evaluate(GameTime.Hours / 24f);
switch (Lighting.ambientMode)
{
case AmbientMode.Flat:
RenderSettings.ambientSkyColor = Lighting.ambientSkyColor.Evaluate(GameTime.Hours / 24f);
break;
case AmbientMode.Trilight:
RenderSettings.ambientSkyColor = Lighting.ambientSkyColor.Evaluate(GameTime.Hours / 24f);
RenderSettings.ambientEquatorColor = Lighting.ambientEquatorColor.Evaluate(GameTime.Hours / 24f);
RenderSettings.ambientGroundColor = Lighting.ambientGroundColor.Evaluate(GameTime.Hours / 24f);
break;
case AmbientMode.Skybox:
DynamicGI.UpdateEnvironment();
break;
}
}
private void SetupSunAndMoonColor(float setup)
{
SunLight.color = Lighting.LightColor.Evaluate(GameTime.Hours / 24f);
MoonLight.color = Lighting.LightColor.Evaluate(GameTime.Hours / 24f);
Shader.SetGlobalColor("_EnviroLighting", Lighting.LightColor.Evaluate(GameTime.Hours / 24f));
float num = (float)Math.PI / 2f - setup;
float num2 = Mathf.Abs(num);
float num3 = 0.17453292f;
float b = Lighting.SunIntensity + Lighting.SunWeatherMod;
float num4 = Lighting.MoonIntensity * Mathf.Clamp01(1.3f - Mathf.Abs(Lighting.MoonPhase)) + Lighting.SunWeatherMod;
if (num4 <= 0.1f)
{
num4 = 0.1f;
}
if (num > 0f)
{
MoonLight.enabled = false;
SunLight.enabled = true;
if (num2 < num3)
{
SunLight.intensity = Mathf.Lerp(0.3f, b, num2 / num3);
}
else
{
SunLight.intensity = Mathf.Lerp(SunLight.intensity, b, 0.01f);
}
if (lightShaftsScript != null && LightShafts.lightShafts)
{
lightShaftsScript.sunTransform = Components.Sun.transform;
}
}
else
{
SunLight.enabled = false;
MoonLight.enabled = true;
if (num2 < num3)
{
MoonLight.intensity = Mathf.Lerp(0.3f, num4, num2 / num3);
}
else
{
MoonLight.intensity = Mathf.Lerp(MoonLight.intensity, num4, 0.01f);
}
}
RenderSettings.fogColor = SunLight.color * Sky.weatherMod;
}
private void ValidateParameters()
{
GameTime.Hours = Mathf.Repeat(GameTime.Hours, 24f);
GameTime.Longitude = Mathf.Clamp(GameTime.Longitude, -180f, 180f);
GameTime.Latitude = Mathf.Clamp(GameTime.Latitude, -90f, 90f);
}
private Vector3 SphericalToCartesian(float radius, float theta, float phi)
{
float num = Mathf.Sin(theta);
float num2 = Mathf.Cos(theta);
float num3 = Mathf.Sin(phi);
float num4 = Mathf.Cos(phi);
Vector3 result = default(Vector3);
result.x = radius * num * num4;
result.y = radius * num2;
result.z = radius * num * num3;
return result;
}
private void CreateVolumeCloudMesh(int slices)
{
Vector3[] array = new Vector3[Clouds.segmentCount * Clouds.segmentCount * slices];
Vector2[] array2 = new Vector2[array.Length];
int[] array3 = new int[(Clouds.segmentCount - 1) * (Clouds.segmentCount - 1) * slices * 2 * 3];
Color[] array4 = new Color[array.Length];
float num = 1f / ((float)Clouds.segmentCount - 1f);
Vector3 vector = new Vector3(num * 2f, 1f / (float)Mathf.Clamp(slices - 1, 1, 999999) * Clouds.thickness, num * 2f);
float num2 = num;
int num3 = 0;
int num4 = 0;
int num5 = 0;
float f = 0f;
float num6 = -1f;
float num7 = 0f;
for (int i = 0; i < slices; i++)
{
num6 = -1f + (float)i * (2f / (float)slices);
num7 = ((!((float)i < (float)slices * 0.5f)) ? (2f - 1f / ((float)slices * 0.5f) * (float)(i + 1)) : (1f / ((float)slices * 0.5f) * (float)i));
if (slices == 1)
{
num7 = 1f;
}
for (int j = 0; j < Clouds.segmentCount; j++)
{
int num8 = Clouds.segmentCount * num3;
for (int k = 0; k < Clouds.segmentCount; k++)
{
if (Clouds.curved)
{
f = Vector3.Distance(new Vector3(vector.x * (float)k - 1f, 0f, vector.z * (float)j - 1f), Vector3.zero);
}
if (slices == 1)
{
array[k + num8] = new Vector3(vector.x * (float)k - 1f, Mathf.Pow(f, 2f) * Clouds.curvedIntensity, vector.z * (float)j - 1f);
}
else
{
array[k + num8] = new Vector3(vector.x * (float)k - 1f, vector.y * (float)i - Clouds.thickness / 2f + Mathf.Pow(f, 2f) * Clouds.curvedIntensity, vector.z * (float)j - 1f);
}
array2[k + num8] = new Vector2(num2 * (float)k, num2 * (float)j);
array4[k + num8] = new Vector4(num6, num6, num6, num7);
}
num3++;
if (j >= 1)
{
for (int l = 0; l < Clouds.segmentCount - 1; l++)
{
array3[num5] = l + num4 + i * Clouds.segmentCount;
array3[1 + num5] = Clouds.segmentCount + l + num4 + i * Clouds.segmentCount;
array3[2 + num5] = 1 + l + num4 + i * Clouds.segmentCount;
array3[3 + num5] = Clouds.segmentCount + 1 + l + num4 + i * Clouds.segmentCount;
array3[4 + num5] = 1 + l + num4 + i * Clouds.segmentCount;
array3[5 + num5] = Clouds.segmentCount + l + num4 + i * Clouds.segmentCount;
num5 += 6;
}
num4 += Clouds.segmentCount;
}
}
}
if (slices > 1)
{
Mesh mesh = new Mesh();
mesh.Clear();
mesh.name = "volumeClouds";
mesh.vertices = array;
mesh.triangles = array3;
mesh.uv = array2;
mesh.colors = array4;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
CalcMeshTangents(mesh);
Components.VolumeCloudsLayer1.GetComponent<MeshFilter>().mesh = mesh;
Components.VolumeCloudsLayer2.GetComponent<MeshFilter>().mesh = mesh;
}
else if (slices == 1)
{
Mesh mesh2 = new Mesh();
mesh2.Clear();
mesh2.name = "volumeCloudsShadows";
mesh2.vertices = array;
mesh2.triangles = array3;
mesh2.uv = array2;
mesh2.colors = array4;
mesh2.RecalculateNormals();
mesh2.RecalculateBounds();
CalcMeshTangents(mesh2);
Components.VolumeCloudsShadowsLayer1.GetComponent<MeshFilter>().mesh = mesh2;
Components.VolumeCloudsShadowsLayer2.GetComponent<MeshFilter>().mesh = mesh2;
}
}
public static void CalcMeshTangents(Mesh mesh)
{
int[] triangles = mesh.triangles;
Vector3[] vertices = mesh.vertices;
Vector2[] uv = mesh.uv;
Vector3[] normals = mesh.normals;
int num = triangles.Length;
int num2 = vertices.Length;
Vector3[] array = new Vector3[num2];
Vector3[] array2 = new Vector3[num2];
Vector4[] array3 = new Vector4[num2];
for (long num3 = 0L; num3 < num; num3 += 3)
{
long num4 = triangles[num3];
long num5 = triangles[num3 + 1];
long num6 = triangles[num3 + 2];
Vector3 vector = vertices[num4];
Vector3 vector2 = vertices[num5];
Vector3 vector3 = vertices[num6];
Vector2 vector4 = uv[num4];
Vector2 vector5 = uv[num5];
Vector2 vector6 = uv[num6];
float num7 = vector2.x - vector.x;
float num8 = vector3.x - vector.x;
float num9 = vector2.y - vector.y;
float num10 = vector3.y - vector.y;
float num11 = vector2.z - vector.z;
float num12 = vector3.z - vector.z;
float num13 = vector5.x - vector4.x;
float num14 = vector6.x - vector4.x;
float num15 = vector5.y - vector4.y;
float num16 = vector6.y - vector4.y;
float num17 = 1f / (num13 * num16 - num14 * num15);
Vector3 vector7 = new Vector3((num16 * num7 - num15 * num8) * num17, (num16 * num9 - num15 * num10) * num17, (num16 * num11 - num15 * num12) * num17);
Vector3 vector8 = new Vector3((num13 * num8 - num14 * num7) * num17, (num13 * num10 - num14 * num9) * num17, (num13 * num12 - num14 * num11) * num17);
array[num4] += vector7;
array[num5] += vector7;
array[num6] += vector7;
array2[num4] += vector8;
array2[num5] += vector8;
array2[num6] += vector8;
}
for (long num18 = 0L; num18 < num2; num18++)
{
Vector3 normal = normals[num18];
Vector3 tangent = array[num18];
Vector3.OrthoNormalize(ref normal, ref tangent);
array3[num18].x = tangent.x;
array3[num18].y = tangent.y;
array3[num18].z = tangent.z;
array3[num18].w = ((!(Vector3.Dot(Vector3.Cross(normal, tangent), array2[num18]) < 0f)) ? 1f : (-1f));
}
mesh.tangents = array3;
}
public void RegisterZone(EnviroZone zoneToAdd)
{
Weather.zones.Add(zoneToAdd);
}
public void EnterZone(EnviroZone zone)
{
Weather.currentActiveZone = zone;
}
public void ExitZone()
{
}
public void CreateWeatherEffectHolder()
{
if (Weather.VFXHolder == null)
{
GameObject gameObject = new GameObject();
gameObject.name = "VFX";
gameObject.transform.parent = EffectsHolder.transform;
gameObject.transform.localPosition = Vector3.zero;
Weather.VFXHolder = gameObject;
}
}
private void UpdateAudioSource(EnviroWeatherPrefab i)
{
if (i != null && i.Sfx != null)
{
if (i.Sfx == Weather.currentAudioSource.clip)
{
Weather.currentAudioSource.GetComponent<EnviroAudioSource>().FadeIn(i.Sfx);
}
else if (Weather.currentAudioSource == AudioSourceWeather)
{
AudioSourceWeather.GetComponent<EnviroAudioSource>().FadeOut();
AudioSourceWeather2.GetComponent<EnviroAudioSource>().FadeIn(i.Sfx);
Weather.currentAudioSource = AudioSourceWeather2;
}
else if (Weather.currentAudioSource == AudioSourceWeather2)
{
AudioSourceWeather2.GetComponent<EnviroAudioSource>().FadeOut();
AudioSourceWeather.GetComponent<EnviroAudioSource>().FadeIn(i.Sfx);
Weather.currentAudioSource = AudioSourceWeather;
}
}
else
{
AudioSourceWeather.GetComponent<EnviroAudioSource>().FadeOut();
AudioSourceWeather2.GetComponent<EnviroAudioSource>().FadeOut();
}
}
private void UpdateClouds(EnviroWeatherPrefab i)
{
if (i != null)
{
Lighting.SunWeatherMod = i.sunLightMod;
Clouds.FirstColor = Color.Lerp(Clouds.FirstColor, i.cloudConfig.FirstColor, Weather.cloudChangeSpeed);
Clouds.SecondColor = Color.Lerp(Clouds.SecondColor, i.cloudConfig.SecondColor, Weather.cloudChangeSpeed);
Clouds.DirectLightIntensity = Mathf.Lerp(Clouds.DirectLightIntensity, i.cloudConfig.DirectLightInfluence, Weather.cloudChangeSpeed);
Clouds.AmbientLightIntensity = Mathf.Lerp(Clouds.AmbientLightIntensity, i.cloudConfig.AmbientLightInfluence, Weather.cloudChangeSpeed);
Clouds.Coverage = Mathf.Lerp(Clouds.Coverage, i.cloudConfig.Coverage, Weather.cloudChangeSpeed);
Clouds.Density = Mathf.Lerp(Clouds.Density, i.cloudConfig.Density, Weather.cloudChangeSpeed);
Clouds.Alpha = Mathf.Lerp(Clouds.Alpha, i.cloudConfig.Alpha, Weather.cloudChangeSpeed);
Clouds.Speed1 = Mathf.Lerp(Clouds.Speed1, i.cloudConfig.Speed1, 0.00025f * Time.deltaTime);
Clouds.Speed2 = Mathf.Lerp(Clouds.Speed2, i.cloudConfig.Speed2, 0.00025f * Time.deltaTime);
Sky.weatherMod = Color.Lerp(Sky.weatherMod, i.WeatherColorMod, Weather.cloudChangeSpeed);
}
}
private void UpdateFog(EnviroWeatherPrefab i)
{
if (i != null)
{
if (Fog.Fogmode == FogMode.Linear)
{
RenderSettings.fogEndDistance = Mathf.Lerp(RenderSettings.fogEndDistance, i.fogDistance, 0.01f);
RenderSettings.fogStartDistance = Mathf.Lerp(RenderSettings.fogStartDistance, i.fogStartDistance, 0.01f);
}
else
{
RenderSettings.fogDensity = Mathf.Lerp(RenderSettings.fogDensity, i.fogDensity, 0.01f);
}
if (Fog.AdvancedFog)
{
Fog.skyFogHeight = Mathf.Lerp(Fog.skyFogHeight, i.SkyFogHeight, Weather.cloudChangeSpeed);
Fog.skyFogStrength = Mathf.Lerp(Fog.skyFogStrength, i.SkyFogIntensity, Weather.cloudChangeSpeed);
Fog.scatteringStrenght = Mathf.Lerp(Fog.scatteringStrenght, i.FogScatteringIntensity, Weather.cloudChangeSpeed);
}
}
}
private void UpdateEffectSystems(EnviroWeatherPrefab id)
{
if (!(id != null))
{
return;
}
for (int i = 0; i < id.effectParticleSystems.Count; i++)
{
float emissionRate = Mathf.Lerp(GetEmissionRate(id.effectParticleSystems[i]), id.effectEmmisionRates[i] * Quality.GlobalParticleEmissionRates, Weather.effectChangeSpeed);
SetEmissionRate(id.effectParticleSystems[i], emissionRate);
}
for (int j = 0; j < Weather.WeatherTemplates.Count; j++)
{
if (!(Weather.WeatherTemplates[j].gameObject != id.gameObject))
{
continue;
}
for (int k = 0; k < Weather.WeatherTemplates[j].effectParticleSystems.Count; k++)
{
float num = Mathf.Lerp(GetEmissionRate(Weather.WeatherTemplates[j].effectParticleSystems[k]), 0f, Weather.effectChangeSpeed);
if (num < 1f)
{
num = 0f;
}
SetEmissionRate(Weather.WeatherTemplates[j].effectParticleSystems[k], num);
}
}
Weather.windZone.windMain = id.WindStrenght;
Weather.curWetness = Weather.wetness;
Weather.wetness = Mathf.Lerp(Weather.curWetness, id.wetnessLevel, Weather.wetnessAccumulationSpeed * Time.deltaTime);
Weather.wetness = Mathf.Clamp(Weather.wetness, 0f, 1f);
Weather.curSnowStrenght = Weather.SnowStrenght;
Weather.SnowStrenght = Mathf.Lerp(Weather.curSnowStrenght, id.snowLevel, Weather.snowAccumulationSpeed * Time.deltaTime);
Weather.SnowStrenght = Mathf.Clamp(Weather.SnowStrenght, 0f, 1f);
}
public static float GetEmissionRate(ParticleSystem system)
{
return system.emission.rate.constantMax;
}
public static void SetEmissionRate(ParticleSystem sys, float emissionRate)
{
ParticleSystem.EmissionModule emission = sys.emission;
ParticleSystem.MinMaxCurve rate = emission.rate;
rate.constantMax = emissionRate;
emission.rate = rate;
}
private IEnumerator PlayThunderRandom()
{
yield return new WaitForSeconds(UnityEngine.Random.Range(10, 20));
int i = UnityEngine.Random.Range(0, Weather.ThunderSFX.Count);
AudioSourceThunder.clip = Weather.ThunderSFX[i];
AudioSourceThunder.loop = false;
AudioSourceThunder.Play();
Weather.LightningGenerator.Lightning();
Weather.thundersfx = 0;
}
public void SetWeatherOverwrite(int weatherId)
{
if (Weather.WeatherTemplates[weatherId] != Weather.currentActiveWeatherID)
{
Weather.currentActiveZone.currentActiveZoneWeatherID = Weather.WeatherTemplates[weatherId];
}
}
private void UpdateWeather()
{
if (Weather.currentActiveWeatherID != Weather.currentActiveZone.currentActiveZoneWeatherID)
{
Weather.lastActiveWeatherID = Weather.currentActiveWeatherID;
Weather.currentActiveWeatherID = Weather.currentActiveZone.currentActiveZoneWeatherID;
if (Weather.currentActiveWeatherID != null)
{
NotifyWeatherChanged(Weather.currentActiveWeatherID);
UpdateAudioSource(Weather.currentActiveWeatherID);
}
}
if (Weather.currentActiveWeatherID != null)
{
UpdateClouds(Weather.currentActiveWeatherID);
UpdateFog(Weather.currentActiveWeatherID);
UpdateEffectSystems(Weather.currentActiveWeatherID);
if (Weather.thundersfx == 0 && (bool)Weather.currentActiveWeatherID && Weather.currentActiveWeatherID.isLightningStorm)
{
Weather.thundersfx = 1;
StartCoroutine(PlayThunderRandom());
}
}
}
}