using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; public class UniStormSystem : MonoBehaviour { public static UniStormSystem Instance = null; //Events public UnityEvent OnHourChangeEvent; public UnityEvent OnDayChangeEvent; public UnityEvent OnMonthChangeEvent; public UnityEvent OnYearChangeEvent; public UnityEvent OnWeatherChangeEvent; //Audio Mixer Volumes public float WeatherSoundsVolume = 1; public float AmbienceVolume = 1; public float MusicVolume = 1; //UI public Slider TimeSlider; public GameObject WeatherButtonGameObject; public GameObject TimeSliderGameObject; public Dropdown WeatherDropdown; public EnableFeature UseUniStormMenu = EnableFeature.Enabled; public KeyCode UniStormMenuKey = KeyCode.Escape; public GameObject UniStormCanvas; public bool m_MenuToggle = true; //Editor public int TabNumber = 0; public int TimeTabNumbers = 0; public int WeatherTabNumbers = 0; public int CelestialTabNumbers = 0; public bool TimeFoldout = true, DateFoldout = true, TimeSoundsFoldout = true, TimeMusicFoldout = true, SunFoldout = true, MoonFoldout = true, AtmosphereFoldout = true, WeatherFoldout = true, LightningFoldout = true, CameraFoldout = true, SettingsFoldout = true; public UniStormProfile m_UniStormProfile; public string FilePath = ""; public UniStormProfileTypeEnum UniStormProfileType; public enum UniStormProfileTypeEnum { Import, Export } //Camera & Player public Transform PlayerTransform; public Camera PlayerCamera; public bool m_PlayerFound = false; public EnableFeature UniStormFollowsPlayer = EnableFeature.Disabled; public EnableFeature GetPlayerAtRuntime = EnableFeature.Disabled; public EnableFeature UseRuntimeDelay = EnableFeature.Disabled; public GetPlayerMethodEnum GetPlayerMethod = GetPlayerMethodEnum.ByTag; public enum GetPlayerMethodEnum {ByTag, ByName}; public string PlayerTag = "Player"; public string PlayerName = "Player"; public string CameraTag = "MainCamera"; public string CameraName = "MainCamera"; //Time public System.DateTime UniStormDate; public int StartingMinute = 0; public int StartingHour = 0; public int Minute = 1; public int Hour = 0; public int Day = 0; public int Month = 0; public int Year = 0; public int DayLength = 10; public int NightLength = 10; public float m_TimeFloat; public EnableFeature TimeFlow = EnableFeature.Enabled; public EnableFeature RealWorldTime = EnableFeature.Disabled; float m_roundingCorrection; float m_PreciseCurveTime; public bool m_HourUpdate = false; float m_TimeOfDaySoundsTimer = 0; int m_TimeOfDaySoundsSeconds = 10; public int TimeOfDaySoundsSecondsMin = 10; public int TimeOfDaySoundsSecondsMax = 30; public List MorningSounds = new List(); public List DaySounds = new List(); public List EveningSounds = new List(); public List NightSounds = new List(); public AudioSource TimeOfDayAudioSource; public List MorningMusic = new List(); public List DayMusic = new List(); public List EveningMusic = new List(); public List NightMusic = new List(); public AudioSource TimeOfDayMusicAudioSource; public int TimeOfDayMusicDelay = 1; float m_CurrentMusicClipLength = 0; float m_TimeOfDayMusicTimer = 0; public EnableFeature TimeOfDaySoundsDuringPrecipitationWeather = EnableFeature.Disabled; float m_CurrentClipLength = 0; int m_LastHour; public CurrentTimeOfDayEnum CurrentTimeOfDay; public enum CurrentTimeOfDayEnum { Morning = 0, Day, Evening, Night } public WeatherGenerationMethodEnum WeatherGenerationMethod = WeatherGenerationMethodEnum.Daily; public List WeatherForecast = new List(); public enum WeatherGenerationMethodEnum { Hourly = 0, Daily = 1 } //General Enums public enum EnableFeature { Enabled = 0, Disabled = 1 } //Weather public AnimationCurve PrecipitationGraph = AnimationCurve.Linear(1, 0, 13, 100); public List NonPrecipiationWeatherTypes = new List(); public List PrecipiationWeatherTypes = new List(); public List AllWeatherTypes = new List(); public WeatherType CurrentWeatherType; public WeatherType NextWeatherType; public int m_PrecipitationOdds = 50; float m_CurrentPrecipitationAmountFloat = 1; int m_CurrentPrecipitationAmountInt = 1; public static bool m_IsFading; public int TransitionSpeed = 45; public int HourToChangeWeather; int m_GeneratedOdds; bool m_WeatherGenerated = false; Coroutine CloudCoroutine, FogCoroutine, WeatherEffectCoroutine, AdditionalWeatherEffectCoroutine, ParticleFadeCoroutine; Coroutine AdditionalParticleFadeCoroutine, SunCoroutine, MoonCoroutine, WindCoroutine, SoundInCoroutine, SoundOutCoroutine; Coroutine LightningCloudsCoroutine, ColorCoroutine, CloudHeightCoroutine, RainShaderCoroutine, SnowShaderCoroutine; public WindZone UniStormWindZone; public GameObject m_SoundTransform; public GameObject m_EffectsTransform; Light m_LightningLight; LightningSystem m_UniStormLightningSystem; public LightningStrike m_LightningStrikeSystem; public int LightningSecondsMin = 5; public int LightningSecondsMax = 10; int m_LightningSeconds; float m_LightningTimer; public List LightningFlashPatterns = new List(); public List ThunderSounds = new List(); public int LightningGroundStrikeOdds = 50; public GameObject LightningStrikeEffect; public GameObject LightningStrikeFire; public EnableFeature LightningOnClouds = EnableFeature.Enabled; Material m_LightningFlashMaterial; public int CloudSpeed = 8; public LayerMask DetectionLayerMask; public List LightningFireTags = new List(); public float LightningLightIntensityMin = 1; public float LightningLightIntensityMax = 3; public float CurrentFogAmount; public int LightningGenerationDistance = 100; public int LightningDetectionDistance = 20; public int m_CloudSeed; public Color CurrentFogColor; public float SnowAmount = 0; public float CurrentWindIntensity = 0; WeatherType TempWeatherType; public CurrentSeasonEnum CurrentSeason; public enum CurrentSeasonEnum { Spring = 1, Summer = 2, Fall = 3, Winter = 4 } //Temperature public TemperatureTypeEnum TemperatureType = TemperatureTypeEnum.Fahrenheit; public enum TemperatureTypeEnum { Fahrenheit, Celsius } public AnimationCurve TemperatureCurve = AnimationCurve.Linear(1, -100, 13, 125); public AnimationCurve TemperatureFluctuation = AnimationCurve.Linear(0, -25, 24, 25); public int Temperature; int m_FreezingTemperature; //Celestial Renderer m_CloudDomeRenderer; Renderer m_CloudDomeLightningRenderer; Material m_CloudDomeMaterial; Material m_SkyBoxMaterial; Renderer m_StarsRenderer; Material m_StarsMaterial; Light m_SunLight; Transform m_CelestialAxisTransform; public int SunRevolution = -90; public float SunIntensity = 1; public float PrecipitationSunIntensity = 0.25f; public AnimationCurve SunIntensityCurve = AnimationCurve.Linear(0, 0, 24, 5); public AnimationCurve SunSize = AnimationCurve.Linear(0, 1, 24, 10); Light m_MoonLight; public int MoonPhaseIndex = 5; public float MoonBrightness = 0.7f; public Material m_MoonPhaseMaterial; Renderer m_MoonRenderer; Transform m_MoonTransform; public float MoonIntensity = 1; public float MoonPhaseIntensity = 1; public AnimationCurve MoonIntensityCurve = AnimationCurve.Linear(0, 0, 24, 5); public AnimationCurve MoonSize = AnimationCurve.Linear(0, 1, 24, 10); Vector3 m_MoonStartingSize; GameObject m_MoonParent; public AnimationCurve AtmosphereThickness = AnimationCurve.Linear(0, 1, 24, 3); public float StarSpeed = 0.75f; public int SunAngle = 10; public int MoonAngle = -10; public HemisphereEnum Hemisphere = HemisphereEnum.Northern; public enum HemisphereEnum { Northern = 0, Southern } [System.Serializable] public class MoonPhaseClass { public Texture MoonPhaseTexture = null; public float MoonPhaseIntensity = 1; } public List MoonPhaseList = new List(); //Colors public Gradient SunColor; public Gradient StormySunColor; public Gradient MoonColor; public Gradient SkyColor; public Gradient AmbientSkyLightColor; public Gradient StormyAmbientSkyLightColor; public Gradient AmbientEquatorLightColor; public Gradient StormyAmbientEquatorLightColor; public Gradient AmbientGroundLightColor; public Gradient StormyAmbientGroundLightColor; public Gradient StarLightColor; public Gradient FogColor; public Gradient FogStormyColor; public Gradient CloudLightColor; public Gradient CloudBaseColor; public Gradient CloudStormyBaseColor; public Gradient SkyTintColor; public Color MoonPhaseColor = Color.white; float m_FadeValue; float m_ReceivedCloudValue; public Gradient DefaultCloudBaseColor; GradientColorKey[] CloudColorKeySwitcher; public Gradient DefaultFogBaseColor; GradientColorKey[] FogColorKeySwitcher; public Gradient DefaultAmbientSkyLightBaseColor; GradientColorKey[] AmbientSkyLightColorKeySwitcher; public Gradient DefaultAmbientEquatorLightBaseColor; GradientColorKey[] AmbientEquatorLightColorKeySwitcher; public Gradient DefaultAmbientGroundLightBaseColor; GradientColorKey[] AmbientGroundLightColorKeySwitcher; public Gradient DefaultSunLightBaseColor; GradientColorKey[] SunLightColorKeySwitcher; public List ParticleSystemList = new List(); public List WeatherEffectsList = new List(); public List AdditionalParticleSystemList = new List(); public List AdditionalWeatherEffectsList = new List(); public List WeatherSoundsList = new List(); public ParticleSystem CurrentParticleSystem; public ParticleSystem AdditionalCurrentParticleSystem; public bool UniStormInitialized = false; //AQUAS support comming soon /* #if AQUAS_PRESENT public float m_AQUAS_CurrentFogValue; public bool m_AquasPresent = false; AQUAS_LensEffects m_Aquas; #endif */ public UnityEngine.Audio.AudioMixer UniStormAudioMixer; void Awake () { GameObject m_UniStormManager = new GameObject(); m_UniStormManager.transform.SetParent(this.transform); m_UniStormManager.AddComponent(); m_UniStormManager.name = "UniStorm Manager"; Instance = this; } void Start() { if (GetPlayerAtRuntime == EnableFeature.Enabled) { //Make sure our PlayerTransform is null because we will be looking it up via Unity tag or by name. PlayerTransform = null; //If our player is being received at runtime, wait to intilialize UniStorm until the player has been found. if (UseRuntimeDelay == EnableFeature.Enabled) { StartCoroutine(InitializeDelay()); } //If our player is being received at runtime and UseRuntimeDelay is disabled, get our player immediately by tag. else if (UseRuntimeDelay == EnableFeature.Disabled) { if (GetPlayerMethod == GetPlayerMethodEnum.ByTag) { PlayerTransform = GameObject.FindWithTag(PlayerTag).transform; PlayerCamera = GameObject.FindWithTag(CameraTag).GetComponent(); } else if (GetPlayerMethod == GetPlayerMethodEnum.ByName) { PlayerTransform = GameObject.Find(PlayerName).transform; PlayerCamera = GameObject.Find(CameraName).GetComponent(); } InitializeUniStorm(); } } //If our player is not being received at runtime, initialize UniStorm immediately. else if (GetPlayerAtRuntime == EnableFeature.Disabled) { InitializeUniStorm(); } } //Wait to intilialize UniStorm until the player has been found. IEnumerator InitializeDelay () { yield return new WaitWhile(() => PlayerTransform == null); if (GetPlayerMethod == GetPlayerMethodEnum.ByTag) { PlayerTransform = GameObject.FindWithTag(PlayerTag).transform; PlayerCamera = GameObject.FindWithTag(CameraTag).GetComponent(); } else if (GetPlayerMethod == GetPlayerMethodEnum.ByName) { PlayerTransform = GameObject.Find(PlayerName).transform; PlayerCamera = GameObject.Find(CameraName).GetComponent(); } InitializeUniStorm(); } //Intilialize UniStorm void InitializeUniStorm() { StopCoroutine(InitializeDelay()); if (PlayerTransform == null || PlayerCamera == null) { Debug.LogWarning("(UniStorm has been disabled) - No player/camera has been assigned on the Player Transform/Player Camera slot." + "Please go to the Player & Camera tab and assign one."); GetComponent().enabled = false; } else if (!PlayerTransform.gameObject.activeSelf || !PlayerCamera.gameObject.activeSelf) { Debug.LogWarning("(UniStorm has been disabled) - The player/camera game object is disabled on the Player Transform/Player Camera slot is disabled. " + "Please go to the Player & Camera tab and ensure your player/camera is enabled."); GetComponent().enabled = false; } //If our current weather type is not apart of the available weather type lists, assign it to the proper category. if (!AllWeatherTypes.Contains(CurrentWeatherType)) { AllWeatherTypes.Add(CurrentWeatherType); } if (MusicVolume == 0) { MusicVolume = 0.001f; } if (AmbienceVolume == 0) { AmbienceVolume = 0.001f; } if (WeatherSoundsVolume == 0) { WeatherSoundsVolume = 0.001f; } UniStormAudioMixer = Resources.Load("UniStorm Audio Mixer") as UnityEngine.Audio.AudioMixer; UniStormAudioMixer.SetFloat("MusicVolume", Mathf.Log(MusicVolume) * 20); UniStormAudioMixer.SetFloat("AmbienceVolume", Mathf.Log(AmbienceVolume) * 20); UniStormAudioMixer.SetFloat("WeatherVolume", Mathf.Log(WeatherSoundsVolume) * 20); //Setup the proper settings for our camera PlayerCamera.farClipPlane = 16000; //Setup our sound holder m_SoundTransform = new GameObject(); m_SoundTransform.name = "UniStorm Sounds"; m_SoundTransform.transform.SetParent(PlayerTransform); m_SoundTransform.transform.localPosition = Vector3.zero; //Setup our particle effects holder m_EffectsTransform = new GameObject(); m_EffectsTransform.name = "UniStorm Effects"; m_EffectsTransform.transform.SetParent(PlayerTransform); m_EffectsTransform.transform.localPosition = Vector3.zero; for (int i = 0; i < AllWeatherTypes.Count; i++) { if (AllWeatherTypes[i].PrecipitationWeatherType == WeatherType.Yes_No.Yes && !PrecipiationWeatherTypes.Contains(AllWeatherTypes[i])) { PrecipiationWeatherTypes.Add(AllWeatherTypes[i]); } else if (AllWeatherTypes[i].PrecipitationWeatherType == WeatherType.Yes_No.No && !NonPrecipiationWeatherTypes.Contains(AllWeatherTypes[i])) { NonPrecipiationWeatherTypes.Add(AllWeatherTypes[i]); } } //Sets up and checks all of our weather types for (int i = 0; i < AllWeatherTypes.Count; i++) { //If our weather types have certain features enabled, but there are none detected, disable the feature. if (AllWeatherTypes[i].UseWeatherSound == WeatherType.Yes_No.Yes && AllWeatherTypes[i].WeatherSound == null) { AllWeatherTypes[i].UseWeatherSound = WeatherType.Yes_No.No; } if (AllWeatherTypes[i].UseWeatherEffect == WeatherType.Yes_No.Yes && AllWeatherTypes[i].WeatherEffect == null) { AllWeatherTypes[i].UseWeatherEffect = WeatherType.Yes_No.No; } if (AllWeatherTypes[i].UseAdditionalWeatherEffect == WeatherType.Yes_No.Yes && AllWeatherTypes[i].AdditionalWeatherEffect == null) { AllWeatherTypes[i].UseAdditionalWeatherEffect = WeatherType.Yes_No.No; } //Add all of our weather effects to a list to be controlled when needed. if (!ParticleSystemList.Contains(AllWeatherTypes[i].WeatherEffect) && AllWeatherTypes[i].WeatherEffect != null) { AllWeatherTypes[i].CreateWeatherEffect(); ParticleSystemList.Add(AllWeatherTypes[i].WeatherEffect); } //Add all of our additional weather effects to a list to be controlled when needed. if (!AdditionalParticleSystemList.Contains(AllWeatherTypes[i].AdditionalWeatherEffect)) { if (AllWeatherTypes[i].UseAdditionalWeatherEffect == WeatherType.Yes_No.Yes) { AllWeatherTypes[i].CreateAdditionalWeatherEffect(); AdditionalParticleSystemList.Add(AllWeatherTypes[i].AdditionalWeatherEffect); } } //Create a weather sound for each weather type that has one. if (AllWeatherTypes[i].UseWeatherSound == WeatherType.Yes_No.Yes && AllWeatherTypes[i].WeatherSound != null) { AllWeatherTypes[i].CreateWeatherSound(); } } //Initialize our color switching keys. This allows gradient colors to be switched between stormy and regular. CloudColorKeySwitcher = new GradientColorKey[8]; CloudColorKeySwitcher = CloudBaseColor.colorKeys; DefaultCloudBaseColor.colorKeys = new GradientColorKey[8]; DefaultCloudBaseColor.colorKeys = CloudBaseColor.colorKeys; FogColorKeySwitcher = new GradientColorKey[8]; FogColorKeySwitcher = FogColor.colorKeys; DefaultFogBaseColor.colorKeys = new GradientColorKey[8]; DefaultFogBaseColor.colorKeys = FogColor.colorKeys; AmbientSkyLightColorKeySwitcher = new GradientColorKey[8]; AmbientSkyLightColorKeySwitcher = AmbientSkyLightColor.colorKeys; DefaultAmbientSkyLightBaseColor.colorKeys = new GradientColorKey[8]; DefaultAmbientSkyLightBaseColor.colorKeys = AmbientSkyLightColor.colorKeys; AmbientEquatorLightColorKeySwitcher = new GradientColorKey[8]; AmbientEquatorLightColorKeySwitcher = AmbientEquatorLightColor.colorKeys; DefaultAmbientEquatorLightBaseColor.colorKeys = new GradientColorKey[8]; DefaultAmbientEquatorLightBaseColor.colorKeys = AmbientEquatorLightColor.colorKeys; AmbientGroundLightColorKeySwitcher = new GradientColorKey[8]; AmbientGroundLightColorKeySwitcher = AmbientGroundLightColor.colorKeys; DefaultAmbientGroundLightBaseColor.colorKeys = new GradientColorKey[8]; DefaultAmbientGroundLightBaseColor.colorKeys = AmbientGroundLightColor.colorKeys; SunLightColorKeySwitcher = new GradientColorKey[6]; SunLightColorKeySwitcher = SunColor.colorKeys; DefaultSunLightBaseColor.colorKeys = new GradientColorKey[6]; DefaultSunLightBaseColor.colorKeys = SunColor.colorKeys; CalculatePrecipiation(); CreateSun(); CreateMoon(); //Intialize our other components and set the proper settings from within the editor GameObject TempAudioSource = new GameObject("UniStorm Time of Day Sounds"); TempAudioSource.transform.SetParent(this.transform); TempAudioSource.transform.localPosition = Vector3.zero; TempAudioSource.AddComponent(); TimeOfDayAudioSource = TempAudioSource.GetComponent(); TimeOfDayAudioSource.outputAudioMixerGroup = UniStormAudioMixer.FindMatchingGroups("Master/Ambience")[0]; m_TimeOfDaySoundsSeconds = Random.Range(TimeOfDaySoundsSecondsMin, TimeOfDaySoundsSecondsMax+1); GameObject TempAudioSourceMusic = new GameObject("UniStorm Time of Day Music"); TempAudioSourceMusic.transform.SetParent(this.transform); TempAudioSourceMusic.transform.localPosition = Vector3.zero; TempAudioSourceMusic.AddComponent(); TimeOfDayMusicAudioSource = TempAudioSourceMusic.GetComponent(); TimeOfDayMusicAudioSource.outputAudioMixerGroup = UniStormAudioMixer.FindMatchingGroups("Master/Music")[0]; UniStormWindZone = GameObject.Find("UniStorm Windzone").GetComponent(); m_StarsRenderer = GameObject.Find("UniStorm Stars").GetComponent(); m_StarsMaterial = m_StarsRenderer.material; m_StarsMaterial.SetFloat("_StarSpeed", StarSpeed); m_CloudDomeRenderer = GameObject.Find("UniStorm Clouds").GetComponent(); m_CloudDomeMaterial = m_CloudDomeRenderer.material; m_CloudDomeMaterial.SetVector("_CloudSpeed", new Vector4(CloudSpeed*0.0001f, 0, 0, 0)); m_CloudDomeLightningRenderer = GameObject.Find("UniStorm Clouds (Lightning)").GetComponent(); m_LightningFlashMaterial = m_CloudDomeLightningRenderer.material; //Calculates our start time based off the user's input float StartingMinuteFloat = (int)Minute; if (RealWorldTime == UniStormSystem.EnableFeature.Disabled) { m_TimeFloat = (float)Hour / 24 + StartingMinuteFloat / 1440; } else if (RealWorldTime == UniStormSystem.EnableFeature.Enabled) { m_TimeFloat = (float)System.DateTime.Now.Hour / 24 + (float)System.DateTime.Now.Minute / 1440; } m_LastHour = Hour; m_SunLight.intensity = SunIntensityCurve.Evaluate((float)Hour) * SunIntensity; m_MoonLight.intensity = MoonIntensityCurve.Evaluate((float)Hour) * MoonIntensity * MoonPhaseIntensity; m_SkyBoxMaterial = (Material)Resources.Load("UniStorm Skybox") as Material; RenderSettings.skybox = m_SkyBoxMaterial; m_SkyBoxMaterial.SetFloat("_AtmosphereThickness", AtmosphereThickness.Evaluate((float)Hour)); m_SkyBoxMaterial.SetColor("_NightSkyTint", SkyTintColor.Evaluate((float)Hour)); Temperature = (int)TemperatureCurve.Evaluate(m_PreciseCurveTime) + (int)TemperatureFluctuation.Evaluate((float)StartingHour); if (TemperatureType == TemperatureTypeEnum.Fahrenheit) { m_FreezingTemperature = 32; } else if (TemperatureType == TemperatureTypeEnum.Celsius) { m_FreezingTemperature = 0; } transform.position = new Vector3(PlayerTransform.position.x, transform.position.y, PlayerTransform.position.z); GenerateWeather(); CreateLightning(); UpdateColors(); CalculateClouds(); CalculateMoonPhase(); InitializeWeather(true); CalculateTimeOfDay(); CalculateSeason(); if (WeatherGenerationMethod == WeatherGenerationMethodEnum.Hourly) { WeatherForecast[Hour] = CurrentWeatherType; } //Only create our UniStorm UI if it is enabled if (UseUniStormMenu == UniStormSystem.EnableFeature.Enabled) { CreateUniStormMenu(); } UniStormInitialized = true; //AQUAS support coming soon /* //Look for AQUAS so it can be used elsewhere #if AQUAS_PRESENT m_Aquas = FindObjectOfType(); if (m_Aquas != null) { m_AquasPresent = true; } #endif */ } //Initialize our starting weather so it fades in instantly on start public void InitializeWeather(bool UseWeatherConditions) { //If our starting weather type's conditions are not met, keep rerolling weather until an appropriate one is found. TempWeatherType = CurrentWeatherType; if (UseWeatherConditions) { while (TempWeatherType.TemperatureType == WeatherType.TemperatureTypeEnum.AboveFreezing && Temperature <= m_FreezingTemperature || TempWeatherType.Season != WeatherType.SeasonEnum.All && (int)TempWeatherType.Season != (int)CurrentSeason || TempWeatherType.TemperatureType == WeatherType.TemperatureTypeEnum.BelowFreezing && Temperature > m_FreezingTemperature) { if (TempWeatherType.PrecipitationWeatherType == WeatherType.Yes_No.No) { TempWeatherType = NonPrecipiationWeatherTypes[Random.Range(0, NonPrecipiationWeatherTypes.Count)]; } else if (TempWeatherType.PrecipitationWeatherType == WeatherType.Yes_No.Yes) { TempWeatherType = PrecipiationWeatherTypes[Random.Range(0, PrecipiationWeatherTypes.Count)]; } else { break; } } } CurrentWeatherType = TempWeatherType; m_ReceivedCloudValue = GetCloudLevel(m_ReceivedCloudValue); m_CloudDomeMaterial.SetFloat("_CloudCover", m_ReceivedCloudValue); RenderSettings.fogDensity = CurrentWeatherType.FogDensity; CurrentFogAmount = RenderSettings.fogDensity; UniStormWindZone.windMain = CurrentWeatherType.WindIntensity; CurrentWindIntensity = CurrentWeatherType.WindIntensity; SunIntensity = CurrentWeatherType.SunIntensity; MoonIntensity = CurrentWeatherType.MoonIntensity; if (CurrentWeatherType.ShaderControl == WeatherType.ShaderControlEnum.Rain) { Shader.SetGlobalFloat("_WetnessStrength", 1); Shader.SetGlobalFloat("_SnowStrength", 0); } else if (CurrentWeatherType.ShaderControl == WeatherType.ShaderControlEnum.Snow) { Shader.SetGlobalFloat("_SnowStrength", 1); Shader.SetGlobalFloat("_WetnessStrength", 0); } else { Shader.SetGlobalFloat("_WetnessStrength", 0); Shader.SetGlobalFloat("_SnowStrength", 0); } if (CurrentWeatherType.PrecipitationWeatherType == WeatherType.Yes_No.Yes) { m_CloudDomeMaterial.SetFloat("_WorldPosGlobal", 2500); } for (int i = 0; i < WeatherEffectsList.Count; i++) { ParticleSystem.EmissionModule CurrentEmission = WeatherEffectsList[i].emission; CurrentEmission.rateOverTime = new ParticleSystem.MinMaxCurve(0); } for (int i = 0; i < AdditionalWeatherEffectsList.Count; i++) { ParticleSystem.EmissionModule CurrentEmission = AdditionalWeatherEffectsList[i].emission; CurrentEmission.rateOverTime = new ParticleSystem.MinMaxCurve(0); } //Initialize our weather type's particle effetcs if (CurrentWeatherType.UseWeatherEffect == WeatherType.Yes_No.Yes) { for (int i = 0; i < WeatherEffectsList.Count; i++) { if (WeatherEffectsList[i].name == CurrentWeatherType.WeatherEffect.name + " (UniStorm)") { CurrentParticleSystem = WeatherEffectsList[i]; ParticleSystem.EmissionModule CurrentEmission = CurrentParticleSystem.emission; CurrentEmission.rateOverTime = new ParticleSystem.MinMaxCurve((float)CurrentWeatherType.ParticleEffectAmount); } } CurrentParticleSystem.transform.localPosition = CurrentWeatherType.ParticleEffectVector; } //Initialize our weather type's additional particle effetcs if (CurrentWeatherType.UseAdditionalWeatherEffect == WeatherType.Yes_No.Yes) { for (int i = 0; i < AdditionalWeatherEffectsList.Count; i++) { if (AdditionalWeatherEffectsList[i].name == CurrentWeatherType.AdditionalWeatherEffect.name + " (UniStorm)") { AdditionalCurrentParticleSystem = AdditionalWeatherEffectsList[i]; ParticleSystem.EmissionModule CurrentEmission = AdditionalCurrentParticleSystem.emission; CurrentEmission.rateOverTime = new ParticleSystem.MinMaxCurve((float)CurrentWeatherType.AdditionalParticleEffectAmount); } } AdditionalCurrentParticleSystem.transform.localPosition = CurrentWeatherType.AdditionalParticleEffectVector; } if (CurrentWeatherType.UseLightning == WeatherType.Yes_No.Yes && CurrentWeatherType.UseWeatherEffect == WeatherType.Yes_No.Yes) { Color C = m_LightningFlashMaterial.color; C.a = 0.5f; m_LightningFlashMaterial.color = C; } //Instantly change all of our gradients to the stormy gradients if (CurrentWeatherType.PrecipitationWeatherType == WeatherType.Yes_No.Yes) { for (int i = 0; i < CloudBaseColor.colorKeys.Length; i++) { CloudColorKeySwitcher[i].color = Color.Lerp(CloudColorKeySwitcher[i].color, CloudStormyBaseColor.colorKeys[i].color, 1); } for (int i = 0; i < FogColor.colorKeys.Length; i++) { FogColorKeySwitcher[i].color = Color.Lerp(FogColorKeySwitcher[i].color, FogStormyColor.colorKeys[i].color, 1); } for (int i = 0; i < AmbientSkyLightColor.colorKeys.Length; i++) { AmbientSkyLightColorKeySwitcher[i].color = Color.Lerp(AmbientSkyLightColorKeySwitcher[i].color, StormyAmbientSkyLightColor.colorKeys[i].color, 1); } for (int i = 0; i < AmbientEquatorLightColor.colorKeys.Length; i++) { AmbientEquatorLightColorKeySwitcher[i].color = Color.Lerp(AmbientEquatorLightColorKeySwitcher[i].color, StormyAmbientEquatorLightColor.colorKeys[i].color, 1); } for (int i = 0; i < AmbientGroundLightColor.colorKeys.Length; i++) { AmbientGroundLightColorKeySwitcher[i].color = Color.Lerp(AmbientGroundLightColorKeySwitcher[i].color, StormyAmbientGroundLightColor.colorKeys[i].color, 1); } for (int i = 0; i < SunColor.colorKeys.Length; i++) { SunLightColorKeySwitcher[i].color = Color.Lerp(SunLightColorKeySwitcher[i].color, StormySunColor.colorKeys[i].color, 1); } FogColor.SetKeys(FogColorKeySwitcher, FogColor.alphaKeys); CloudBaseColor.SetKeys(CloudColorKeySwitcher, CloudBaseColor.alphaKeys); AmbientSkyLightColor.SetKeys(AmbientSkyLightColorKeySwitcher, AmbientSkyLightColor.alphaKeys); AmbientEquatorLightColor.SetKeys(AmbientEquatorLightColorKeySwitcher, AmbientEquatorLightColor.alphaKeys); AmbientGroundLightColor.SetKeys(AmbientGroundLightColorKeySwitcher, AmbientGroundLightColor.alphaKeys); SunColor.SetKeys(SunLightColorKeySwitcher, SunColor.alphaKeys); } //Instantly change all of our gradients to the regular gradients else if (CurrentWeatherType.PrecipitationWeatherType == WeatherType.Yes_No.No) { for (int i = 0; i < CloudBaseColor.colorKeys.Length; i++) { CloudColorKeySwitcher[i].color = Color.Lerp(CloudColorKeySwitcher[i].color, DefaultCloudBaseColor.colorKeys[i].color, 1); } for (int i = 0; i < FogColor.colorKeys.Length; i++) { FogColorKeySwitcher[i].color = Color.Lerp(FogColorKeySwitcher[i].color, DefaultFogBaseColor.colorKeys[i].color, 1); } for (int i = 0; i < AmbientSkyLightColor.colorKeys.Length; i++) { AmbientSkyLightColorKeySwitcher[i].color = Color.Lerp(AmbientSkyLightColorKeySwitcher[i].color, DefaultAmbientSkyLightBaseColor.colorKeys[i].color, 1); } for (int i = 0; i < AmbientEquatorLightColor.colorKeys.Length; i++) { AmbientEquatorLightColorKeySwitcher[i].color = Color.Lerp(AmbientEquatorLightColorKeySwitcher[i].color, DefaultAmbientEquatorLightBaseColor.colorKeys[i].color, 1); } for (int i = 0; i < AmbientGroundLightColor.colorKeys.Length; i++) { AmbientGroundLightColorKeySwitcher[i].color = Color.Lerp(AmbientGroundLightColorKeySwitcher[i].color, DefaultAmbientGroundLightBaseColor.colorKeys[i].color, 1); } for (int i = 0; i < SunColor.colorKeys.Length; i++) { SunLightColorKeySwitcher[i].color = Color.Lerp(SunLightColorKeySwitcher[i].color, DefaultSunLightBaseColor.colorKeys[i].color, 1); } FogColor.SetKeys(FogColorKeySwitcher, FogColor.alphaKeys); CloudBaseColor.SetKeys(CloudColorKeySwitcher, CloudBaseColor.alphaKeys); AmbientSkyLightColor.SetKeys(AmbientSkyLightColorKeySwitcher, AmbientSkyLightColor.alphaKeys); AmbientEquatorLightColor.SetKeys(AmbientEquatorLightColorKeySwitcher, AmbientEquatorLightColor.alphaKeys); AmbientGroundLightColor.SetKeys(AmbientGroundLightColorKeySwitcher, AmbientGroundLightColor.alphaKeys); SunColor.SetKeys(SunLightColorKeySwitcher, SunColor.alphaKeys); m_CloudDomeMaterial.SetFloat("_WorldPosGlobal", 0); } foreach (AudioSource A in WeatherSoundsList) { A.volume = 0; } if (CurrentWeatherType.UseWeatherSound == WeatherType.Yes_No.Yes) { foreach (AudioSource A in WeatherSoundsList) { if (A.gameObject.name == CurrentWeatherType.WeatherTypeName + " (UniStorm)") { A.Play(); A.volume = CurrentWeatherType.WeatherVolume; } } } if (CurrentWeatherType.CloudLevel == WeatherType.CloudLevelEnum.MostlyCloudy) { m_CloudDomeMaterial.SetFloat("_WorldPosGlobal", 500); } else if (CurrentWeatherType.CloudLevel == WeatherType.CloudLevelEnum.Cloudy) { m_CloudDomeMaterial.SetFloat("_WorldPosGlobal", 2500); } else { m_CloudDomeMaterial.SetFloat("_WorldPosGlobal", 0); } } //If follow player is enabled, adjust the distant UniStorm components to the player's position void FollowPlayer () { m_CloudDomeRenderer.transform.position = new Vector3(PlayerTransform.position.x, PlayerTransform.position.y - 550, PlayerTransform.position.z); m_MoonLight.transform.position = PlayerTransform.position; m_StarsRenderer.transform.position = PlayerTransform.position; } //Calculate our precipitation odds based on the UniStorm date void CalculatePrecipiation() { CalculateMonths(); //Calculate our months GetDate(); //Calculate our UniStorm date //This algorithm uses an Animation curve to calculate the precipitation odds given the date from the Animation Curve m_roundingCorrection = UniStormDate.DayOfYear * 0.00273972602f; m_PreciseCurveTime = ((UniStormDate.DayOfYear / 28.07692307692308f)) + 1 - m_roundingCorrection; m_PreciseCurveTime = Mathf.Round(m_PreciseCurveTime * 10f) / 10f; m_CurrentPrecipitationAmountFloat = PrecipitationGraph.Evaluate(m_PreciseCurveTime); m_CurrentPrecipitationAmountInt = (int)Mathf.Round(m_CurrentPrecipitationAmountFloat); m_PrecipitationOdds = m_CurrentPrecipitationAmountInt; } //Create and positioned UniStorm's moon void CreateMoon() { m_MoonLight = GameObject.Find("UniStorm Moon").GetComponent(); m_MoonLight.transform.localEulerAngles = new Vector3(-180, MoonAngle, 0); GameObject m_CreatedMoon = Instantiate((GameObject)Resources.Load("UniStorm Moon Object") as GameObject, transform.position, Quaternion.identity); m_CreatedMoon.name = "UniStorm Moon Object"; m_MoonRenderer = GameObject.Find("UniStorm Moon Object").GetComponent(); m_MoonTransform = m_MoonRenderer.transform; m_MoonStartingSize = m_MoonTransform.localScale; m_MoonPhaseMaterial = m_MoonRenderer.material; m_MoonPhaseMaterial.SetColor("_MoonColor", MoonPhaseColor); m_MoonTransform.parent = m_MoonLight.transform; m_MoonTransform.localPosition = new Vector3(0, 0, -11000); m_MoonTransform.localEulerAngles = new Vector3(270, 0, 0); m_MoonTransform.localScale = new Vector3(m_MoonTransform.localScale.x, m_MoonTransform.localScale.y, m_MoonTransform.localScale.z); } //Sets up UniStorm's sun void CreateSun () { m_SunLight = GameObject.Find("UniStorm Sun").GetComponent(); m_SunLight.transform.localEulerAngles = new Vector3(0, SunAngle, 0); m_CelestialAxisTransform = GameObject.Find("Celestial Axis").transform; RenderSettings.sun = m_SunLight; m_SkyBoxMaterial = RenderSettings.skybox; } //Create, setup, and assign all needed lightning components void CreateLightning() { GameObject CreatedLightningSystem = new GameObject("UniStorm Lightning System"); CreatedLightningSystem.AddComponent(); m_UniStormLightningSystem = CreatedLightningSystem.GetComponent(); m_UniStormLightningSystem.transform.SetParent(this.transform); for (int i = 0; i < ThunderSounds.Count; i++) { m_UniStormLightningSystem.ThunderSounds.Add(ThunderSounds[i]); } GameObject CreatedLightningLight = new GameObject("UniStorm Lightning Light"); CreatedLightningLight.AddComponent(); m_LightningLight = CreatedLightningLight.GetComponent(); m_LightningLight.type = LightType.Directional; m_LightningLight.transform.SetParent(this.transform); m_LightningLight.transform.localPosition = Vector3.zero; m_LightningLight.intensity = 0; m_LightningLight.shadows = LightShadows.Hard; m_UniStormLightningSystem.LightningLightSource = m_LightningLight; m_UniStormLightningSystem.PlayerTransform = PlayerTransform; m_UniStormLightningSystem.LightningGenerationDistance = LightningGenerationDistance; m_LightningSeconds = Random.Range(LightningSecondsMin, LightningSecondsMax); m_UniStormLightningSystem.LightningLightIntensityMin = LightningLightIntensityMin; m_UniStormLightningSystem.LightningLightIntensityMax = LightningLightIntensityMax; } //A public function for UniStorm's UI Menu to change the weather with a dropdown public void ChangeWeatherUI () { CurrentWeatherType = AllWeatherTypes[WeatherDropdown.value]; TransitionWeather(); } //If enabled, create our UniStorm UI and Canvas. void CreateUniStormMenu() { //Resource load UI here UniStormCanvas = Instantiate((GameObject)Resources.Load("UniStorm Canvas") as GameObject, transform.position, Quaternion.identity); UniStormCanvas.name = "UniStorm Canvas"; TimeSlider = GameObject.Find("Time Slider").GetComponent(); TimeSliderGameObject = TimeSlider.gameObject; TimeSlider.onValueChanged.AddListener(delegate { CalculateTimeSlider(); }); //Create an event to control UniStorm's time with a slider TimeSlider.maxValue = 0.995f; WeatherButtonGameObject = GameObject.Find("Change Weather Button"); WeatherDropdown = GameObject.Find("Weather Dropdown").GetComponent(); GameObject.Find("Change Weather Button").GetComponent