Files
2026-03-04 10:03:45 +08:00

950 lines
32 KiB
C#

using System;
using UnityEngine;
namespace Artngame.SKYMASTER
{
[ExecuteInEditMode]
public class CloudHandlerSM : MonoBehaviour
{
public enum CloudPreset
{
Custom = 0,
ClearDay = 1
}
public bool followPlayer;
public bool rotateWithCamera;
public bool rotateMultiQuadC;
public float IntensityDiffOffset;
public float IntensitySunOffset;
public float IntensityFogOffset;
[HideInInspector]
public bool EnableInsideClouds;
public bool FogFromSkyGrad;
[HideInInspector]
public bool LerpRot;
public AnimationCurve IntensityDiff = new AnimationCurve(new Keyframe(0f, 0.4f), new Keyframe(0.374f, 0.292f), new Keyframe(0.6f, 0.2766f), new Keyframe(0.757f, 0.278f), new Keyframe(0.798f, 0.271f), new Keyframe(0.849f, 0.275f), new Keyframe(0.887f, 0.248f), new Keyframe(0.944f, 0.28f), new Keyframe(1f, 0.4f));
public AnimationCurve IntensityFog = new AnimationCurve(new Keyframe(0f, 5f), new Keyframe(0.75f, 10f), new Keyframe(0.88f, 11f), new Keyframe(0.89f, 10.58f), new Keyframe(1f, 5f));
public AnimationCurve IntensitySun = new AnimationCurve(new Keyframe(0f, 0.078f), new Keyframe(0.1864f, 0.148f), new Keyframe(0.71f, 0.129f), new Keyframe(0.839f, 0.303f), new Keyframe(0.9f, 0.13f), new Keyframe(1f, 0.078f));
public bool CurvesFromSkyMaster;
public bool DomeClouds = true;
public Vector3 DomeScale;
public Vector3 DomeHeights;
public bool MultiQuadClouds;
public Vector3 MultiQuadScale;
public Vector3 MultiQuadHeights;
public bool MultiQuadAClouds;
public Vector3 MultiQuadAScale;
public Vector3 MultiQuadAHeights;
public bool MultiQuadBClouds;
public Vector3 MultiQuadBScale;
public Vector3 MultiQuadBHeights;
public bool MultiQuadCClouds;
public Vector3 MultiQuadCScale;
public Vector3 MultiQuadCHeights;
public bool OneQuadClouds;
public Vector3 OneQuadScale;
public Vector3 OneQuadHeights;
public Transform FlatBedSPlane;
public Transform SideSPlane;
public Transform SideASPlane;
public Transform SideBSPlane;
public Transform SideCSPlane;
public Transform RotCloudsSPlane;
public bool WeatherDensity;
public bool UseUnityFog;
public float CloudEvolution = 0.07f;
public float ClearDayCoverage = -0.12f;
public float ClearDayHorizon = 0.1f;
public float StormCoverage;
public float StormHorizon = 0.01f;
public Color StormSunColor = new Color(0.5f, 0.5f, 0.5f, 0.5f);
public float Coverage = -0.12f;
public float Transp = 0.51f;
public float Intensity = 0.1f;
public float Horizon = 0.1f;
public CloudPreset cloudType = CloudPreset.ClearDay;
public SkyMasterManager SkyManager;
public bool autoRainbow;
public float rainbowApperSpeed = 1f;
private bool was_rain;
private float was_rain_end_time;
public float rainbowTime = 60f;
public float rainboxMaxIntensity = 0.7f;
public float rainboxMinIntensity;
public Material rainbowMat;
public Material cloudFlatMat;
public Material cloudSidesMat;
public Material cloudSidesAMat;
public Material cloudSidesBMat;
public Material cloudSidesCMat;
public Material cloudRotMat;
public Transform FlatBedClouds;
public Transform SideClouds;
public Transform SideAClouds;
public Transform SideBClouds;
public Transform SideCClouds;
public Transform RotClouds;
public GameObject LightningPrefab;
public bool EnableLightning;
public Color DayCloudColor = new Color(46f / 51f, 46f / 51f, 46f / 51f, 4f / 51f);
public Color DayCloudShadowCol = new Color(0.23921569f, 0.23921569f, 27f / 85f, 14f / 51f);
public Color DayCloudTintCol = new Color(0.043137256f, 0.043137256f, 0.043137256f, 1f);
public Color DayCloudFogCol = new Color(0.76862746f, 73f / 85f, 78f / 85f, 1f);
public float DayFogFactor = 1f;
public float DayIntensity = 0.1f;
public Color DawnCloudColor = new Color(77f / 85f, 38f / 51f, 0.9411765f, 22f / 51f);
public Color DawnCloudShadowCol = new Color(14f / 51f, 1f / 85f, 1f / 85f, 0.40784314f);
public Color DawnCloudTintCol = new Color(0.043137256f, 2f / 51f, 2f / 51f, 1f);
public Color DawnCloudFogCol = new Color(82f / 85f, 0.07450981f, 0.05490196f, 0.88235295f);
public float DawnFogFactor = 1.94f;
public float DawnIntensity = -3.79f;
public Color DuskCloudColor = new Color(0.12156863f, 0.11372549f, 0.11372549f, 0.14509805f);
public Color DuskCloudShadowCol = new Color(0.6313726f, 0.32156864f, 13f / 85f, 21f / 85f);
public Color DuskCloudTintCol = new Color(0.043137256f, 2f / 51f, 2f / 51f, 1f);
public Color DuskCloudFogCol = new Color(82f / 85f, 0.07450981f, 0.05490196f, 0.88235295f);
public float DuskFogFactor = 1.94f;
public float DuskIntensity = -1.25f;
public Color NightCloudColor = new Color(44f / 51f, 0.88235295f, 0.8235294f, 0.02745098f);
private int prev_preset;
public bool HasScatterShader;
public bool UpdateScatterShader;
public float fog_depth = 0.29f;
public float reileigh = 1.3f;
public float mieCoefficient = 1f;
public float mieDirectionalG = 0.1f;
public float ExposureBias = 0.11f;
private const float n = 1.0003f;
private const float N = 2.545E+25f;
private const float pn = 0.035f;
public Vector3 lambda = new Vector3(6.8E-07f, 5.5E-07f, 4.5E-07f);
public Vector3 K = new Vector3(0.9f, 0.5f, 0.5f);
public float WindStrength = 1f;
public float WindParallaxFactor = 1.2f;
public float CloudDensity = 0.0001f;
public Transform LightningBox;
private float last_lightning_time;
public float lightning_every = 15f;
public float max_lightning_time = 2f;
public float lightning_rate_offset = 5f;
private Transform LightningOne;
private Transform LightningTwo;
private void Start()
{
if (Application.isPlaying)
{
if (rainbowMat != null)
{
Color color = rainbowMat.GetColor("_Color");
rainbowMat.SetColor("_Color", new Color(color.r, color.g, color.b, 0f));
}
_ = Camera.main != null;
if (cloudFlatMat == null)
{
cloudFlatMat = FlatBedClouds.gameObject.GetComponentsInChildren<MeshRenderer>(includeInactive: true)[0].material;
}
if (cloudSidesMat == null)
{
cloudSidesMat = SideClouds.gameObject.GetComponentsInChildren<MeshRenderer>(includeInactive: true)[0].material;
}
if (cloudSidesAMat == null)
{
cloudSidesAMat = SideAClouds.gameObject.GetComponentsInChildren<MeshRenderer>(includeInactive: true)[0].material;
}
if (cloudSidesBMat == null)
{
cloudSidesBMat = SideBClouds.gameObject.GetComponentsInChildren<MeshRenderer>(includeInactive: true)[0].material;
}
if (cloudSidesCMat == null)
{
cloudSidesCMat = SideCClouds.gameObject.GetComponentsInChildren<MeshRenderer>(includeInactive: true)[0].material;
}
if (cloudRotMat == null)
{
cloudRotMat = RotClouds.gameObject.GetComponentsInChildren<MeshRenderer>(includeInactive: true)[0].material;
}
if (SkyManager != null)
{
if (cloudFlatMat != null)
{
UpdateCloudParams(Init: true, cloudFlatMat);
}
if (cloudSidesMat != null)
{
UpdateCloudParams(Init: true, cloudSidesMat);
}
if (cloudSidesAMat != null)
{
UpdateCloudParams(Init: true, cloudSidesAMat);
}
if (cloudSidesBMat != null)
{
UpdateCloudParams(Init: true, cloudSidesBMat);
}
if (cloudRotMat != null)
{
UpdateCloudParams(Init: true, cloudRotMat);
}
}
if (WeatherDensity)
{
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm || SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm)
{
Coverage = StormCoverage;
Horizon = StormHorizon;
EnableLightning = true;
}
else
{
Coverage = ClearDayCoverage;
Horizon = ClearDayHorizon;
EnableLightning = false;
}
}
}
if (FlatBedClouds != null && cloudFlatMat != null)
{
DomeScale = FlatBedClouds.localScale;
DomeHeights = new Vector3(FlatBedClouds.position.y, cloudFlatMat.GetFloat("_CutHeight"), 0f);
}
if (SideClouds != null && cloudSidesMat != null)
{
MultiQuadScale = SideClouds.localScale;
MultiQuadHeights = new Vector3(SideClouds.position.y, cloudSidesMat.GetFloat("_CutHeight"), 0f);
}
if (SideAClouds != null && cloudSidesAMat != null)
{
MultiQuadAScale = SideAClouds.localScale;
MultiQuadAHeights = new Vector3(SideAClouds.position.y, cloudSidesAMat.GetFloat("_CutHeight"), 0f);
}
if (SideBClouds != null && cloudSidesBMat != null)
{
MultiQuadBScale = SideBClouds.localScale;
MultiQuadBHeights = new Vector3(SideBClouds.position.y, cloudSidesBMat.GetFloat("_CutHeight"), 0f);
}
if (SideCClouds != null && cloudSidesCMat != null)
{
MultiQuadCScale = SideCClouds.localScale;
MultiQuadCHeights = new Vector3(SideCClouds.position.y, cloudSidesCMat.GetFloat("_CutHeight"), 0f);
}
if (RotClouds != null && cloudRotMat != null)
{
OneQuadScale = RotClouds.localScale;
OneQuadHeights = new Vector3(RotClouds.position.y, cloudRotMat.GetFloat("_CutHeight"), 0f);
}
}
private void UpdateCloudParams(bool Init, Material oceanMat)
{
bool flag = (SkyManager.AutoSunPosition && SkyManager.Rot_Sun_X > 0f) | (!SkyManager.AutoSunPosition && ((SkyManager.Current_Time > 9f + SkyManager.Shift_dawn) & (SkyManager.Current_Time <= SkyManager.NightTimeMax + SkyManager.Shift_dawn)));
bool flag2 = (SkyManager.AutoSunPosition && SkyManager.Rot_Sun_X > 65f) | (!SkyManager.AutoSunPosition && SkyManager.Current_Time > 17f + SkyManager.Shift_dawn);
bool flag3 = (SkyManager.AutoSunPosition && SkyManager.Rot_Sun_X > 85f) | (!SkyManager.AutoSunPosition && SkyManager.Current_Time > 22f + SkyManager.Shift_dawn);
bool flag4 = (SkyManager.AutoSunPosition && SkyManager.Rot_Sun_X < 10f) | (!SkyManager.AutoSunPosition && SkyManager.Current_Time < 10f + SkyManager.Shift_dawn);
float num = Time.deltaTime;
if (Init)
{
num = 10000f;
}
if (SkyManager.windZone != null)
{
Vector4 vector = oceanMat.GetVector("_Velocity1");
Vector4 vector2 = oceanMat.GetVector("_Velocity2");
float windMain = SkyManager.windZone.windMain;
Vector4 b = new Vector4(SkyManager.windZone.transform.forward.x, SkyManager.windZone.transform.forward.z, 0f, -0.007f) * (0f - windMain) * WindStrength * 1f;
oceanMat.SetVector("_Velocity1", Vector4.Lerp(vector, b, 0.0001f * num * 21f));
oceanMat.SetVector("_Velocity2", new Vector4(Mathf.Lerp(vector2.x, b.x * WindParallaxFactor * 1f, 0.0001f * num * 11f * WindParallaxFactor * 1f), Mathf.Lerp(vector2.y, b.y * WindParallaxFactor * 1f, 0.0001f * num * 11f * WindParallaxFactor), 0f, CloudEvolution));
}
if (!HasScatterShader)
{
return;
}
if (UpdateScatterShader)
{
reileigh = SkyManager.m_fRayleighScaleDepth;
reileigh = SkyManager.m_Kr;
mieCoefficient = SkyManager.m_Km;
}
if (!Application.isPlaying)
{
num = 10000f;
}
Color color = oceanMat.GetColor("_SunColor");
Color color2 = oceanMat.GetColor("_ShadowColor");
float a = oceanMat.GetFloat("_Density");
oceanMat.SetFloat("_Density", Mathf.Lerp(a, CloudDensity, 0.27f * num + 0.05f));
float a2 = oceanMat.GetFloat("_Coverage");
float a3 = oceanMat.GetFloat("_Transparency");
float a4 = oceanMat.GetFloat("_HorizonFactor");
Color color3 = oceanMat.GetColor("_Color");
Color color4 = oceanMat.GetColor("_FogColor");
if (UseUnityFog)
{
oceanMat.SetFloat("_FogUnity", 1f);
}
else
{
oceanMat.SetFloat("_FogUnity", 0f);
}
float num2 = 0.3f * (SkyManager.SPEED + 0.1f);
if (!Application.isPlaying)
{
num2 = 1000f * num2;
}
if (!SkyManager.VolCloudGradients)
{
float num3 = 0f;
float num4 = 0f;
if (!CurvesFromSkyMaster)
{
num3 = IntensityDiff.Evaluate(SkyManager.calcColorTime) + IntensityDiffOffset + 0.3f;
num4 = IntensityFog.Evaluate(SkyManager.calcColorTime) + IntensityFogOffset;
}
else
{
num3 = SkyManager.VcloudLightDiff + IntensityDiffOffset + 0.3f;
num4 = SkyManager.VcloudFog + IntensityFogOffset;
}
if (flag)
{
oceanMat.SetVector("sunPosition", -SkyManager.SunObj.transform.forward.normalized);
if (flag2)
{
if (!flag3)
{
if (cloudType != CloudPreset.Custom && cloudType == CloudPreset.ClearDay)
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, DuskCloudColor, 3f * num2 * num));
oceanMat.SetColor("_ShadowColor", Color.Lerp(color2, DuskCloudShadowCol, num2 * num));
oceanMat.SetFloat("_Coverage", Mathf.Lerp(a2, Coverage, num2 * num));
oceanMat.SetFloat("_Transparency", Mathf.Lerp(a3, Transp, num2 * num));
oceanMat.SetColor("_Color", Color.Lerp(color3, DuskCloudTintCol, num2 * num));
oceanMat.SetColor("_FogColor", Color.Lerp(color4, DuskCloudFogCol, num2 * num));
}
}
else if (cloudType != CloudPreset.Custom && cloudType == CloudPreset.ClearDay)
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, DayCloudColor * 0.3f, 0.2f * num2 * num));
oceanMat.SetColor("_ShadowColor", Color.Lerp(color2, 4f * DayCloudShadowCol, num2 * num));
oceanMat.SetFloat("_Coverage", Mathf.Lerp(a2, Coverage, num2 * num));
oceanMat.SetFloat("_Transparency", Mathf.Lerp(a3, Transp, num2 * num));
oceanMat.SetColor("_Color", Color.Lerp(color3, DayCloudTintCol, num2 * num));
oceanMat.SetColor("_FogColor", Color.Lerp(color4, DayCloudFogCol, 4f * num2 * num));
}
}
else if (flag4)
{
if (cloudType != CloudPreset.Custom && cloudType == CloudPreset.ClearDay)
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, DawnCloudColor, 1f * num2 * num));
oceanMat.SetColor("_ShadowColor", Color.Lerp(color2, DawnCloudShadowCol, num2 * num));
oceanMat.SetFloat("_Coverage", Mathf.Lerp(a2, Coverage, num2 * num));
oceanMat.SetFloat("_Transparency", Mathf.Lerp(a3, Transp, num2 * num));
oceanMat.SetColor("_Color", Color.Lerp(color3, DawnCloudTintCol, num2 * num));
oceanMat.SetColor("_FogColor", Color.Lerp(color4, DawnCloudFogCol, num2 * num));
}
}
else if (cloudType != CloudPreset.Custom && cloudType == CloudPreset.ClearDay)
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, DayCloudColor, 0.3f * num2 * num));
oceanMat.SetColor("_ShadowColor", Color.Lerp(color2, DayCloudShadowCol, num2 * num));
oceanMat.SetFloat("_Coverage", Mathf.Lerp(a2, Coverage, num2 * num));
oceanMat.SetFloat("_Transparency", Mathf.Lerp(a3, Transp, num2 * num));
oceanMat.SetColor("_Color", Color.Lerp(color3, DayCloudTintCol, num2 * num));
oceanMat.SetColor("_FogColor", Color.Lerp(color4, DayCloudFogCol, num2 * num));
}
}
else
{
oceanMat.SetVector("sunPosition", -SkyManager.MoonObj.transform.forward.normalized);
if (cloudType != CloudPreset.Custom && cloudType == CloudPreset.ClearDay)
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, NightCloudColor, 0.8f * num2 * num));
oceanMat.SetColor("_ShadowColor", Color.Lerp(color2, 1f * DayCloudShadowCol, num2 * num));
oceanMat.SetFloat("_Coverage", Mathf.Lerp(a2, Coverage, num2 * num));
oceanMat.SetFloat("_Transparency", Mathf.Lerp(a3, Transp, num2 * num));
oceanMat.SetColor("_Color", Color.Lerp(color3, DayCloudTintCol, num2 * num));
oceanMat.SetColor("_FogColor", Color.Lerp(color4, DayCloudFogCol, 4f * num2 * num));
}
}
oceanMat.SetFloat("_ColorDiff", num3);
oceanMat.SetFloat("_HorizonFactor", Mathf.Lerp(a4, Horizon, num2 * num + 0.05f));
oceanMat.SetFloat("_FogFactor", num4);
}
oceanMat.SetVector("betaR", totalRayleigh(lambda) * reileigh);
oceanMat.SetVector("betaM", totalMie(lambda, K, fog_depth) * mieCoefficient);
oceanMat.SetFloat("fog_depth", fog_depth);
oceanMat.SetFloat("mieCoefficient", mieCoefficient);
oceanMat.SetFloat("mieDirectionalG", mieDirectionalG);
oceanMat.SetFloat("ExposureBias", ExposureBias);
float num5 = 0.002f;
if (!Application.isPlaying)
{
num5 = 0.1f;
}
if (SkyManager.VolCloudGradients)
{
if (flag)
{
oceanMat.SetVector("sunPosition", -SkyManager.SunObj.transform.forward.normalized);
}
else
{
oceanMat.SetVector("sunPosition", -SkyManager.MoonObj.transform.forward.normalized);
}
oceanMat.SetFloat("_Transparency", Mathf.Lerp(a3, Transp, num2 * num));
oceanMat.SetFloat("_HorizonFactor", Mathf.Lerp(a4, Horizon, num2 * num + 0.05f));
float num6 = 0f;
float num7 = 0f;
float num8 = 0f;
if (!CurvesFromSkyMaster)
{
num6 = IntensitySun.Evaluate(SkyManager.calcColorTime) + IntensitySunOffset;
num7 = IntensityDiff.Evaluate(SkyManager.calcColorTime) + IntensityDiffOffset;
num8 = IntensityFog.Evaluate(SkyManager.calcColorTime) + IntensityFogOffset;
}
else
{
num6 = SkyManager.VcloudSunIntensity + IntensitySunOffset;
num7 = SkyManager.VcloudLightDiff + IntensityDiffOffset;
num8 = SkyManager.VcloudFog + IntensityFogOffset;
}
if (WeatherDensity && Application.isPlaying)
{
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm)
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, new Color(StormSunColor.r, StormSunColor.g, StormSunColor.b, num6), 0.8f * num2 * num + num5));
}
else
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, new Color(SkyManager.gradCloudLitColor.r, SkyManager.gradCloudLitColor.g, SkyManager.gradCloudLitColor.b, num6), 0.8f * num2 * num + num5));
}
}
else
{
oceanMat.SetColor("_SunColor", Color.Lerp(color, new Color(SkyManager.gradCloudLitColor.r, SkyManager.gradCloudLitColor.g, SkyManager.gradCloudLitColor.b, num6), 0.8f * num2 * num + num5));
}
oceanMat.SetColor("_ShadowColor", Color.Lerp(color2, new Color(SkyManager.gradCloudShadeColor.r, SkyManager.gradCloudShadeColor.g, SkyManager.gradCloudShadeColor.b, SkyManager.VolCloudTransp), 0.8f * num2 * num + num5));
oceanMat.SetFloat("_ColorDiff", num7);
if (FogFromSkyGrad)
{
oceanMat.SetColor("_FogColor", Color.Lerp(color4, SkyManager.gradSkyColor, 4f * num2 * num + num5));
}
else
{
oceanMat.SetColor("_FogColor", Color.Lerp(color4, SkyManager.gradCloudFogColor, 4f * num2 * num + num5));
}
oceanMat.SetFloat("_FogFactor", num8);
oceanMat.SetFloat("_Coverage", Mathf.Lerp(a2, Coverage, num2 * num + num5));
}
if (WeatherDensity)
{
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm || SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.LightningStorm)
{
Coverage = Mathf.Lerp(Coverage, StormCoverage, num + 0.05f);
Horizon = Mathf.Lerp(Horizon, StormHorizon, num + 0.05f);
EnableLightning = true;
}
else
{
Coverage = Mathf.Lerp(Coverage, ClearDayCoverage, 0.8f * num2 * num + num5);
Horizon = Mathf.Lerp(Horizon, ClearDayHorizon, num + 0.05f);
EnableLightning = false;
}
}
}
private void Update()
{
if (MultiQuadClouds)
{
if (!SideClouds.gameObject.activeInHierarchy)
{
SideClouds.gameObject.SetActive(value: true);
}
if (SideClouds != null && cloudSidesMat != null)
{
SideClouds.localScale = MultiQuadScale;
SideClouds.position = new Vector3(SideClouds.position.x, MultiQuadHeights.x, SideClouds.position.z);
cloudSidesMat.SetFloat("_CutHeight", MultiQuadHeights.y);
}
}
else if (SideClouds.gameObject.activeInHierarchy)
{
SideClouds.gameObject.SetActive(value: false);
}
if (MultiQuadAClouds)
{
if (!SideAClouds.gameObject.activeInHierarchy)
{
SideAClouds.gameObject.SetActive(value: true);
}
if (SideAClouds != null && cloudSidesAMat != null)
{
SideAClouds.localScale = MultiQuadAScale;
SideAClouds.position = new Vector3(SideAClouds.position.x, MultiQuadAHeights.x, SideAClouds.position.z);
cloudSidesAMat.SetFloat("_CutHeight", MultiQuadAHeights.y);
}
}
else if (SideAClouds.gameObject.activeInHierarchy)
{
SideAClouds.gameObject.SetActive(value: false);
}
if (MultiQuadBClouds)
{
if (!SideBClouds.gameObject.activeInHierarchy)
{
SideBClouds.gameObject.SetActive(value: true);
}
if (SideBClouds != null && cloudSidesBMat != null)
{
SideBClouds.localScale = MultiQuadBScale;
SideBClouds.position = new Vector3(SideBClouds.position.x, MultiQuadBHeights.x, SideBClouds.position.z);
cloudSidesBMat.SetFloat("_CutHeight", MultiQuadBHeights.y);
}
}
else if (SideBClouds.gameObject.activeInHierarchy)
{
SideBClouds.gameObject.SetActive(value: false);
}
if (MultiQuadCClouds)
{
if (!SideCClouds.gameObject.activeInHierarchy)
{
SideCClouds.gameObject.SetActive(value: true);
}
if (SideCClouds != null && cloudSidesCMat != null)
{
SideCClouds.localScale = MultiQuadCScale;
SideCClouds.position = new Vector3(SideCClouds.position.x, MultiQuadCHeights.x, SideCClouds.position.z);
cloudSidesCMat.SetFloat("_CutHeight", MultiQuadCHeights.y);
}
}
else if (SideCClouds.gameObject.activeInHierarchy)
{
SideCClouds.gameObject.SetActive(value: false);
}
if (OneQuadClouds)
{
if (!RotClouds.gameObject.activeInHierarchy)
{
RotClouds.gameObject.SetActive(value: true);
}
if (RotClouds != null && cloudRotMat != null)
{
RotClouds.localScale = OneQuadScale;
RotClouds.position = new Vector3(RotClouds.position.x, OneQuadHeights.x, RotClouds.position.z);
cloudRotMat.SetFloat("_CutHeight", OneQuadHeights.y);
}
}
else if (RotClouds.gameObject.activeInHierarchy)
{
RotClouds.gameObject.SetActive(value: false);
}
if (DomeClouds)
{
if (!FlatBedClouds.gameObject.activeInHierarchy)
{
FlatBedClouds.gameObject.SetActive(value: true);
}
if (FlatBedClouds != null && cloudFlatMat != null)
{
FlatBedClouds.localScale = DomeScale;
FlatBedClouds.position = new Vector3(FlatBedClouds.position.x, DomeHeights.x, FlatBedClouds.position.z);
cloudFlatMat.SetFloat("_CutHeight", DomeHeights.y);
}
}
else if (FlatBedClouds.gameObject.activeInHierarchy)
{
FlatBedClouds.gameObject.SetActive(value: false);
}
if (SkyManager != null)
{
if (cloudFlatMat != null && DomeClouds)
{
UpdateCloudParams(Init: false, cloudFlatMat);
}
if (cloudSidesMat != null && (bool)SideClouds)
{
UpdateCloudParams(Init: false, cloudSidesMat);
}
if (cloudSidesAMat != null && (bool)SideAClouds)
{
UpdateCloudParams(Init: false, cloudSidesAMat);
}
if (cloudSidesBMat != null && (bool)SideBClouds)
{
UpdateCloudParams(Init: false, cloudSidesBMat);
}
if (cloudSidesCMat != null && (bool)SideCClouds)
{
UpdateCloudParams(Init: false, cloudSidesCMat);
}
if (cloudRotMat != null && OneQuadClouds)
{
UpdateCloudParams(Init: false, cloudRotMat);
}
}
if (rainbowMat != null)
{
Color color = rainbowMat.GetColor("_Color");
if (!Application.isPlaying)
{
float a = rainboxMaxIntensity;
if (autoRainbow)
{
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Rain || SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm || SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStormDark)
{
a = ((SkyManager.currentWeatherName != SkyMasterManager.Volume_Weather_types.Rain) ? (rainboxMaxIntensity / 3f) : (rainboxMaxIntensity / 1f));
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Cloudy)
{
a = rainboxMinIntensity;
}
}
rainbowMat.SetColor("_Color", new Color(color.r, color.g, color.b, a));
}
else
{
float num = rainboxMaxIntensity;
if (autoRainbow)
{
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Rain || SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStorm || (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.HeavyStormDark && !was_rain))
{
was_rain = true;
was_rain_end_time = Time.fixedTime;
num = ((SkyManager.currentWeatherName != SkyMasterManager.Volume_Weather_types.Rain) ? (rainboxMaxIntensity / 3f) : (rainboxMaxIntensity / 1f));
}
if (SkyManager.currentWeatherName == SkyMasterManager.Volume_Weather_types.Cloudy)
{
if (was_rain)
{
float num2 = Time.fixedTime - was_rain_end_time;
if (num2 > rainbowTime)
{
num = rainboxMaxIntensity / num2;
if (num2 < 0.05f || num2 <= 0f)
{
was_rain = false;
}
}
else
{
num = rainbowTime * rainboxMaxIntensity / num2;
}
}
else
{
num = 0f;
}
if (num > rainboxMaxIntensity)
{
num = rainboxMaxIntensity;
}
}
}
rainbowMat.SetColor("_Color", Color.Lerp(color, new Color(color.r, color.g, color.b, num), Time.deltaTime * 0.001f * rainbowApperSpeed + 0.002f));
}
}
if (!Application.isPlaying)
{
return;
}
if (EnableLightning)
{
if (LightningOne == null)
{
LightningOne = UnityEngine.Object.Instantiate(LightningPrefab).transform;
LightningOne.gameObject.SetActive(value: false);
}
if (LightningTwo == null)
{
LightningTwo = UnityEngine.Object.Instantiate(LightningPrefab).transform;
LightningTwo.gameObject.SetActive(value: false);
}
if (LightningBox != null)
{
if (Time.fixedTime - last_lightning_time > lightning_every - UnityEngine.Random.Range(0f - lightning_rate_offset, lightning_rate_offset))
{
Vector2 vector = LightningBox.position.x * Vector2.one + LightningBox.localScale.x / 2f * new Vector2(-1f, 1f);
Vector2 vector2 = LightningBox.position.y * Vector2.one + LightningBox.localScale.y / 2f * new Vector2(-1f, 1f);
Vector2 vector3 = LightningBox.position.z * Vector2.one + LightningBox.localScale.z / 2f * new Vector2(-1f, 1f);
LightningOne.position = new Vector3(UnityEngine.Random.Range(vector.x, vector.y), UnityEngine.Random.Range(vector2.x, vector2.y), UnityEngine.Random.Range(vector3.x, vector3.y));
if (UnityEngine.Random.Range(0f, SkyManager.WeatherSeverity + 1f) != 1f)
{
LightningOne.gameObject.SetActive(value: true);
}
LightningTwo.position = new Vector3(UnityEngine.Random.Range(vector.x, vector.y), UnityEngine.Random.Range(vector2.x, vector2.y), UnityEngine.Random.Range(vector3.x, vector3.y));
if (UnityEngine.Random.Range(0f, SkyManager.WeatherSeverity + 1f) != 1f)
{
LightningTwo.gameObject.SetActive(value: true);
}
last_lightning_time = Time.fixedTime;
}
else if (Time.fixedTime - last_lightning_time > max_lightning_time)
{
if (LightningOne != null && LightningOne.gameObject.activeInHierarchy)
{
LightningOne.gameObject.SetActive(value: false);
}
if (LightningTwo != null && LightningTwo.gameObject.activeInHierarchy)
{
LightningTwo.gameObject.SetActive(value: false);
}
}
}
}
else
{
if (LightningOne != null && LightningOne.gameObject.activeInHierarchy)
{
LightningOne.gameObject.SetActive(value: false);
}
if (LightningTwo != null && LightningTwo.gameObject.activeInHierarchy)
{
LightningTwo.gameObject.SetActive(value: false);
}
}
if (rotateWithCamera && Camera.main != null)
{
if (RotClouds != null && RotClouds.gameObject.activeInHierarchy)
{
if (!EnableInsideClouds)
{
if (RotCloudsSPlane != null && Application.isPlaying)
{
RotCloudsSPlane.parent = null;
if (!RotCloudsSPlane.gameObject.activeInHierarchy)
{
RotCloudsSPlane.gameObject.SetActive(value: true);
}
}
if (LerpRot)
{
RotClouds.eulerAngles = new Vector3(RotClouds.eulerAngles.x, Mathf.Lerp(RotClouds.eulerAngles.y, Camera.main.transform.eulerAngles.y, Time.deltaTime * 20f), RotClouds.eulerAngles.z);
}
else
{
RotClouds.eulerAngles = new Vector3(RotClouds.eulerAngles.x, Camera.main.transform.eulerAngles.y, RotClouds.eulerAngles.z);
}
}
else
{
float num3 = 0f;
Transform transform = Camera.main.transform;
float num4 = transform.position.y - 100f;
if (num4 > 0f)
{
num3 = num4 / 10f - transform.eulerAngles.x;
Debug.Log(num3);
}
RotClouds.eulerAngles = new Vector3(num3, transform.eulerAngles.y, RotClouds.eulerAngles.z);
}
}
else if (RotCloudsSPlane != null && RotCloudsSPlane.gameObject.activeInHierarchy)
{
RotCloudsSPlane.gameObject.SetActive(value: false);
}
if (SideClouds != null && SideClouds.gameObject.activeInHierarchy)
{
if (!EnableInsideClouds)
{
if (SideSPlane != null && Application.isPlaying)
{
SideSPlane.parent = null;
if (!SideSPlane.gameObject.activeInHierarchy)
{
SideSPlane.gameObject.SetActive(value: true);
}
}
if (LerpRot)
{
SideClouds.eulerAngles = new Vector3(SideClouds.eulerAngles.x, Mathf.Lerp(SideClouds.eulerAngles.y, Camera.main.transform.eulerAngles.y, Time.deltaTime * 20f), SideClouds.eulerAngles.z);
}
else
{
SideClouds.eulerAngles = new Vector3(SideClouds.eulerAngles.x, Camera.main.transform.eulerAngles.y, SideClouds.eulerAngles.z);
}
}
}
else if (SideSPlane != null && SideSPlane.gameObject.activeInHierarchy)
{
SideSPlane.gameObject.SetActive(value: false);
}
if (rotateMultiQuadC && SideCClouds != null && SideCClouds.gameObject.activeInHierarchy)
{
if (!EnableInsideClouds)
{
if (SideCSPlane != null && Application.isPlaying)
{
SideCSPlane.parent = null;
if (!SideCSPlane.gameObject.activeInHierarchy)
{
SideCSPlane.gameObject.SetActive(value: true);
}
}
if (LerpRot)
{
SideCClouds.eulerAngles = new Vector3(SideCClouds.eulerAngles.x, Mathf.Lerp(SideCClouds.eulerAngles.y, Camera.main.transform.eulerAngles.y, Time.deltaTime * 20f), SideCClouds.eulerAngles.z);
}
else
{
SideCClouds.eulerAngles = new Vector3(SideCClouds.eulerAngles.x, Camera.main.transform.eulerAngles.y, SideCClouds.eulerAngles.z);
}
}
}
else if (SideCSPlane != null && SideCSPlane.gameObject.activeInHierarchy)
{
SideCSPlane.gameObject.SetActive(value: false);
}
}
if (followPlayer && SkyManager.Hero != null)
{
SideClouds.position = new Vector3(SkyManager.Hero.position.x, SideClouds.position.y, SkyManager.Hero.position.z);
SideAClouds.position = new Vector3(SkyManager.Hero.position.x, SideAClouds.position.y, SkyManager.Hero.position.z);
SideBClouds.position = new Vector3(SkyManager.Hero.position.x, SideBClouds.position.y, SkyManager.Hero.position.z);
SideCClouds.position = new Vector3(SkyManager.Hero.position.x, SideCClouds.position.y, SkyManager.Hero.position.z);
FlatBedClouds.position = new Vector3(SkyManager.Hero.position.x, FlatBedClouds.position.y, SkyManager.Hero.position.z);
RotClouds.position = new Vector3(SkyManager.Hero.position.x, RotClouds.position.y, SkyManager.Hero.position.z);
if (SideSPlane != null)
{
SideSPlane.position = new Vector3(SkyManager.Hero.position.x, SideSPlane.position.y, SkyManager.Hero.position.z);
}
if (SideCSPlane != null)
{
SideCSPlane.position = new Vector3(SkyManager.Hero.position.x, SideCSPlane.position.y, SkyManager.Hero.position.z);
}
if (RotCloudsSPlane != null)
{
RotCloudsSPlane.position = new Vector3(SkyManager.Hero.position.x, RotCloudsSPlane.position.y, SkyManager.Hero.position.z);
}
}
}
private static Vector3 totalRayleigh(Vector3 lambda)
{
return new Vector3(8f * Mathf.Pow(MathF.PI, 3f) * Mathf.Pow(Mathf.Pow(1.0003f, 2f) - 1f, 2f) * 6.105f / (7.635E+25f * Mathf.Pow(lambda.x, 4f) * 5.755f), 8f * Mathf.Pow(MathF.PI, 3f) * Mathf.Pow(Mathf.Pow(1.0003f, 2f) - 1f, 2f) * 6.105f / (7.635E+25f * Mathf.Pow(lambda.y, 4f) * 5.755f), 8f * Mathf.Pow(MathF.PI, 3f) * Mathf.Pow(Mathf.Pow(1.0003f, 2f) - 1f, 2f) * 6.105f / (7.635E+25f * Mathf.Pow(lambda.z, 4f) * 5.755f));
}
private static Vector3 totalMie(Vector3 lambda, Vector3 K, float T)
{
float num = 0.2f * T * 1E-16f;
return new Vector3(0.434f * num * MathF.PI * Mathf.Pow(MathF.PI * 2f / lambda.x, 2f) * K.x, 0.434f * num * MathF.PI * Mathf.Pow(MathF.PI * 2f / lambda.y, 2f) * K.y, 0.434f * num * MathF.PI * Mathf.Pow(MathF.PI * 2f / lambda.z, 2f) * K.z);
}
}
}