/// <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; }
// Use this for initialization protected virtual void Start() { //Temporary - DEBUGGING activeWeatherSet = weatherSets[0]; weatherLastFrame = GetWeather(); WeatherEvent currentWeatherEvent = WeatherEventFromWeatherType(weatherLastFrame); currentWeatherEvent.OnActivate(); }