/// <summary> /// Move between two weather events by transferring intensity from one to the other as defined by our transitionCurve /// </summary> /// <param name="currentWeatherEvent">The current weather event to transition from</param> /// <param name="nextWeatherEvent">The weather event to transition to</param> /// <param name="transitionTime">The amount of time the transition should take</param> /// <param name="nextWeatherTarget">The intensity of the nextWeatherEvent at the completion of the transition</param> /// <param name="time">The time the transition should take</param> private IEnumerator Transition(WeatherEvent currentWeatherEvent, WeatherEvent nextWeatherEvent, float transitionTime, float nextWeatherTarget) { float currentWeatherStartIntensity = currentWeatherEvent.IntensityData.intensity; float currentWeatherTarget = 0f; float nextWeatherStartIntensity = 0f; Vector2 startWind = currentWeatherEvent.IntensityData.wind; if (OnWeatherChangeBeginEvent != null) { OnWeatherChangeBeginEvent(new WeatherChangeEventArgs(nextWeatherEvent, currentWeatherEvent)); } nextWeatherEvent.OnActivate(); float evaluationValue = 0.0f; while (evaluationValue <= transitionTime) { float stepVal = transitionCurve.Evaluate(evaluationValue / transitionTime); float currentWeatherNewIntensity = Mathf.Lerp(currentWeatherStartIntensity, currentWeatherTarget, stepVal); float nextWeatherNewIntensity = Mathf.Lerp(nextWeatherStartIntensity, nextWeatherTarget, stepVal); Vector2 newWind = Vector2.Lerp(startWind, Vector2.one * 0.01f, stepVal); // no wind at all looks unnatural, so we aim for just a very low value if (stepVal < 0.5f) //first half of transition { nextWeatherEvent.IntensityData = new IntensityData(1.0f - currentWeatherNewIntensity, temperatureLastFrame, humidityLastFrame, newWind, nextWeatherEvent.WeatherType); currentWeatherEvent.IntensityData = new IntensityData(currentWeatherNewIntensity, temperatureLastFrame, humidityLastFrame, newWind, currentWeatherEvent.WeatherType); } else //second half of transition { currentWeatherEvent.IntensityData = new IntensityData(currentWeatherNewIntensity, temperatureLastFrame, humidityLastFrame, newWind, currentWeatherEvent.WeatherType); nextWeatherEvent.IntensityData = new IntensityData(1.0f - currentWeatherNewIntensity, temperatureLastFrame, humidityLastFrame, newWind, nextWeatherEvent.WeatherType); } //Debugging intensityPlot.AddKey(timeExtension.CheckedTimeSinceLevelLoadNoUpdate, currentWeatherEvent.Intensity); intensityPlot.AddKey(timeExtension.CheckedTimeSinceLevelLoadNoUpdate + 0.001f, nextWeatherEvent.Intensity); //Fire off the WeatherChangedStep delegate if (OnWeatherChangeStep != null) { OnWeatherChangeStep(new WeatherChangeEventArgs(nextWeatherEvent, currentWeatherEvent)); } yield return(null); evaluationValue += Time.deltaTime; } //re-call OnActivate for the new weather in case there were crossover WeatherProperties down the chain nextWeatherEvent.OnActivate(); //Fire off the OnWeatherChangeCompleteEvent delegate if (OnWeatherChangeCompleteEvent != null) { OnWeatherChangeCompleteEvent(new WeatherChangeEventArgs(nextWeatherEvent, currentWeatherEvent)); } transitionCoroutine = null; }
/// <summary> /// Do an update frame for Procedural mode /// </summary> private void ProceduralUpdate() { if (transitionCoroutine == null) //when no weather transition occuring { WeatherTypes currentWeather = GetWeather(); WeatherEvent currentWeatherEvent = WeatherEventFromWeatherType(weatherLastFrame); if (currentWeather != weatherLastFrame) //If the weather changed this frame { WeatherEvent newWeatherEvent = WeatherEventFromWeatherType(currentWeather); if (currentWeatherEvent == null) { Debug.LogError("No weather event set for " + weatherLastFrame); return; } if (newWeatherEvent == null) { Debug.LogError("No weather event set for " + currentWeather); return; } transitionCoroutine = StartCoroutine(Transition(currentWeatherEvent, newWeatherEvent, weatherEventTransitionTime, currentWeatherEvent.Intensity)); weatherLastFrame = currentWeather; } else //No weather changed, update intensity { float intensity = GetIntensityValueAt(weatherQueryLocation.position); //Generators.GetIntensityNoise(weatherQueryLocation.position.x + trackedX, weatherQueryLocation.position.y + trackedY, worldSize.x, worldSize.y, proceduralScale, 0.00f); Vector2 wind = GetWindValueAt(weatherQueryLocation.position); currentWeatherEvent.IntensityData = new IntensityData(intensity, temperatureLastFrame, humidityLastFrame, wind, currentWeather); intensityPlot.AddKey(new Keyframe(timeExtension.CheckedTimeSinceLevelLoad, currentWeatherEvent.IntensityData.intensity)); } } }
// Use this for initialization protected virtual void Start() { //Temporary - DEBUGGING activeWeatherSet = weatherSets[0]; weatherLastFrame = GetWeather(); WeatherEvent currentWeatherEvent = WeatherEventFromWeatherType(weatherLastFrame); currentWeatherEvent.OnActivate(); }
public WeatherChangeEventArgs(WeatherEvent enteringWeatherEvent, WeatherEvent exitingWeatherEvent) { this.enteringWeatherEvent = enteringWeatherEvent; this.exitingWeatherEvent = exitingWeatherEvent; }