683 lines
25 KiB
C#
683 lines
25 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
public class biomesSkyMaster : MonoBehaviour
|
|
{
|
|
public SkyMasterManager skyManager;
|
|
|
|
public bool changeByTerrainLayers;
|
|
|
|
public List<TerrainLayer> biomesTerrainLayer = new List<TerrainLayer>();
|
|
|
|
public bool playMusicPerBiome;
|
|
|
|
public List<AudioClip> biomesMusic = new List<AudioClip>();
|
|
|
|
public bool randomMusicTracks;
|
|
|
|
public List<biomeMusicTracks> biomesMusics = new List<biomeMusicTracks>();
|
|
|
|
public bool resetOtherBiomeClips;
|
|
|
|
public bool changeClipsPerTime;
|
|
|
|
public float changeTrackTime = 30f;
|
|
|
|
public float FadeMusicTime = 3f;
|
|
|
|
private float lastMusicChangeTime;
|
|
|
|
public bool fadeOutInMode;
|
|
|
|
public List<AudioSource> biomeAudioSources = new List<AudioSource>();
|
|
|
|
public List<float> biomeMaxVolume = new List<float>();
|
|
|
|
private Vector3 prevPlayerPos = new Vector3(0f, 0f, 0f);
|
|
|
|
private float lastTerrainLayerChangeTime;
|
|
|
|
public float TerrainLayerChangeDelay = 2f;
|
|
|
|
public float updateTerrainLayerDist = 1f;
|
|
|
|
public float updateRate = 2f;
|
|
|
|
public float offsetRaycastDown = 0.5f;
|
|
|
|
public float maxRaycastDist = 100f;
|
|
|
|
[SerializeField]
|
|
private LayerMask FloorLayer;
|
|
|
|
public TerrainLayer currentTerrainLayer;
|
|
|
|
public List<Transform> biomesCenters = new List<Transform>();
|
|
|
|
public List<float> biomesRadius = new List<float>();
|
|
|
|
public Transform Player;
|
|
|
|
public bool enableDebug;
|
|
|
|
public Material shaderCloudsScriptlessMat;
|
|
|
|
public bool useShaderCloudsVolcano;
|
|
|
|
public Gradient initialSkyGrad;
|
|
|
|
public Gradient initialSkyUnderGrad;
|
|
|
|
public List<Gradient> biomesSkyGradients = new List<Gradient>();
|
|
|
|
public List<Gradient> biomesSkyUnderGradients = new List<Gradient>();
|
|
|
|
public List<SkyMasterManager.Volume_Weather_types> biomesWeather = new List<SkyMasterManager.Volume_Weather_types>();
|
|
|
|
public int cloudType;
|
|
|
|
public bool useMultiTypeClouds;
|
|
|
|
public List<int> biomeCloudType = new List<int>();
|
|
|
|
public bool scriptlessShaderVolClouds = true;
|
|
|
|
public bool updateFullVolumeClouds = true;
|
|
|
|
public CloudScript fullVolumeClouds;
|
|
|
|
public FullVolumeCloudsSkyMaster volumeClouds;
|
|
|
|
public float cloudLerpSpeed = 1f;
|
|
|
|
[Tooltip("Sunny, Foggy,Heavy Fog,Tornado,Snow storm,Freeze storm,Flat cloud,Ligthtning,Heavy Storm,Heavy Storm Dark,Cloudy,Rolling Fog,Volcano,Rain ")]
|
|
public List<float> cloudDensities = new List<float>();
|
|
|
|
public bool assignSampleCloudDensities;
|
|
|
|
public float fullVolumeCloudDensityModifier = 2f;
|
|
|
|
public bool useSunColoration;
|
|
|
|
public bool useTimeOfDay;
|
|
|
|
public bool resumeTOD;
|
|
|
|
public List<bool> timeOfDayAchieved = new List<bool>();
|
|
|
|
public List<Color> biomesSunColors = new List<Color>();
|
|
|
|
public List<float> biomesTimeOfDay = new List<float>();
|
|
|
|
public bool useCloudColoration;
|
|
|
|
[Tooltip("Alpha in base = ambient, in sun is sun power and in top is cloud transparency - density")]
|
|
public bool useAlphaForCloudLightPower;
|
|
|
|
public List<Color> cloudTopColor = new List<Color>();
|
|
|
|
public List<Color> cloudBaseColor = new List<Color>();
|
|
|
|
public List<Color> cloudSunColor = new List<Color>();
|
|
|
|
public bool controlFog = true;
|
|
|
|
public bool controlFogHeight;
|
|
|
|
public bool controlFogDistance;
|
|
|
|
public bool controlVolumetricLighting;
|
|
|
|
public List<float> biomeVortexPower = new List<float>();
|
|
|
|
public GlobalFogSkyMaster fog;
|
|
|
|
public List<float> biomesFogHeight = new List<float>();
|
|
|
|
public List<float> biomesFogDistance = new List<float>();
|
|
|
|
public List<float> biomesFogIntensity = new List<float>();
|
|
|
|
public List<float> biomesGradientDistance = new List<float>();
|
|
|
|
public List<Gradient> biomesFogGradients = new List<Gradient>();
|
|
|
|
public List<Color> biomesFogColor = new List<Color>();
|
|
|
|
public List<float> biomesVolumeLightPower = new List<float>();
|
|
|
|
public List<float> biomesLocalVolumeLightsPower = new List<float>();
|
|
|
|
public bool controlCloudShafts;
|
|
|
|
public List<int> biomesCloudShaftsType = new List<int>();
|
|
|
|
public List<float> biomesCloudShaftsPower = new List<float>();
|
|
|
|
public bool controlSunIntensity = true;
|
|
|
|
public List<float> biomesSunIntensity = new List<float>();
|
|
|
|
public bool controlAmbientIntensity = true;
|
|
|
|
public List<float> biomesAmbientIntensity = new List<float>();
|
|
|
|
public bool regulateReflections;
|
|
|
|
public PlanarReflectionSM reflectionScript;
|
|
|
|
public int currentBiomeID;
|
|
|
|
private Gradient outGrad;
|
|
|
|
private IEnumerator CheckGround()
|
|
{
|
|
while (true)
|
|
{
|
|
if ((Player.position - prevPlayerPos).magnitude > updateTerrainLayerDist && Physics.Raycast(Player.position - new Vector3(0f, offsetRaycastDown, 0f), Vector3.down, out var hitInfo, maxRaycastDist, FloorLayer))
|
|
{
|
|
prevPlayerPos = Player.position;
|
|
if (hitInfo.collider.TryGetComponent<Terrain>(out var component))
|
|
{
|
|
yield return StartCoroutine(findTerrainLayer(component, hitInfo.point));
|
|
}
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
private IEnumerator findTerrainLayer(Terrain Terrain, Vector3 HitPoint)
|
|
{
|
|
Vector3 vector = HitPoint - Terrain.transform.position;
|
|
Vector3 vector2 = new Vector3(vector.x / Terrain.terrainData.size.x, 0f, vector.z / Terrain.terrainData.size.z);
|
|
int x = Mathf.FloorToInt(vector2.x * (float)Terrain.terrainData.alphamapWidth);
|
|
int y = Mathf.FloorToInt(vector2.z * (float)Terrain.terrainData.alphamapHeight);
|
|
float[,,] alphamaps = Terrain.terrainData.GetAlphamaps(x, y, 1, 1);
|
|
int num = 0;
|
|
for (int i = 1; i < alphamaps.Length; i++)
|
|
{
|
|
if (alphamaps[0, 0, i] > alphamaps[0, 0, num])
|
|
{
|
|
num = i;
|
|
}
|
|
}
|
|
currentTerrainLayer = Terrain.terrainData.terrainLayers[num];
|
|
yield return new WaitForSeconds(updateRate);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if (changeByTerrainLayers)
|
|
{
|
|
StartCoroutine(CheckGround());
|
|
}
|
|
if (assignSampleCloudDensities)
|
|
{
|
|
cloudDensities.Clear();
|
|
cloudDensities.Add(0f);
|
|
cloudDensities.Add(0.2f);
|
|
cloudDensities.Add(0.3f);
|
|
cloudDensities.Add(0.4f);
|
|
cloudDensities.Add(0.7f);
|
|
cloudDensities.Add(0.8f);
|
|
cloudDensities.Add(0.1f);
|
|
cloudDensities.Add(0.85f);
|
|
cloudDensities.Add(1f);
|
|
cloudDensities.Add(0.9f);
|
|
cloudDensities.Add(0.5f);
|
|
cloudDensities.Add(0.1f);
|
|
cloudDensities.Add(0f);
|
|
cloudDensities.Add(0.5f);
|
|
}
|
|
if (skyManager != null)
|
|
{
|
|
skyManager.SkyColorGrad = biomesSkyGradients[0];
|
|
skyManager.SkyTintGrad = biomesSkyUnderGradients[0];
|
|
}
|
|
if (Player == null)
|
|
{
|
|
Player = Camera.main.transform;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (skyManager != null && updateFullVolumeClouds && fullVolumeClouds != null)
|
|
{
|
|
if (!useMultiTypeClouds || (useMultiTypeClouds && biomeCloudType[currentBiomeID] == 0))
|
|
{
|
|
if (volumeClouds == null || (volumeClouds != null && !volumeClouds.enabled))
|
|
{
|
|
if (!fullVolumeClouds.enabled)
|
|
{
|
|
fullVolumeClouds.enabled = true;
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Sunny)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[0] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[0] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.FlatClouds)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[6] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[6] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStormDark)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[9] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[9] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Rain)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[13] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[13] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Tornado)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[3] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[3] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Cloudy)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[10] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[10] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[7] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[7] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[8] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[8] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.SnowStorm)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[4] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[4] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.VolcanoErupt)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, cloudDensities[0] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, cloudDensities[0] * fullVolumeCloudDensityModifier, Time.deltaTime * cloudLerpSpeed);
|
|
if (useShaderCloudsVolcano && scriptlessShaderVolClouds)
|
|
{
|
|
float a = shaderCloudsScriptlessMat.GetFloat("_Coverage");
|
|
shaderCloudsScriptlessMat.SetFloat("_Coverage", Mathf.Lerp(a, 1f, Time.deltaTime * cloudLerpSpeed * 0.14f));
|
|
}
|
|
}
|
|
else if (useShaderCloudsVolcano && scriptlessShaderVolClouds)
|
|
{
|
|
float a2 = shaderCloudsScriptlessMat.GetFloat("_Coverage");
|
|
shaderCloudsScriptlessMat.SetFloat("_Coverage", Mathf.Lerp(a2, 0f, Time.deltaTime * cloudLerpSpeed * 0.14f));
|
|
}
|
|
}
|
|
if (volumeClouds != null && volumeClouds.enabled)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, 0f, Time.deltaTime * cloudLerpSpeed);
|
|
if (volumeClouds._NoiseAmp1 < 6f)
|
|
{
|
|
volumeClouds.enabled = false;
|
|
Camera.main.clearFlags = CameraClearFlags.Skybox;
|
|
if (regulateReflections && reflectionScript != null && reflectionScript.m_ReflectionCameraOut != null)
|
|
{
|
|
FullVolumeCloudsSkyMaster component = reflectionScript.m_ReflectionCameraOut.GetComponent<FullVolumeCloudsSkyMaster>();
|
|
if (component != null)
|
|
{
|
|
component.enabled = false;
|
|
}
|
|
CloudScript component2 = reflectionScript.m_ReflectionCameraOut.GetComponent<CloudScript>();
|
|
if (component2 != null)
|
|
{
|
|
component2.enabled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (fullVolumeClouds == null || (fullVolumeClouds != null && !fullVolumeClouds.enabled))
|
|
{
|
|
if (!volumeClouds.enabled)
|
|
{
|
|
volumeClouds.enabled = true;
|
|
}
|
|
float num = 10f;
|
|
float num2 = 5f;
|
|
float num3 = fullVolumeCloudDensityModifier * num + num2;
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Sunny)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[0] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.FlatClouds)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[6] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStormDark)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[9] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Rain)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[13] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Tornado)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[3] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Cloudy)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[10] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[7] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[8] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.SnowStorm)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[4] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (skyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.VolcanoErupt)
|
|
{
|
|
volumeClouds._NoiseAmp1 = Mathf.Lerp(volumeClouds._NoiseAmp1, cloudDensities[0] * num3, Time.deltaTime * cloudLerpSpeed);
|
|
if (useShaderCloudsVolcano && scriptlessShaderVolClouds)
|
|
{
|
|
float a3 = shaderCloudsScriptlessMat.GetFloat("_Coverage");
|
|
shaderCloudsScriptlessMat.SetFloat("_Coverage", Mathf.Lerp(a3, 1f, Time.deltaTime * cloudLerpSpeed * 0.14f));
|
|
}
|
|
}
|
|
else if (useShaderCloudsVolcano && scriptlessShaderVolClouds)
|
|
{
|
|
float a4 = shaderCloudsScriptlessMat.GetFloat("_Coverage");
|
|
shaderCloudsScriptlessMat.SetFloat("_Coverage", Mathf.Lerp(a4, 0f, Time.deltaTime * cloudLerpSpeed * 0.14f));
|
|
}
|
|
}
|
|
if (fullVolumeClouds.enabled)
|
|
{
|
|
fullVolumeClouds.coverage = Mathf.Lerp(fullVolumeClouds.coverage, 0f, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.coverageHigh = Mathf.Lerp(fullVolumeClouds.coverageHigh, 0f, Time.deltaTime * cloudLerpSpeed);
|
|
if (fullVolumeClouds.coverage < 0.01f)
|
|
{
|
|
fullVolumeClouds.enabled = false;
|
|
if (regulateReflections && reflectionScript != null && reflectionScript.m_ReflectionCameraOut != null)
|
|
{
|
|
FullVolumeCloudsSkyMaster component3 = reflectionScript.m_ReflectionCameraOut.GetComponent<FullVolumeCloudsSkyMaster>();
|
|
if (component3 != null)
|
|
{
|
|
component3.enabled = true;
|
|
}
|
|
CloudScript component4 = reflectionScript.m_ReflectionCameraOut.GetComponent<CloudScript>();
|
|
if (component4 != null)
|
|
{
|
|
component4.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!(Player != null))
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < biomesCenters.Count; i++)
|
|
{
|
|
if ((changeByTerrainLayers || !((biomesCenters[i].position - Player.position).magnitude < biomesRadius[i])) && (!changeByTerrainLayers || !(currentTerrainLayer == biomesTerrainLayer[i]) || !(Time.fixedTime - lastTerrainLayerChangeTime > TerrainLayerChangeDelay)))
|
|
{
|
|
continue;
|
|
}
|
|
lastTerrainLayerChangeTime = Time.fixedTime;
|
|
currentBiomeID = i;
|
|
skyManager.SkyColorGrad = LerpGradient(skyManager.SkyColorGrad, biomesSkyGradients[i], Time.deltaTime * cloudLerpSpeed, doColor: true, doAlpha: true);
|
|
skyManager.SkyTintGrad = LerpGradient(skyManager.SkyTintGrad, biomesSkyUnderGradients[i], Time.deltaTime * cloudLerpSpeed, doColor: true, doAlpha: true);
|
|
skyManager.currentWeatherName = biomesWeather[i];
|
|
if (controlFog && fog != null)
|
|
{
|
|
fog.DistGradient = LerpGradient(fog.DistGradient, biomesFogGradients[i], Time.deltaTime * 2f, doColor: true, doAlpha: true);
|
|
fog.heightDensity = Mathf.Lerp(fog.heightDensity, biomesFogIntensity[i] / 10000f, Time.deltaTime * cloudLerpSpeed);
|
|
fog.GradientBounds.y = Mathf.Lerp(fog.GradientBounds.y, biomesGradientDistance[i], Time.deltaTime * cloudLerpSpeed);
|
|
if (controlFogHeight)
|
|
{
|
|
fog.height = Mathf.Lerp(fog.height, biomesFogHeight[i], Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (controlFogDistance)
|
|
{
|
|
fog.startDistance = Mathf.Lerp(fog.startDistance, biomesFogDistance[i], Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
}
|
|
if (useSunColoration)
|
|
{
|
|
Color color = skyManager.SUN_LIGHT.GetComponent<Light>().color;
|
|
skyManager.SUN_LIGHT.GetComponent<Light>().color = Color.Lerp(color, biomesSunColors[i], Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (useTimeOfDay)
|
|
{
|
|
if (resumeTOD)
|
|
{
|
|
if (timeOfDayAchieved.Count < biomesCenters.Count)
|
|
{
|
|
timeOfDayAchieved.Clear();
|
|
for (int j = 0; j < biomesCenters.Count; j++)
|
|
{
|
|
timeOfDayAchieved.Add(item: false);
|
|
}
|
|
}
|
|
if (timeOfDayAchieved[currentBiomeID])
|
|
{
|
|
for (int k = 0; k < biomesCenters.Count; k++)
|
|
{
|
|
if (k != currentBiomeID)
|
|
{
|
|
timeOfDayAchieved[k] = false;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
skyManager.Current_Time = Mathf.Lerp(skyManager.Current_Time, biomesTimeOfDay[i], Time.deltaTime * cloudLerpSpeed);
|
|
if (Mathf.Abs(skyManager.Current_Time - biomesTimeOfDay[i]) < 0.1f)
|
|
{
|
|
timeOfDayAchieved[currentBiomeID] = true;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
skyManager.Current_Time = Mathf.Lerp(skyManager.Current_Time, biomesTimeOfDay[i], Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
}
|
|
if (controlSunIntensity)
|
|
{
|
|
skyManager.Max_sun_intensity = Mathf.Lerp(skyManager.Max_sun_intensity, biomesSunIntensity[i], Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (controlAmbientIntensity)
|
|
{
|
|
skyManager.AmbientIntensity = Mathf.Lerp(skyManager.AmbientIntensity, biomesAmbientIntensity[i], Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
if (playMusicPerBiome && biomeAudioSources.Count > i)
|
|
{
|
|
for (int l = 0; l < biomeAudioSources.Count; l++)
|
|
{
|
|
if (biomeAudioSources[l].clip == null || (!randomMusicTracks && biomeAudioSources[l].clip != biomesMusic[l]) || (randomMusicTracks && changeClipsPerTime && Time.fixedTime - lastMusicChangeTime > changeTrackTime))
|
|
{
|
|
if (randomMusicTracks)
|
|
{
|
|
if (resetOtherBiomeClips)
|
|
{
|
|
for (int m = 0; m < biomeAudioSources.Count; m++)
|
|
{
|
|
if (m != currentBiomeID)
|
|
{
|
|
biomeAudioSources[m].clip = null;
|
|
}
|
|
}
|
|
}
|
|
if (biomeAudioSources[l].clip == null)
|
|
{
|
|
biomeAudioSources[l].clip = biomesMusics[l].list[Random.Range(0, biomesMusics[l].list.Count)];
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(FadeOutIn(biomeAudioSources[currentBiomeID], FadeMusicTime));
|
|
fadeOutInMode = true;
|
|
}
|
|
lastMusicChangeTime = Time.fixedTime;
|
|
}
|
|
else
|
|
{
|
|
biomeAudioSources[l].clip = biomesMusic[l];
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (fadeOutInMode)
|
|
{
|
|
continue;
|
|
}
|
|
if (l == i)
|
|
{
|
|
if (biomeAudioSources[l].volume < biomeMaxVolume[i])
|
|
{
|
|
if (!biomeAudioSources[l].isPlaying)
|
|
{
|
|
biomeAudioSources[l].Play(0uL);
|
|
}
|
|
StartCoroutine(FadeAudio(biomeAudioSources[l], 4f, biomeMaxVolume[i]));
|
|
}
|
|
}
|
|
else if (biomeAudioSources[l].volume > 0f)
|
|
{
|
|
StartCoroutine(FadeAudio(biomeAudioSources[l], 2f, 0f));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (useCloudColoration)
|
|
{
|
|
if (!useMultiTypeClouds || (useMultiTypeClouds && biomeCloudType[currentBiomeID] == 0))
|
|
{
|
|
fullVolumeClouds.cloudTopColor = Color.Lerp(fullVolumeClouds.cloudTopColor, cloudTopColor[i], Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.cloudBaseColor = Color.Lerp(fullVolumeClouds.cloudBaseColor, cloudBaseColor[i], Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.highSunColor = Color.Lerp(fullVolumeClouds.highSunColor, cloudSunColor[i], Time.deltaTime * cloudLerpSpeed);
|
|
if (useAlphaForCloudLightPower)
|
|
{
|
|
fullVolumeClouds.ambientLightFactor = Mathf.Lerp(fullVolumeClouds.ambientLightFactor, cloudBaseColor[i].a / 1f, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.sunLightFactor = Mathf.Lerp(fullVolumeClouds.sunLightFactor, cloudSunColor[i].a / 1f * 5f, Time.deltaTime * cloudLerpSpeed);
|
|
fullVolumeClouds.cloudSampleMultiplier = Mathf.Lerp(fullVolumeClouds.cloudSampleMultiplier, cloudTopColor[i].a / 1f * 2f, Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
volumeClouds._SkyTint = Vector3.Lerp(volumeClouds._SkyTint, new Vector3(cloudTopColor[i].r, cloudTopColor[i].g, cloudTopColor[i].b) * 5f, Time.deltaTime * cloudLerpSpeed);
|
|
volumeClouds._GroundColor = Vector3.Lerp(volumeClouds._GroundColor, new Vector3(cloudBaseColor[i].r, cloudBaseColor[i].g, cloudBaseColor[i].b), Time.deltaTime * cloudLerpSpeed);
|
|
}
|
|
}
|
|
if (enableDebug)
|
|
{
|
|
Debug.Log("Inside Biome: " + i);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
private Gradient LerpGradient(Gradient gradA, Gradient gradB, float lerpTime, bool doColor, bool doAlpha)
|
|
{
|
|
List<float> list = new List<float>();
|
|
if (doColor)
|
|
{
|
|
for (int i = 0; i < gradA.colorKeys.Length; i++)
|
|
{
|
|
float time = gradA.colorKeys[i].time;
|
|
if (!list.Contains(time) && list.Count < 8)
|
|
{
|
|
list.Add(time);
|
|
}
|
|
}
|
|
}
|
|
if (doAlpha)
|
|
{
|
|
for (int j = 0; j < gradA.alphaKeys.Length; j++)
|
|
{
|
|
float time2 = gradA.alphaKeys[j].time;
|
|
if (!list.Contains(time2) && list.Count < 8)
|
|
{
|
|
list.Add(time2);
|
|
}
|
|
}
|
|
}
|
|
GradientColorKey[] array = new GradientColorKey[list.Count];
|
|
GradientAlphaKey[] array2 = new GradientAlphaKey[list.Count];
|
|
for (int k = 0; k < list.Count; k++)
|
|
{
|
|
float time3 = list[k];
|
|
Color col = Color.Lerp(gradA.Evaluate(time3), gradB.Evaluate(time3), lerpTime);
|
|
array[k] = new GradientColorKey(col, time3);
|
|
array2[k] = new GradientAlphaKey(col.a, time3);
|
|
}
|
|
if (enableDebug)
|
|
{
|
|
Debug.Log("keysTimes.Count: " + list.Count);
|
|
}
|
|
outGrad = new Gradient();
|
|
outGrad.SetKeys(array, array2);
|
|
return outGrad;
|
|
}
|
|
|
|
public IEnumerator FadeAudio(AudioSource audioSource, float timer, float volume)
|
|
{
|
|
float time = 0f;
|
|
float begindVolume = audioSource.volume;
|
|
while (time < timer)
|
|
{
|
|
time += Time.deltaTime;
|
|
audioSource.volume = Mathf.Lerp(begindVolume, volume, time / timer);
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public IEnumerator FadeOut(AudioSource audioSource, float FadeTime)
|
|
{
|
|
float startVolume = audioSource.volume;
|
|
while (audioSource.volume > 0f)
|
|
{
|
|
audioSource.volume -= startVolume * Time.deltaTime / FadeTime;
|
|
yield return null;
|
|
}
|
|
audioSource.Stop();
|
|
}
|
|
|
|
public IEnumerator FadeOutIn(AudioSource audioSource, float FadeTime)
|
|
{
|
|
float startVolume = audioSource.volume;
|
|
while (audioSource.volume > 0f)
|
|
{
|
|
audioSource.volume -= startVolume * Time.deltaTime / FadeTime;
|
|
yield return null;
|
|
}
|
|
audioSource.clip = biomesMusics[currentBiomeID].list[Random.Range(0, biomesMusics[currentBiomeID].list.Count)];
|
|
fadeOutInMode = false;
|
|
}
|
|
|
|
public IEnumerator FadeIn(AudioSource audioSource, float FadeTime)
|
|
{
|
|
audioSource.Play();
|
|
audioSource.volume = 0f;
|
|
while (audioSource.volume < 1f)
|
|
{
|
|
audioSource.volume += Time.deltaTime / FadeTime;
|
|
yield return null;
|
|
}
|
|
fadeOutInMode = false;
|
|
}
|
|
}
|
|
}
|