using BitStrap; using UltimateWater; using UnityEngine; using uNature.Core.FoliageClasses; public class WeatherLevelManager : MonoBehaviour { [HideInInspector] public GameController gameController; public float startHour = 7f; public int temperatureType = 1; public float minTemperature = 15f; public float maxTemperature = 32f; public int pressure; public float cloudiness; public float fog; public Vector2 fogRange = new Vector2(0.01f, 1f); [ReadOnly] public float hourFog; [Space(10f)] public float precipitation; public Vector2 rainEmission = new Vector2(1000f, 5000f); public Vector2 snowEmission = new Vector2(1000f, 5000f); [Space(10f)] public float windStrength; public float windDirection; public WindZone windZone; public float maxWindStrength = 15f; public Vector2 windZoneMainBounds = Vector2.zero; public Vector2 windZoneTurbulanceBounds = Vector2.zero; [ReadOnly] public WaterProfileBlend waterProfileBlend; [Space(10f)] public AnimationCurve pressureCurve = AnimationCurve.Linear(0f, 0f, 24f, 0f); public AnimationCurve temperatureCurve = AnimationCurve.Linear(0f, 0f, 24f, 0f); public AnimationCurve fogCurve = AnimationCurve.Linear(0f, 0f, 24f, 0f); public float normalTimeSpeed = 120f; public bool timeSpeedTest; [HideInInspector] public AudioObject windAudioObject; public AudioObject rainAudioObject; [Space(10f)] public bool updateChangeWeather = true; [ReadOnly] public float changeWeatherTimer; [ReadOnly] public int prevWeatherPartChange = -1; public bool showCausticsInEditor; private bool firstUpdate = true; private void Awake() { RenderSettings.fog = true; } private void Start() { changeWeatherTimer = 60f; } public void UpdateHourWeather() { if (firstUpdate && (bool)waterProfileBlend) { UpdateWaterProfiles(); firstUpdate = false; } if ((bool)gameController.fishingPlayer.volumetricFog) { gameController.fishingPlayer.volumetricFog.density = GetHourFog(); gameController.fishingPlayer.volumetricFog.lightColor = gameController.azureSkyController.VolumetricFogGradientColor[gameController.azureSkyController.DAY_of_WEEK].Evaluate(gameController.azureSkyController.getGradientTime); } if (updateChangeWeather) { changeWeatherTimer -= Time.deltaTime; if (changeWeatherTimer <= 0f) { ChangeWeather(); } } } public int GetHour() { return Mathf.FloorToInt(gameController.azureSkyController.TIME_of_DAY); } public void SetHour(float hour) { gameController.azureSkyController.TIME_of_DAY = hour; } public int GetMinutes() { return Mathf.FloorToInt((gameController.azureSkyController.TIME_of_DAY - (float)GetHour()) * 60f); } public float GetFullTime() { return gameController.azureSkyController.TIME_of_DAY; } public int GetPressure() { return Mathf.RoundToInt(pressureCurve.Evaluate(gameController.azureSkyController.TIME_of_DAY) * (float)pressure); } public int GetTemperature() { return Mathf.RoundToInt(Mathf.Lerp(minTemperature, maxTemperature, temperatureCurve.Evaluate(GetFullTime()))); } public float GetWindSpeed() { return windStrength; } public float GetWindHUDSpeed() { return windStrength * maxWindStrength; } public float GetCloudiness() { return cloudiness; } public float GetFog() { return Mathf.Lerp(0.01f, 0.11f, fog); } public float GetHourFog() { return GetFog() * fogCurve.Evaluate(GetHour()); } public float GetPercipitation() { return precipitation; } public float GetWindZoneMain() { return Mathf.Lerp(windZoneMainBounds.x, windZoneMainBounds.y, windStrength); } public float GetWindZoneTurbulance() { return Mathf.Lerp(windZoneTurbulanceBounds.x, windZoneTurbulanceBounds.y, windStrength); } public float GetWindClouds() { if ((bool)gameController.uniStormSystem) { return Mathf.Lerp(9f, 80f, windStrength); } if ((bool)gameController.azureSkyController) { return Mathf.Lerp(0.1f, 3.5f, windStrength); } return 0f; } public Vector4 GetWindGrass() { return Vector4.Lerp(new Vector4(0.034f, 0.78f, 0.0217f, 0.217f), new Vector4(0.2f, 3f, 0.15f, 3f), windStrength); } public float GetWindGrassUNature(float grassWindStrength) { return Mathf.Lerp(0.5f, 2.7f, grassWindStrength); } public float GetWindFog() { return Mathf.Lerp(0.01f, 0.03f, windStrength); } public void UpdateWeather(bool fromWeatherSettings) { if (fromWeatherSettings && (bool)gameController.weatherSettings) { timeSpeedTest = gameController.weatherSettings.randomTest; temperatureType = (int)gameController.weatherSettings.temperature; pressure = (int)gameController.weatherSettings.pressure; cloudiness = gameController.weatherSettings.clouds; fog = Mathf.Clamp(gameController.weatherSettings.fog, fogRange.x, fogRange.y); precipitation = gameController.weatherSettings.precipitation; windStrength = gameController.weatherSettings.windStrength; windDirection = gameController.weatherSettings.windDirection; } waterProfileBlend = gameController.water.GetComponent(); if ((bool)waterProfileBlend) { waterProfileBlend.Water = gameController.water; } gameController.azureSkyController.DAY_CYCLE = ((!timeSpeedTest) ? normalTimeSpeed : 5f); if (fromWeatherSettings) { if (gameController.isTournament && (bool)GlobalSettings.Instance) { gameController.azureSkyController.TIME_of_DAY = GlobalSettings.Instance.weatherSettings.hour; } else if ((bool)gameController.fisheryEditorGame) { gameController.azureSkyController.TIME_of_DAY = 7f; } else { gameController.azureSkyController.TIME_of_DAY = ((!GlobalSettings.Instance) ? 11f : startHour); } } SetPrecipitation(precipitation); if ((bool)gameController.globalSettings) { LevelsManager.FisheryDefinition currentFishery = gameController.globalSettings.levelsManager.GetCurrentFishery(); minTemperature = (int)currentFishery.temperatureNormal[temperatureType] - 10; maxTemperature = (int)currentFishery.temperatureNormal[temperatureType] + 10; } if (precipitation >= 1f) { cloudiness = Random.Range(0.85f, 1f); } SetCloudiness(cloudiness); SetWindStrength(windStrength); SetGrassWindStrength(windStrength); SetWindDirection(windDirection); SetFogDensity(fog); gameController.azureSkyController.SkyUpdate(); } public void SetPrecipitation(float factor) { if (gameController == null) { return; } precipitation = factor; if (precipitation > 0f) { if (gameController.iceLevel) { gameController.fishingPlayer.snow.SetEmissionRate(Mathf.Lerp(snowEmission.x, snowEmission.y, precipitation)); gameController.fishingPlayer.snow.Play(); if ((bool)gameController.fishingPlayer.waterDropsRainMy) { gameController.fishingPlayer.waterDropsRainMy.enabled = false; } return; } gameController.fishingPlayer.rain.SetEmissionRate(Mathf.Lerp(rainEmission.x, rainEmission.y, precipitation)); gameController.fishingPlayer.rain.Play(); if ((bool)gameController.fishingPlayer.waterDropsRainMy) { gameController.fishingPlayer.waterDropsRainMy.enabled = true; } if ((bool)rainAudioObject) { rainAudioObject.Unpause(12f); } else { rainAudioObject = AudioController.Play("Rain_01", precipitation); } } else { gameController.fishingPlayer.snow.Stop(true); gameController.fishingPlayer.rain.Stop(true); if ((bool)gameController.fishingPlayer.waterDropsRainMy) { gameController.fishingPlayer.waterDropsRainMy.enabled = false; } if ((bool)rainAudioObject) { rainAudioObject.Pause(10f); } } } public void SetCloudiness(float factor) { if (!(gameController == null)) { cloudiness = factor; gameController.azureSkyController.WispyCovarage = Mathf.Lerp(5f, 0f, cloudiness); } } public void SetWindStrength(float factor) { if (!(gameController == null)) { windStrength = factor; if (windStrength < 0.01f) { windStrength = 0.01f; } windZone.windMain = GetWindZoneMain(); windZone.windTurbulence = GetWindZoneTurbulance(); if ((bool)gameController.fishingPlayer.volumetricFog) { gameController.fishingPlayer.volumetricFog.speed = GetWindFog(); } gameController.azureSkyController.WispyCloudSpeed = GetWindClouds(); UpdateWaterProfiles(); if (windAudioObject == null) { windAudioObject = AudioController.Play("WindStrong_01", windStrength); } if ((bool)windAudioObject) { windAudioObject.volume = windStrength * 0.13f; } } } public void SetGrassWindStrength(float factor) { if (!(gameController == null) && (bool)FoliageCore_MainManager.instance) { FoliageDB.instance.globalWindSettings.windSpeed = GetWindGrassUNature(factor); } } public void SetWindDirection(float factor) { if (!(gameController == null)) { windDirection = factor; windZone.transform.eulerAngles = new Vector3(0f, windDirection, 0f); gameController.azureSkyController.WispyCloudDirection = (360f - windDirection) / 60f; if ((bool)gameController.fishingPlayer.volumetricFog) { gameController.fishingPlayer.volumetricFog.windDirection = -windZone.transform.forward; } } } public void SetFogDensity(float factor) { if (!(gameController == null)) { fog = factor; if ((bool)gameController.fishingPlayer.volumetricFog) { gameController.fishingPlayer.volumetricFog.density = GetHourFog(); } } } public void UpdateWaterProfiles() { if (gameController == null) { return; } if ((bool)gameController.fisheryEditorGame && gameController.iceLevel) { waterProfileBlend.Water.ProfilesManager.Profiles[0].Weight = 1f; waterProfileBlend.Water.ProfilesManager.Profiles[1].Weight = 0f; waterProfileBlend.Water.ProfilesManager.OnValidate(); } else if ((bool)waterProfileBlend && waterProfileBlend.Water.ProfilesManager.Profiles.Length > 1) { float num = windStrength; if (gameController.oceanLevel && gameController.fishingPlayer.currentState != FishingPlayer.PlayerState.DRIVING_BOAT) { num = ((gameController.fishingPlayer.currentState == FishingPlayer.PlayerState.WATCH_FISH && gameController.fishingPlayer.fish.watchStyle == Fish.WatchStyle.BOAT) ? (num * 0.5f) : ((!gameController.fishingPlayer.underwaterCamera.isTurnedOn) ? (num * 0.75f) : (num * 0f))); } waterProfileBlend.Water.ProfilesManager.Profiles[0].Weight = 1f - num; waterProfileBlend.Water.ProfilesManager.Profiles[1].Weight = num; waterProfileBlend.Water.ProfilesManager.OnValidate(); } } [Button] public void ChangeWeather(bool instant = false) { if (gameController == null || (gameController.isTournament && !PhotonNetwork.isMasterClient)) { return; } float num = 0f; float num2 = 0f; int num3 = -1; for (int i = 0; i < 10; i++) { num3 = Random.Range(0, 4); if (num3 != prevWeatherPartChange) { break; } } if (num3 == 0) { num = Random.Range(0f, 1f); if (precipitation > 0f || num < 0.25f) { SetPrecipitation((!(precipitation > 0f)) ? 1f : 0f); } Debug.Log("Precipitation newFactor: " + num); } switch (num3) { case 1: num = Random.Range(20f, 40f); num2 = num; if (Random.Range(0f, 1f) < 0.5f) { num *= -1f; } num = windDirection + num; if (instant) { SetWindDirection(Utilities.GetAngleNormalRange(num)); } else { LeanTween.value(windDirection, num, num2 * 0.4f).setEaseInOutQuad().setOnUpdate(delegate(float val) { SetWindDirection(Utilities.GetAngleNormalRange(val)); }); } num = Random.Range(0.3f, 0.6f); if (windStrength > 0.8f || (windStrength > 0.2f && Random.Range(0f, 1f) < 0.5f)) { num *= -1f; } num = Mathf.Clamp01(windStrength + num); SetGrassWindStrength(num); if (instant) { SetWindStrength(num); break; } LeanTween.value(windStrength, num, 15f).setEaseInOutQuad().setOnUpdate(delegate(float val) { SetWindStrength(val); }); break; case 2: num = Random.Range(0.3f, 0.6f); if (fog > 0.8f || (fog > 0.2f && Random.Range(0f, 1f) < 0.5f)) { num *= -1f; } num = Mathf.Clamp(fog + num, fogRange.x, fogRange.y); if (instant) { SetFogDensity(num); break; } LeanTween.value(fog, num, 5f).setEaseInOutQuad().setOnUpdate(delegate(float val) { SetFogDensity(val); }); break; case 0: case 3: num = Random.Range(0.3f, 0.6f); if (cloudiness > 0.8f || (cloudiness > 0.2f && Random.Range(0f, 1f) < 0.5f)) { num *= -1f; } num = Mathf.Clamp01(cloudiness + num); if (precipitation >= 1f) { num = Random.Range(0.85f, 1f); } if (instant) { SetCloudiness(num); break; } LeanTween.value(cloudiness, num, 5f).setEaseInOutQuad().setOnUpdate(delegate(float val) { SetCloudiness(val); }); break; } prevWeatherPartChange = num3; changeWeatherTimer = Random.Range(180f, 360f); if (gameController.isTournament && PhotonNetwork.isMasterClient) { MultiplayerManager.Instance.UpdateWeather(); } } [Button] public void ChangeTimeScale() { if (Time.timeScale == 1f) { Time.timeScale = 4f; gameController.azureSkyController.DAY_CYCLE = 1f; } else { Time.timeScale = 1f; gameController.azureSkyController.DAY_CYCLE = normalTimeSpeed; } gameController.azureSkyController.SetTime(gameController.azureSkyController.TIME_of_DAY, gameController.azureSkyController.DAY_CYCLE); } }