add weather and time

This commit is contained in:
XuGaoFeng
2026-05-09 09:10:52 +08:00
parent 48e0dea5e1
commit 0ca1b49fa7
639 changed files with 121558 additions and 102 deletions

View File

@@ -0,0 +1,597 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace Enviro
{
[Serializable]
public class EnviroWeather
{
public List<EnviroWeatherType> weatherTypes = new List<EnviroWeatherType>();
public float cloudsTransitionSpeed = 1f;
public float fogTransitionSpeed = 1f;
public float lightingTransitionSpeed = 1f;
public float skyTransitionSpeed = 1f;
public float effectsTransitionSpeed = 1f;
public float auroraTransitionSpeed = 1f;
public float environmentTransitionSpeed = 1f;
public float audioTransitionSpeed = 1f;
}
[Serializable]
[ExecuteInEditMode]
public class EnviroWeatherModule : EnviroModule
{
public Enviro.EnviroWeather Settings;
public EnviroWeatherModule preset;
public EnviroWeatherType targetWeatherType;
public float weatherBlendProgress = 0f;
//Zones
public bool globalAutoWeatherChange = true;
//Trigger
public BoxCollider triggerCollider;
public Rigidbody triggerRB;
//UI
public bool showWeatherPresetsControls,showTransitionControls,showZoneControls;
private bool instantTransition = false;
public override void Enable ()
{
if(EnviroManager.instance == null)
return;
if(targetWeatherType == null && Settings.weatherTypes.Count > 0)
targetWeatherType = Settings.weatherTypes[0];
if(EnviroManager.instance.defaultZone != null)
EnviroManager.instance.currentZone = EnviroManager.instance.defaultZone;
weatherBlendProgress = 1f;
Setup();
}
public override void Disable ()
{
if(EnviroManager.instance == null)
return;
Cleanup();
}
private void Setup()
{
if(EnviroManager.instance.gameObject.GetComponent<BoxCollider>() == null)
triggerCollider = EnviroManager.instance.gameObject.AddComponent<BoxCollider>();
else
triggerCollider = EnviroManager.instance.gameObject.GetComponent<BoxCollider>();
triggerCollider.isTrigger = true;
triggerCollider.size = new Vector3(0.1f,0.1f,0.1f);
if(EnviroManager.instance.gameObject.GetComponent<Rigidbody>() == null)
triggerRB = EnviroManager.instance.gameObject.AddComponent<Rigidbody>();
else
triggerRB = EnviroManager.instance.gameObject.GetComponent<Rigidbody>();
triggerRB.isKinematic = true;
}
private void Cleanup()
{
if(triggerCollider != null)
DestroyImmediate(triggerCollider);
if(triggerRB != null)
DestroyImmediate(triggerRB);
}
/// Adds weather type to the list or creates a new one.
public void CreateNewWeatherType()
{
EnviroWeatherType type = EnviroWeatherTypeCreation.CreateMyAsset();
Settings.weatherTypes.Add(type);
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(this);
#endif
}
/// Removes the weather type from the list.
public void RemoveWeatherType(EnviroWeatherType type)
{
Settings.weatherTypes.Remove(type);
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(this);
#endif
}
//Cleans the list from null entries.
public void CleanupList()
{
for (int i = 0; i < Settings.weatherTypes.Count; i++)
{
if(Settings.weatherTypes[i] == null)
Settings.weatherTypes.RemoveAt(i);
}
}
private IEnumerator InstantTransition()
{
yield return null;
instantTransition = false;
}
// Update Method
public override void UpdateModule ()
{
if(!active)
return;
if(EnviroManager.instance == null)
return;
//Instant changes when not playing or instant change is triggered
if(!Application.isPlaying || instantTransition)
{
if(targetWeatherType != null)
{
BlendVolumetricCloudsOverride(1f);
BlendFlatCloudsOverride(1f);
BlendLightingOverride(1f);
BlendSkyOverride(1f);
BlendEffectsOverride(1f);
BlendAuroraOverride(1f);
BlendFogOverride(1f);
BlendAudioOverride(1f);
BlendEnvironmentOverride(1f);
BlendLightningOverride(1f);
}
if(instantTransition)
instantTransition = false;
}
else
{
if(targetWeatherType != null)
{
BlendVolumetricCloudsOverride(Settings.cloudsTransitionSpeed * Time.deltaTime);
BlendFlatCloudsOverride(Settings.cloudsTransitionSpeed * Time.deltaTime);
BlendLightingOverride(Settings.lightingTransitionSpeed * Time.deltaTime);
BlendSkyOverride(Settings.skyTransitionSpeed * Time.deltaTime);
BlendEffectsOverride(Settings.effectsTransitionSpeed * Time.deltaTime);
BlendAuroraOverride(Settings.auroraTransitionSpeed * Time.deltaTime);
BlendFogOverride(Settings.fogTransitionSpeed * Time.deltaTime);
BlendAudioOverride(Settings.audioTransitionSpeed * Time.deltaTime);
BlendEnvironmentOverride(Settings.environmentTransitionSpeed * Time.deltaTime);
BlendLightningOverride(1f);
UpdateWeatherBlendProgress(Settings.cloudsTransitionSpeed * Time.deltaTime);
}
}
}
private void BlendLightingOverride(float blendTime)
{
EnviroLightingModule lighting = EnviroManager.instance.Lighting;
if(lighting != null)
{
lighting.Settings.directLightIntensityModifier = Mathf.Lerp(lighting.Settings.directLightIntensityModifier, targetWeatherType.lightingOverride.directLightIntensityModifier,blendTime);
lighting.Settings.ambientIntensityModifier = Mathf.Lerp(lighting.Settings.ambientIntensityModifier, targetWeatherType.lightingOverride.ambientIntensityModifier,blendTime);
lighting.Settings.shadowIntensity = Mathf.Lerp(lighting.Settings.shadowIntensity, targetWeatherType.lightingOverride.shadowIntensity,blendTime);
}
}
private void BlendSkyOverride(float blendTime)
{
EnviroSkyModule sky = EnviroManager.instance.Sky;
if(sky != null)
{
sky.Settings.mieScatteringMultiplier = Mathf.Lerp(sky.Settings.mieScatteringMultiplier, targetWeatherType.skyOverride.mieScatteringMultiplier,blendTime);
sky.Settings.skyColorExponent = Mathf.Lerp(sky.Settings.skyColorExponent, targetWeatherType.skyOverride.skyColorExponent,blendTime);
sky.Settings.skyColorTint = Color.Lerp(sky.Settings.skyColorTint, targetWeatherType.skyOverride.skyColorTint,blendTime);
}
}
private void BlendFogOverride(float blendTime)
{
EnviroFogModule fog = EnviroManager.instance.Fog;
if(fog != null)
{
fog.Settings.fogDensity = Mathf.Lerp(fog.Settings.fogDensity, targetWeatherType.fogOverride.fogDensity,blendTime);
fog.Settings.fogHeightFalloff = Mathf.Lerp(fog.Settings.fogHeightFalloff, targetWeatherType.fogOverride.fogHeightFalloff,blendTime);
fog.Settings.fogHeight = Mathf.Lerp(fog.Settings.fogHeight, targetWeatherType.fogOverride.fogHeight,blendTime);
fog.Settings.fogDensity2 = Mathf.Lerp(fog.Settings.fogDensity2, targetWeatherType.fogOverride.fogDensity2,blendTime);
fog.Settings.fogHeightFalloff2 = Mathf.Lerp(fog.Settings.fogHeightFalloff2, targetWeatherType.fogOverride.fogHeightFalloff2,blendTime);
fog.Settings.fogHeight2 = Mathf.Lerp(fog.Settings.fogHeight2, targetWeatherType.fogOverride.fogHeight2,blendTime);
fog.Settings.fogColorBlend = Mathf.Lerp(fog.Settings.fogColorBlend, targetWeatherType.fogOverride.fogColorBlend,blendTime);
fog.Settings.fogColorMod = Color.Lerp(fog.Settings.fogColorMod, targetWeatherType.fogOverride.fogColorMod,blendTime);
fog.Settings.scattering = Mathf.Lerp(fog.Settings.scattering, targetWeatherType.fogOverride.scattering,blendTime);
fog.Settings.extinction = Mathf.Lerp(fog.Settings.extinction, targetWeatherType.fogOverride.extinction,blendTime);
fog.Settings.anistropy = Mathf.Lerp(fog.Settings.anistropy, targetWeatherType.fogOverride.anistropy,blendTime);
#if ENVIRO_HDRP
fog.Settings.fogAttenuationDistance = Mathf.Lerp(fog.Settings.fogAttenuationDistance, targetWeatherType.fogOverride.fogAttenuationDistance,blendTime);
fog.Settings.baseHeight = Mathf.Lerp(fog.Settings.baseHeight, targetWeatherType.fogOverride.baseHeight,blendTime);
fog.Settings.maxHeight = Mathf.Lerp(fog.Settings.maxHeight, targetWeatherType.fogOverride.maxHeight,blendTime);
fog.Settings.ambientDimmer = Mathf.Lerp(fog.Settings.ambientDimmer, targetWeatherType.fogOverride.ambientDimmer,blendTime);
fog.Settings.directLightMultiplier = Mathf.Lerp(fog.Settings.directLightMultiplier, targetWeatherType.fogOverride.directLightMultiplier,blendTime);
fog.Settings.directLightShadowdimmer = Mathf.Lerp(fog.Settings.ambientDimmer, targetWeatherType.fogOverride.directLightShadowdimmer,blendTime);
#endif
fog.Settings.unityFogDensity = Mathf.Lerp(fog.Settings.unityFogDensity, targetWeatherType.fogOverride.unityFogDensity,blendTime);
fog.Settings.unityFogStartDistance = Mathf.Lerp(fog.Settings.unityFogStartDistance, targetWeatherType.fogOverride.unityFogStartDistance,blendTime);
fog.Settings.unityFogEndDistance = Mathf.Lerp(fog.Settings.unityFogEndDistance, targetWeatherType.fogOverride.unityFogEndDistance,blendTime);
}
}
private void BlendEffectsOverride(float blendTime)
{
EnviroEffectsModule effects = EnviroManager.instance.Effects;
if(effects != null)
{
for (int i = 0; i < effects.Settings.effectTypes.Count; i++)
{
bool hasOverride = false;
for(int a = 0; a < targetWeatherType.effectsOverride.effectsOverride.Count; a++)
{
if(effects.Settings.effectTypes[i].name == targetWeatherType.effectsOverride.effectsOverride[a].name)
{
effects.Settings.effectTypes[i].emissionRate = Mathf.Lerp(effects.Settings.effectTypes[i].emissionRate, targetWeatherType.effectsOverride.effectsOverride[a].emission,blendTime);
hasOverride = true;
}
}
if(!hasOverride)
{
effects.Settings.effectTypes[i].emissionRate = Mathf.Lerp(effects.Settings.effectTypes[i].emissionRate, 0f,blendTime);
}
}
}
}
private void BlendVolumetricCloudsOverride(float blendTime)
{
EnviroVolumetricCloudsModule clouds = EnviroManager.instance.VolumetricClouds;
if(clouds != null)
{
clouds.settingsGlobal.ambientLighIntensity = Mathf.Lerp(clouds.settingsGlobal.ambientLighIntensity, targetWeatherType.cloudsOverride.ambientLightIntensity,blendTime);
clouds.settingsVolume.coverage = Mathf.Lerp(clouds.settingsVolume.coverage, targetWeatherType.cloudsOverride.coverage,blendTime);
clouds.settingsVolume.dilateCoverage = Mathf.Lerp(clouds.settingsVolume.dilateCoverage, targetWeatherType.cloudsOverride.dilateCoverage,blendTime);
clouds.settingsVolume.dilateType = Mathf.Lerp(clouds.settingsVolume.dilateType, targetWeatherType.cloudsOverride.dilateType,blendTime);
clouds.settingsVolume.cloudsTypeModifier = Mathf.Lerp(clouds.settingsVolume.cloudsTypeModifier, targetWeatherType.cloudsOverride.typeModifier,blendTime);
clouds.settingsVolume.cloudTypeShaping = Mathf.Lerp(clouds.settingsVolume.cloudTypeShaping, targetWeatherType.cloudsOverride.cloudTypeShaping,blendTime);
clouds.settingsVolume.silverLiningIntensity = Mathf.Lerp(clouds.settingsVolume.silverLiningIntensity, targetWeatherType.cloudsOverride.silverLiningIntensity,blendTime);
clouds.settingsVolume.edgeHighlightStrength = Mathf.Lerp(clouds.settingsVolume.edgeHighlightStrength, targetWeatherType.cloudsOverride.edgeHighlightStrength,blendTime);
clouds.settingsVolume.bottomShape = Mathf.Lerp(clouds.settingsVolume.bottomShape, targetWeatherType.cloudsOverride.bottomShape,blendTime);
clouds.settingsVolume.midShape = Mathf.Lerp(clouds.settingsVolume.midShape, targetWeatherType.cloudsOverride.midShape,blendTime);
clouds.settingsVolume.topShape = Mathf.Lerp(clouds.settingsVolume.topShape, targetWeatherType.cloudsOverride.topShape,blendTime);
clouds.settingsVolume.topLayer = Mathf.Lerp(clouds.settingsVolume.topLayer, targetWeatherType.cloudsOverride.topLayer,blendTime);
clouds.settingsVolume.rampShape = Mathf.Lerp(clouds.settingsVolume.rampShape, targetWeatherType.cloudsOverride.rampShape,blendTime);
clouds.settingsVolume.scatteringIntensity = Mathf.Lerp(clouds.settingsVolume.scatteringIntensity, targetWeatherType.cloudsOverride.scatteringIntensity,blendTime);
clouds.settingsVolume.multiScatterStrength = Mathf.Lerp(clouds.settingsVolume.multiScatterStrength, targetWeatherType.cloudsOverride.multiScatterStrength,blendTime);
clouds.settingsVolume.multiScatterFalloff = Mathf.Lerp(clouds.settingsVolume.multiScatterFalloff, targetWeatherType.cloudsOverride.multiScatterFalloff,blendTime);
clouds.settingsVolume.ambientFloor = Mathf.Lerp(clouds.settingsVolume.ambientFloor, targetWeatherType.cloudsOverride.ambientFloor,blendTime);
clouds.settingsVolume.directIndirectBalance = Mathf.Lerp(clouds.settingsVolume.directIndirectBalance, targetWeatherType.cloudsOverride.directIndirectBalance,blendTime);
clouds.settingsVolume.exposure = Mathf.Lerp(clouds.settingsVolume.exposure, targetWeatherType.cloudsOverride.exposure,blendTime);
clouds.settingsVolume.silverLiningSpread = Mathf.Lerp(clouds.settingsVolume.silverLiningSpread, targetWeatherType.cloudsOverride.silverLiningSpread,blendTime);
clouds.settingsVolume.absorbtion = Mathf.Lerp(clouds.settingsVolume.absorbtion, targetWeatherType.cloudsOverride.ligthAbsorbtion,blendTime);
clouds.settingsVolume.density = Mathf.Lerp(clouds.settingsVolume.density, targetWeatherType.cloudsOverride.density,blendTime);
clouds.settingsVolume.densitySmoothness = Mathf.Lerp(clouds.settingsVolume.densitySmoothness, targetWeatherType.cloudsOverride.densitySmoothness,blendTime);
clouds.settingsVolume.baseErosionIntensity = Mathf.Lerp(clouds.settingsVolume.baseErosionIntensity, targetWeatherType.cloudsOverride.baseErosionIntensity,blendTime);
clouds.settingsVolume.detailErosionIntensity = Mathf.Lerp(clouds.settingsVolume.detailErosionIntensity, targetWeatherType.cloudsOverride.detailErosionIntensity,blendTime);
clouds.settingsVolume.curlIntensity = Mathf.Lerp(clouds.settingsVolume.curlIntensity, targetWeatherType.cloudsOverride.curlIntensity,blendTime);
clouds.settingsVolume.baseNoiseMultiplier = Mathf.Lerp(clouds.settingsVolume.baseNoiseMultiplier, targetWeatherType.cloudsOverride.baseNoiseMultiplier,blendTime);
clouds.settingsVolume.detailNoiseMultiplier = Mathf.Lerp(clouds.settingsVolume.detailNoiseMultiplier, targetWeatherType.cloudsOverride.detailNoiseMultiplier,blendTime);
}
}
private void BlendFlatCloudsOverride(float blendTime)
{
EnviroFlatCloudsModule flatClouds = EnviroManager.instance.FlatClouds;
if(flatClouds != null)
{
flatClouds.settings.cirrusCloudsAlpha = Mathf.Lerp(flatClouds.settings.cirrusCloudsAlpha, targetWeatherType.flatCloudsOverride.cirrusCloudsAlpha,blendTime);
flatClouds.settings.cirrusCloudsCoverage = Mathf.Lerp(flatClouds.settings.cirrusCloudsCoverage, targetWeatherType.flatCloudsOverride.cirrusCloudsCoverage,blendTime);
flatClouds.settings.cirrusCloudsColorPower = Mathf.Lerp(flatClouds.settings.cirrusCloudsColorPower, targetWeatherType.flatCloudsOverride.cirrusCloudsColorPower,blendTime);
flatClouds.settings.flatCloudsCoverage = Mathf.Lerp(flatClouds.settings.flatCloudsCoverage, targetWeatherType.flatCloudsOverride.flatCloudsCoverage,blendTime);
flatClouds.settings.flatCloudsDensity = Mathf.Lerp(flatClouds.settings.flatCloudsDensity, targetWeatherType.flatCloudsOverride.flatCloudsDensity,blendTime);
flatClouds.settings.flatCloudsLightIntensity = Mathf.Lerp(flatClouds.settings.flatCloudsLightIntensity, targetWeatherType.flatCloudsOverride.flatCloudsLightIntensity,blendTime);
flatClouds.settings.flatCloudsAmbientIntensity = Mathf.Lerp(flatClouds.settings.flatCloudsAmbientIntensity, targetWeatherType.flatCloudsOverride.flatCloudsAmbientIntensity,blendTime);
flatClouds.settings.flatCloudsShadowIntensity = Mathf.Lerp(flatClouds.settings.flatCloudsShadowIntensity, targetWeatherType.flatCloudsOverride.flatCloudsShadowIntensity,blendTime);
}
}
private void BlendAuroraOverride(float blendTime)
{
EnviroAuroraModule aurora = EnviroManager.instance.Aurora;
if(aurora != null)
{
aurora.Settings.auroraIntensityModifier = Mathf.Lerp(aurora.Settings.auroraIntensityModifier, targetWeatherType.auroraOverride.auroraIntensity,blendTime);
}
}
private void BlendEnvironmentOverride(float blendTime)
{
EnviroEnvironmentModule environment = EnviroManager.instance.Environment;
if(environment != null)
{
environment.Settings.temperatureWeatherMod = Mathf.Lerp(environment.Settings.temperatureWeatherMod, targetWeatherType.environmentOverride.temperatureWeatherMod,blendTime);
environment.Settings.wetnessTarget = Mathf.Lerp(environment.Settings.wetnessTarget, targetWeatherType.environmentOverride.wetnessTarget,blendTime);
environment.Settings.snowTarget = Mathf.Lerp(environment.Settings.snowTarget, targetWeatherType.environmentOverride.snowTarget,blendTime);
environment.Settings.windDirectionX = Mathf.Lerp(environment.Settings.windDirectionX, targetWeatherType.environmentOverride.windDirectionX,blendTime);
environment.Settings.windDirectionY = Mathf.Lerp(environment.Settings.windDirectionY, targetWeatherType.environmentOverride.windDirectionY,blendTime);
environment.Settings.windSpeed = Mathf.Lerp(environment.Settings.windSpeed, targetWeatherType.environmentOverride.windSpeed,blendTime);
environment.Settings.windTurbulence = Mathf.Lerp(environment.Settings.windTurbulence, targetWeatherType.environmentOverride.windTurbulence,blendTime);
}
}
private void BlendAudioOverride(float blendTime)
{
EnviroAudioModule audio = EnviroManager.instance.Audio;
if(audio != null)
{
for(int i = 0; i < audio.Settings.ambientClips.Count; i++)
{
bool hasOverride = false;
for(int a = 0; a < targetWeatherType.audioOverride.ambientOverride.Count; a++)
{
if(targetWeatherType.audioOverride.ambientOverride[a].name == audio.Settings.ambientClips[i].name)
{
audio.Settings.ambientClips[i].volume = Mathf.Lerp(audio.Settings.ambientClips[i].volume ,targetWeatherType.audioOverride.ambientOverride[a].volume,blendTime);
hasOverride = true;
}
}
if(!hasOverride)
audio.Settings.ambientClips[i].volume = Mathf.Lerp(audio.Settings.ambientClips[i].volume ,0f,blendTime);
}
for(int i = 0; i < audio.Settings.weatherClips.Count; i++)
{
bool hasOverride = false;
for(int a = 0; a < targetWeatherType.audioOverride.weatherOverride.Count; a++)
{
if(targetWeatherType.audioOverride.weatherOverride[a].name == audio.Settings.weatherClips[i].name)
{
audio.Settings.weatherClips[i].volume = Mathf.Lerp(audio.Settings.weatherClips[i].volume ,targetWeatherType.audioOverride.weatherOverride[a].volume,blendTime);
hasOverride = true;
}
}
if(!hasOverride)
audio.Settings.weatherClips[i].volume = Mathf.Lerp(audio.Settings.weatherClips[i].volume ,0f,blendTime);
}
}
}
private void BlendLightningOverride(float blendTime)
{
EnviroLightningModule lightning = EnviroManager.instance.Lightning;
if(lightning != null)
{
lightning.Settings.lightningStorm = targetWeatherType.lightningOverride.lightningStorm;
lightning.Settings.randomLightingDelay = Mathf.Lerp(lightning.Settings.randomLightingDelay, targetWeatherType.lightningOverride.randomLightningDelay,blendTime);
}
}
private void UpdateWeatherBlendProgress(float blendTime)
{
//float currentCov = Math.Abs(EnviroManager.instance.VolumetricClouds.settingsVolume.coverage);
//float targetCov = Math.Abs(targetWeatherType.cloudsOverride.coverageLayer1);
//weatherBlendProgress = Mathf.Lerp(1f,0f,targetCov - currentCov);
weatherBlendProgress = Mathf.Lerp(weatherBlendProgress, 1f,blendTime);
weatherBlendProgress = Mathf.Clamp01(weatherBlendProgress);
if(weatherBlendProgress >= 0.99)
weatherBlendProgress = 1f;
}
//Changes the Weather to new type.
public void ChangeWeather(EnviroWeatherType type)
{
if(targetWeatherType != type)
{
EnviroManager.instance.NotifyWeatherChanged(type);
EnviroManager.instance.NotifyZoneWeatherChanged(type,null);
}
if(EnviroManager.instance.currentZone != null)
EnviroManager.instance.currentZone.currentWeatherType = type;
targetWeatherType = type;
weatherBlendProgress = 0f;
}
public void ChangeWeather(string typeName)
{
for(int i = 0; i < Settings.weatherTypes.Count; i++)
{
if(Settings.weatherTypes[i].name == typeName)
{
if(targetWeatherType != Settings.weatherTypes[i])
{
EnviroManager.instance.NotifyWeatherChanged(Settings.weatherTypes[i]);
EnviroManager.instance.NotifyZoneWeatherChanged(Settings.weatherTypes[i],null);
}
if(EnviroManager.instance.currentZone != null)
EnviroManager.instance.currentZone.currentWeatherType = Settings.weatherTypes[i];
targetWeatherType = Settings.weatherTypes[i];
weatherBlendProgress = 0f;
}
}
}
public void ChangeWeather(int index)
{
for(int i = 0; i < Settings.weatherTypes.Count; i++)
{
if(i == index)
{
if(targetWeatherType != Settings.weatherTypes[i])
{
EnviroManager.instance.NotifyWeatherChanged(Settings.weatherTypes[i]);
EnviroManager.instance.NotifyZoneWeatherChanged(Settings.weatherTypes[i],null);
}
if(EnviroManager.instance.currentZone != null)
EnviroManager.instance.currentZone.currentWeatherType = Settings.weatherTypes[i];
targetWeatherType = Settings.weatherTypes[i];
weatherBlendProgress = 0f;
return;
}
}
}
public void ChangeZoneWeather(int weather, int zone)
{
if(EnviroManager.instance.zones.Count >= zone && Settings.weatherTypes.Count >= weather)
{
EnviroManager.instance.zones[zone].currentWeatherType = Settings.weatherTypes[weather];
EnviroManager.instance.NotifyZoneWeatherChanged(Settings.weatherTypes[weather],EnviroManager.instance.zones[zone]);
}
}
public void ChangeWeatherInstant(EnviroWeatherType type)
{
if(targetWeatherType != type)
{
EnviroManager.instance.NotifyWeatherChanged(type);
EnviroManager.instance.NotifyZoneWeatherChanged(type,null);
}
if(EnviroManager.instance.currentZone != null)
EnviroManager.instance.currentZone.currentWeatherType = type;
targetWeatherType = type;
weatherBlendProgress = 1f;
instantTransition = true;
}
public void ChangeWeatherInstant(string typeName)
{
for(int i = 0; i < Settings.weatherTypes.Count; i++)
{
if(Settings.weatherTypes[i].name == typeName)
{
if(targetWeatherType != Settings.weatherTypes[i])
{
EnviroManager.instance.NotifyWeatherChanged(Settings.weatherTypes[i]);
EnviroManager.instance.NotifyZoneWeatherChanged(Settings.weatherTypes[i],null);
}
if(EnviroManager.instance.currentZone != null)
EnviroManager.instance.currentZone.currentWeatherType = Settings.weatherTypes[i];
targetWeatherType = Settings.weatherTypes[i];
weatherBlendProgress = 1f;
instantTransition = true;
}
}
}
public void ChangeWeatherInstant(int index)
{
for(int i = 0; i < Settings.weatherTypes.Count; i++)
{
if(i == index)
{
if(targetWeatherType != Settings.weatherTypes[i])
{
EnviroManager.instance.NotifyWeatherChanged(Settings.weatherTypes[i]);
EnviroManager.instance.NotifyZoneWeatherChanged(Settings.weatherTypes[i],null);
}
if(EnviroManager.instance.currentZone != null)
EnviroManager.instance.currentZone.currentWeatherType = Settings.weatherTypes[i];
targetWeatherType = Settings.weatherTypes[i];
weatherBlendProgress = 1f;
instantTransition = true;
return;
}
}
}
public void RegisterZone(EnviroZone zone)
{
EnviroManager.instance.zones.Add(zone);
}
public void RemoveZone(EnviroZone zone)
{
if(EnviroManager.instance.zones.Contains(zone))
EnviroManager.instance.zones.Remove(zone);
}
//Save and Load
public void LoadModuleValues ()
{
if(preset != null)
{
Settings = JsonUtility.FromJson<Enviro.EnviroWeather>(JsonUtility.ToJson(preset.Settings));
}
else
{
Debug.Log("Please assign a saved module to load from!");
}
}
public void SaveModuleValues ()
{
#if UNITY_EDITOR
EnviroWeatherModule t = ScriptableObject.CreateInstance<EnviroWeatherModule>();
t.name = "Weather Module";
t.Settings = JsonUtility.FromJson<Enviro.EnviroWeather>(JsonUtility.ToJson(Settings));
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(EnviroHelper.assetPath + "/New " + t.name + ".asset");
UnityEditor.AssetDatabase.CreateAsset(t, assetPathAndName);
UnityEditor.AssetDatabase.SaveAssets();
UnityEditor.AssetDatabase.Refresh();
#endif
}
public void SaveModuleValues (EnviroWeatherModule module)
{
module.Settings = JsonUtility.FromJson<Enviro.EnviroWeather>(JsonUtility.ToJson(Settings));
#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(module);
UnityEditor.AssetDatabase.SaveAssets();
#endif
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: b3ccdfb360c52f049bf71126aa74826f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.1.2
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Weather/EnviroWeatherModule.cs
uploadId: 660896

View File

@@ -0,0 +1,300 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace Enviro
{
[Serializable]
public class EnviroWeatherTypeCloudsOverride
{
public float ambientLightIntensity = 1f;
public float coverage = 0f;
public float dilateCoverage = 0.5f;
public float dilateType = 0.5f;
public float typeModifier = 0.5f;
public float cloudTypeShaping = 1.0f;
public float scatteringIntensity = 1.0f;
public float multiScatterStrength = 0.5f;
public float multiScatterFalloff = 0.02f;
public float ambientFloor = 0.02f;
public float directIndirectBalance = 0.5f;
public float exposure = 1f;
public float silverLiningSpread = 0.3f;
public float silverLiningIntensity = 1f;
public float edgeHighlightStrength = 1f;
public float ligthAbsorbtion = 0.5f;
public float density = 1.0f;
public float densitySmoothness = 1.0f;
public float baseErosionIntensity = 0.4f;
public float baseNoiseMultiplier = 1f;
public float detailErosionIntensity = 0.25f;
public float detailNoiseMultiplier = 1f;
public float curlIntensity = 0.2f;
public float bottomShape = 0.0f;
public float midShape = 0.0f;
public float topShape = 0.0f;
public float topLayer = 0.0f;
public float rampShape = 1.0f;
}
[Serializable]
public class EnviroWeatherTypeFlatCloudsOverride
{
public float cirrusCloudsAlpha = 0.5f;
public float cirrusCloudsCoverage = 0.5f;
public float cirrusCloudsColorPower = 1.0f;
public float flatCloudsCoverage = 1.0f;
public float flatCloudsDensity = 1.0f;
public float flatCloudsLightIntensity = 1.0f;
public float flatCloudsAmbientIntensity = 1.0f;
public float flatCloudsShadowIntensity = 0.6f;
public int flatCloudsShadowSteps = 8;
}
[Serializable]
public class EnviroWeatherTypeLightingOverride
{
public float directLightIntensityModifier = 1.0f;
public float ambientIntensityModifier = 1.0f;
public float shadowIntensity = 1.0f;
}
[Serializable]
public class EnviroWeatherTypeSkyOverride
{
public float intensity = 1.0f;
public float mieScatteringMultiplier = 1.0f;
public float skyColorExponent = 1.0f;
public Color skyColorTint = Color.white;
}
[Serializable]
public class EnviroAudioOverrideType
{
public bool showEditor;
public string name;
public float volume;
public bool spring;
public bool summer;
public bool autumn;
public bool winter;
}
[Serializable]
public class EnviroWeatherTypeAudioOverride
{
public List<EnviroAudioOverrideType> ambientOverride = new List<EnviroAudioOverrideType>();
public List<EnviroAudioOverrideType> weatherOverride = new List<EnviroAudioOverrideType>();
}
[Serializable]
public class EnviroWeatherTypeFogOverride
{
public float fogDensity = 0.02f;
public float fogHeightFalloff = 0.2f;
public float fogHeight = 0.0f;
public float fogDensity2 = 0.02f;
public float fogHeightFalloff2 = 0.2f;
public float fogHeight2;
public float fogColorBlend = 0.5f;
public Color fogColorMod = Color.white;
public float scattering = 0.015f;
public float extinction = 0.01f;
public float anistropy = 0.6f;
#if ENVIRO_HDRP
public float fogAttenuationDistance = 400f;
public float maxHeight = 250f;
public float baseHeight = 0f;
public float ambientDimmer = 1f;
public float directLightMultiplier = 1f;
public float directLightShadowdimmer = 1f;
#endif
public float unityFogDensity = 0.002f;
public float unityFogStartDistance = 0f;
public float unityFogEndDistance = 1000f;
}
[Serializable]
public class EnviroEffectsOverrideType
{
public bool showEditor;
public string name;
public float emission;
}
[Serializable]
public class EnviroWeatherTypeEffectsOverride
{
public List<EnviroEffectsOverrideType> effectsOverride = new List<EnviroEffectsOverrideType>();
}
[Serializable]
public class EnviroWeatherTypeAuroraOverride
{
public float auroraIntensity = 1f;
}
[Serializable]
public class EnviroWeatherTypeEnvironmentOverride
{
public float temperatureWeatherMod = 0f;
public float wetnessTarget = 0f;
public float snowTarget = 0f;
public float windDirectionX = 1f;
public float windDirectionY = -1f;
public float windSpeed = 0.25f;
public float windTurbulence = 0.25f;
}
[Serializable]
public class EnviroWeatherTypeLightningOverride
{
public bool lightningStorm = false;
public float randomLightningDelay = 1f;
}
[Serializable]
public class EnviroWeatherType : ScriptableObject
{
//Inspector
public bool showEditor, showEffectControls, showCloudControls, showFlatCloudControls, showFogControls, showSkyControls, showLightingControls, showAuroraControls,showEnvironmentControls, showAudioControls, showAmbientAudioControls, showWeatherAudioControls,showLightningControls;
public EnviroWeatherTypeCloudsOverride cloudsOverride;
public EnviroWeatherTypeFlatCloudsOverride flatCloudsOverride;
public EnviroWeatherTypeLightingOverride lightingOverride;
public EnviroWeatherTypeSkyOverride skyOverride;
public EnviroWeatherTypeFogOverride fogOverride;
public EnviroWeatherTypeAuroraOverride auroraOverride;
public EnviroWeatherTypeEffectsOverride effectsOverride;
public EnviroWeatherTypeAudioOverride audioOverride;
public EnviroWeatherTypeLightningOverride lightningOverride;
public EnviroWeatherTypeEnvironmentOverride environmentOverride;
}
public class EnviroWeatherTypeCreation {
#if UNITY_EDITOR
[UnityEditor.MenuItem("Assets/Create/Enviro3/Weather")]
#endif
public static EnviroWeatherType CreateMyAsset()
{
EnviroWeatherType wpreset = ScriptableObject.CreateInstance<EnviroWeatherType>();
#if UNITY_EDITOR
// Create and save the new profile with unique name
string path = UnityEditor.AssetDatabase.GetAssetPath (UnityEditor.Selection.activeObject);
if (path == "")
{
path = EnviroHelper.assetPath + "/Profiles/Weather Types";
}
string assetPathAndName = UnityEditor.AssetDatabase.GenerateUniqueAssetPath (path + "/New " + "Weather Type" + ".asset");
UnityEditor.AssetDatabase.CreateAsset (wpreset, assetPathAndName);
UnityEditor.AssetDatabase.SaveAssets ();
UnityEditor.AssetDatabase.Refresh();
#endif
return wpreset;
}
public static GameObject GetAssetPrefab(string name)
{
#if UNITY_EDITOR
string[] assets = UnityEditor.AssetDatabase.FindAssets(name, null);
for (int idx = 0; idx < assets.Length; idx++)
{
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]);
if (path.Contains(".prefab"))
{
return UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>(path);
}
}
#endif
return null;
}
public static Cubemap GetAssetCubemap(string name)
{
#if UNITY_EDITOR
string[] assets = UnityEditor.AssetDatabase.FindAssets(name, null);
for (int idx = 0; idx < assets.Length; idx++)
{
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]);
if (path.Contains(".png"))
{
return UnityEditor.AssetDatabase.LoadAssetAtPath<Cubemap>(path);
}
}
#endif
return null;
}
public static Texture GetAssetTexture(string name)
{
#if UNITY_EDITOR
string[] assets = UnityEditor.AssetDatabase.FindAssets(name, null);
for (int idx = 0; idx < assets.Length; idx++)
{
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(assets[idx]);
if (path.Length > 0)
{
return UnityEditor.AssetDatabase.LoadAssetAtPath<Texture>(path);
}
}
#endif
return null;
}
public static Gradient CreateGradient()
{
Gradient nG = new Gradient ();
GradientColorKey[] gClr = new GradientColorKey[2];
GradientAlphaKey[] gAlpha = new GradientAlphaKey[2];
gClr [0].color = Color.white;
gClr [0].time = 0f;
gClr [1].color = Color.white;
gClr [1].time = 0f;
gAlpha [0].alpha = 0f;
gAlpha [0].time = 0f;
gAlpha [1].alpha = 0f;
gAlpha [1].time = 1f;
nG.SetKeys (gClr, gAlpha);
return nG;
}
public static Color GetColor (string hex)
{
Color clr = new Color ();
ColorUtility.TryParseHtmlString (hex, out clr);
return clr;
}
public static Keyframe CreateKey (float value, float time)
{
Keyframe k = new Keyframe();
k.value = value;
k.time = time;
return k;
}
public static Keyframe CreateKey (float value, float time, float inTangent, float outTangent)
{
Keyframe k = new Keyframe();
k.value = value;
k.time = time;
k.inTangent = inTangent;
k.outTangent = outTangent;
return k;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 5cbac6e678443724c9bd2baf5d564c1d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.1.2
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Weather/EnviroWeatherType.cs
uploadId: 660896

View File

@@ -0,0 +1,267 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace Enviro
{
[Serializable]
public class EnviroZoneWeather
{
public bool showEditor;
public EnviroWeatherType weatherType;
public float probability = 50f;
public bool seasonalProbability = false;
public float probabilitySpring = 50f;
public float probabilitySummer = 50f;
public float probabilityAutumn = 50f;
public float probabilityWinter = 50f;
}
[AddComponentMenu("Enviro 3/Weather Zone")]
[ExecuteInEditMode]
public class EnviroZone : MonoBehaviour
{
public EnviroWeatherType currentWeatherType;
public EnviroWeatherType nextWeatherType;
public bool autoWeatherChanges = true;
public float weatherChangeIntervall = 2f;
public double nextWeatherUpdate;
public List<EnviroZoneWeather> weatherTypeList = new List<EnviroZoneWeather>();
public Vector3 zoneScale = Vector3.one;
public Color zoneGizmoColor;
private BoxCollider zoneCollider;
void OnEnable()
{
if(zoneCollider == null)
{
zoneCollider = gameObject.GetComponent<BoxCollider>();
if(zoneCollider == null)
zoneCollider = gameObject.AddComponent<BoxCollider>();
}
zoneCollider.isTrigger = true;
if(EnviroManager.instance != null && EnviroManager.instance.Weather != null)
{
bool addedToMgr = false;
for(int i = 0; i < EnviroManager.instance.zones.Count; i++)
{
if(EnviroManager.instance.zones[i] == this)
{
addedToMgr = true;
break;
}
}
if(!addedToMgr)
EnviroManager.instance.Weather.RegisterZone(this);
}
nextWeatherUpdate = EnviroManager.instance.Time.GetDateInHours() + weatherChangeIntervall;
}
void OnDisable()
{
if(EnviroManager.instance != null && EnviroManager.instance.Weather != null)
{
for(int i = 0; i < EnviroManager.instance.zones.Count; i++)
{
if(EnviroManager.instance.zones[i] == this)
EnviroManager.instance.Weather.RemoveZone(this);
}
}
}
public void UpdateZoneScale ()
{
zoneCollider.size = zoneScale;
}
// Adds a new weather type to the zone.
public void AddWeatherType(EnviroWeatherType wType)
{
EnviroZoneWeather weatherTypeEntry = new EnviroZoneWeather();
weatherTypeEntry.weatherType = wType;
weatherTypeList.Add(weatherTypeEntry);
}
// Removes a weather type from the zone.
public void RemoveWeatherZoneType(EnviroZoneWeather wType)
{
weatherTypeList.Remove(wType);
}
// Changes the weather of the zone instantly.
public void ChangeZoneWeatherInstant (EnviroWeatherType type)
{
if(EnviroManager.instance != null && currentWeatherType != type)
{
EnviroManager.instance.NotifyZoneWeatherChanged(type,this);
if(EnviroManager.instance.currentZone == this && EnviroManager.instance.Weather != null)
EnviroManager.instance.Weather.targetWeatherType = type;
}
currentWeatherType = type;
}
// Changes the weather of the zone to the type for next weather update.
public void ChangeZoneWeather (EnviroWeatherType type)
{
nextWeatherType = type;
}
private void ChooseNextWeatherRandom ()
{
float rand = UnityEngine.Random.Range(0f,100f * weatherTypeList.Count);
bool nextWeatherFound = false;
for (int i = 0; i < weatherTypeList.Count; i++)
{
if(weatherTypeList[i].seasonalProbability == true && EnviroManager.instance != null && EnviroManager.instance.Environment != null)
{
switch (EnviroManager.instance.Environment.Settings.season)
{
case Enviro.EnviroEnvironment.Seasons.Spring:
if(rand <= weatherTypeList[i].probabilitySpring * weatherTypeList.Count)
{
ChangeZoneWeather(weatherTypeList[i].weatherType);
nextWeatherFound = true;
return;
}
break;
case Enviro.EnviroEnvironment.Seasons.Summer:
if(rand <= weatherTypeList[i].probabilitySummer * weatherTypeList.Count)
{
ChangeZoneWeather(weatherTypeList[i].weatherType);
nextWeatherFound = true;
return;
}
break;
case Enviro.EnviroEnvironment.Seasons.Autumn:
if(rand <= weatherTypeList[i].probabilityAutumn * weatherTypeList.Count)
{
ChangeZoneWeather(weatherTypeList[i].weatherType);
nextWeatherFound = true;
return;
}
break;
case Enviro.EnviroEnvironment.Seasons.Winter:
if(rand <= weatherTypeList[i].probabilityWinter * weatherTypeList.Count)
{
ChangeZoneWeather(weatherTypeList[i].weatherType);
nextWeatherFound = true;
return;
}
break;
}
}
else
{
if(rand <= weatherTypeList[i].probability * weatherTypeList.Count)
{
ChangeZoneWeather(weatherTypeList[i].weatherType);
nextWeatherFound = true;
return;
}
}
rand -= 100f;
}
if(!nextWeatherFound)
ChangeZoneWeather(currentWeatherType);
}
private void UpdateZoneWeather()
{
if(EnviroManager.instance.Time != null)
{
double currentDate = EnviroManager.instance.Time.GetDateInHours();
if(currentDate >= nextWeatherUpdate)
{
if(nextWeatherType != null)
ChangeZoneWeatherInstant(nextWeatherType);
else
ChangeZoneWeatherInstant(currentWeatherType);
//Get next weather
ChooseNextWeatherRandom ();
nextWeatherUpdate = currentDate + weatherChangeIntervall;
}
}
}
void Update()
{
UpdateZoneScale ();
if(!Application.isPlaying)
return;
if (EnviroManager.instance == null || EnviroManager.instance.Weather == null)
return;
if(autoWeatherChanges && EnviroManager.instance.Weather.globalAutoWeatherChange)
UpdateZoneWeather();
//Forces the weather change in Enviro when this zone is currently the active one.
if(EnviroManager.instance.currentZone == this && EnviroManager.instance.Weather.targetWeatherType != currentWeatherType)
EnviroManager.instance.Weather.targetWeatherType = currentWeatherType;
}
void OnTriggerEnter (Collider col)
{
if (EnviroManager.instance == null || EnviroManager.instance.Weather == null)
return;
//Change Weather to Zone Weather:
if(col.gameObject.GetComponent<EnviroManager>())
EnviroManager.instance.currentZone = this;
}
void OnTriggerExit (Collider col)
{
if (EnviroManager.instance == null || EnviroManager.instance.Weather == null)
return;
if(col.gameObject.GetComponent<EnviroManager>())
{
if(EnviroManager.instance.currentZone == this)
{
if(EnviroManager.instance.defaultZone != null)
EnviroManager.instance.currentZone = EnviroManager.instance.defaultZone;
else
EnviroManager.instance.currentZone = null;
}
}
}
void OnDrawGizmos ()
{
Gizmos.color = zoneGizmoColor;
Matrix4x4 rotationMatrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one);
Gizmos.matrix = rotationMatrix;
Gizmos.DrawCube(Vector3.zero, new Vector3(zoneScale.x, zoneScale.y, zoneScale.z));
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: baeda0a1d6b671b4790fdd0c3071e5d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.1.2
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Weather/EnviroZone.cs
uploadId: 660896

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 570331f12772ae1459f11edc3fc993af
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b3ccdfb360c52f049bf71126aa74826f, type: 3}
m_Name: Default Weather Preset
m_EditorClassIdentifier:
showModuleInspector: 1
showSaveLoad: 0
active: 1
Settings:
weatherTypes:
- {fileID: 11400000, guid: 3e61e22e1ac8ba045a3b0e53c22b3629, type: 2}
- {fileID: 11400000, guid: 6c589d06d1746d04a864437f71d0cc30, type: 2}
- {fileID: 11400000, guid: de555bbfb870a794d8ba3d0d8e68f475, type: 2}
- {fileID: 11400000, guid: 11fdd63974de7ae44b1c689d499953f6, type: 2}
- {fileID: 11400000, guid: bb17a17dcbe893f4d992633c085dc5eb, type: 2}
- {fileID: 11400000, guid: 9ba6458aa7df92d4494a7a3d40830a15, type: 2}
- {fileID: 11400000, guid: f736e404e0b052942bc41c35c50dccad, type: 2}
- {fileID: 11400000, guid: 96eebec6fa78a3c48ba2bc98ac5ab57f, type: 2}
- {fileID: 11400000, guid: ebf8ae7a51a5cd342a90c81f5182d8a8, type: 2}
cloudsTransitionSpeed: 1
fogTransitionSpeed: 1
lightingTransitionSpeed: 1
skyTransitionSpeed: 1
effectsTransitionSpeed: 1
auroraTransitionSpeed: 1
environmentTransitionSpeed: 1
audioTransitionSpeed: 1
preset: {fileID: 0}
targetWeatherType: {fileID: 0}
weatherBlendProgress: 0
globalAutoWeatherChange: 1
triggerCollider: {fileID: 0}
triggerRB: {fileID: 0}
showWeatherPresetsControls: 0
showTransitionControls: 0
showZoneControls: 0

View File

@@ -0,0 +1,16 @@
fileFormatVersion: 2
guid: 8c4e279017d5e44458e3e4663b6ab460
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 236601
packageName: Enviro 3 - Sky and Weather
packageVersion: 3.1.2
assetPath: Assets/Enviro 3 - Sky and Weather/Scripts/Runtime/Modules/Weather/Preset/Default
Weather Preset.asset
uploadId: 660896