protected void Update() { //Convert position to 2D for the queries to the weather system Vector2 position = new Vector2(transform.position.x, transform.position.z); //Get the current weather event and its associated properties WeatherEvent weatherEvent = weatherManager.GetWeatherEventAt(position); WeatherProperties properties = weatherEvent.Properties; float?intensity = properties.EvaluateIntensityData(this.PropertyParent, weatherEvent.WeatherPropertiesIntensityCurves, weatherManager.GetIntensityValueAt(position)); if (intensity == null) { Debug.LogError("Intensity value could not be found"); return; } //This is driven by precipitation, so we want the inverse intensity of that float fireIntensity = 1f - (float)intensity; //Change look of fire based on the intensity ParticleSystem.EmissionModule emission = fireParticleEffect.emission; emission.rateOverTime = fireIntensity * 10; ParticleSystem.MainModule mainModule = fireParticleEffect.main; mainModule.startLifetime = fireIntensity * 5f; }
protected override void LoadValue() { WeatherProperties properties = WeatherManager.instance.m_properties; switch (Name) { case ValueName.MinTemperatureDay: properties.m_minTemperatureDay = (float)(CustomValue ?? Value); break; case ValueName.MaxTemperatureDay: properties.m_maxTemperatureDay = (float)(CustomValue ?? Value); break; case ValueName.MinTemperatureNight: properties.m_minTemperatureNight = (float)(CustomValue ?? Value); break; case ValueName.MaxTemperatureNight: properties.m_maxTemperatureNight = (float)(CustomValue ?? Value); break; case ValueName.MinTemperatureRain: properties.m_minTemperatureRain = (float)(CustomValue ?? Value); break; case ValueName.MaxTemperatureRain: properties.m_maxTemperatureRain = (float)(CustomValue ?? Value); break; case ValueName.MinTemperatureFog: properties.m_minTemperatureFog = (float)(CustomValue ?? Value); break; case ValueName.MaxTemperatureFog: properties.m_maxTemperatureFog = (float)(CustomValue ?? Value); break; case ValueName.RainProbabilityDay: properties.m_rainProbabilityDay = (int)(CustomValue ?? Value); break; case ValueName.RainProbabilityNight: properties.m_rainProbabilityNight = (int)(CustomValue ?? Value); break; case ValueName.FogProbabilityDay: properties.m_fogProbabilityDay = (int)(CustomValue ?? Value); break; case ValueName.FogProbabilityNight: properties.m_fogProbabilityNight = (int)(CustomValue ?? Value); break; case ValueName.NorthernLightsProbability: properties.m_northernLightsProbability = (int)(CustomValue ?? Value); break; } }
protected override bool SetFromProperties() { WeatherProperties properties = WeatherManager.instance.m_properties; switch (Name) { case ValueName.MinTemperatureDay: return(SetValue(properties.m_minTemperatureDay)); case ValueName.MaxTemperatureDay: return(SetValue(properties.m_maxTemperatureDay)); case ValueName.MinTemperatureNight: return(SetValue(properties.m_minTemperatureNight)); case ValueName.MaxTemperatureNight: return(SetValue(properties.m_maxTemperatureNight)); case ValueName.MinTemperatureRain: return(SetValue(properties.m_minTemperatureRain)); case ValueName.MaxTemperatureRain: return(SetValue(properties.m_maxTemperatureRain)); case ValueName.MinTemperatureFog: return(SetValue(properties.m_minTemperatureFog)); case ValueName.MaxTemperatureFog: return(SetValue(properties.m_maxTemperatureFog)); case ValueName.RainProbabilityDay: return(SetValue(properties.m_rainProbabilityDay)); case ValueName.RainProbabilityNight: return(SetValue(properties.m_rainProbabilityNight)); case ValueName.FogProbabilityDay: return(SetValue(properties.m_fogProbabilityDay)); case ValueName.FogProbabilityNight: return(SetValue(properties.m_fogProbabilityNight)); case ValueName.NorthernLightsProbability: return(SetValue(properties.m_northernLightsProbability)); default: return(false); } }
public override void OnInspectorGUI() { serializedObject.Update(); WeatherEvent weatherEvent = (WeatherEvent)target; //Draw default weatherType field FieldInfo weatherTypeField = typeof(WeatherEvent).GetField("weatherType", BindingFlags.Instance | BindingFlags.NonPublic); DrawField(weatherTypeField, serializedObject); //Draw default customProperties field FieldInfo weatherPropertiesField = typeof(WeatherEvent).GetField("customProperties", BindingFlags.Instance | BindingFlags.NonPublic); if (weatherPropertiesField == null) { throw new ArgumentException("WeatherEvent has no customProperties field"); } DrawField(weatherPropertiesField, serializedObject); //draw default property field for customProperties from the serialized property //if there is an assigned weather properties, grab it WeatherProperties weatherProperties = (WeatherProperties)weatherPropertiesField.GetValue(weatherEvent); //check there is one - if there is we do curve stuff, otherwise display a label to tell user to assign one.... if (weatherProperties != null) { FieldInfo nonRealiantPropertiesField = typeof(WeatherProperties).GetField("weatherProperties", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo realiantPropertiesField = typeof(WeatherProperties).GetField("reliantWeatherProperties", BindingFlags.Instance | BindingFlags.NonPublic); WeatherProperty[] weatherPropertyArray = (WeatherProperty[])nonRealiantPropertiesField.GetValue(weatherProperties); ReliantWeatherProperty[] reliantWeatherPropertyArray = (ReliantWeatherProperty[])realiantPropertiesField.GetValue(weatherProperties); FieldInfo curvesField = typeof(WeatherEvent).GetField("curves", BindingFlags.Instance | BindingFlags.NonPublic); AnimationCurve[] curves = (AnimationCurve[])curvesField.GetValue(weatherEvent); int curvesLength = weatherPropertyArray.Length + reliantWeatherPropertyArray.Length; if (curves == null) //first time with this object, need to add new curves for editing { curves = new AnimationCurve[curvesLength]; for (int i = 0; i < curves.Length; i++) { curves[i] = GetDefaultCurve(); } } //need to lengthen or shorten array (or fix a null element) if (curves.Length != curvesLength || curves.Contains(null)) //number of properties has changed etc { AnimationCurve[] newCurves = new AnimationCurve[curvesLength]; if (curves.Length < curvesLength) //less curves than expected... { for (int i = 0; i < curvesLength; i++) { if (i < curves.Length && curves[i] != null) //so fill the curves we have (and replace null elements) { newCurves[i] = curves[i]; } else //for the rest, create a new curve { newCurves[i] = GetDefaultCurve(); } } } else //null elements or longer than expected { for (int i = 0; i < curvesLength; i++) { if (curves[i] == null) //replace null elements with defaults { newCurves[i] = GetDefaultCurve(); } else //fill the rest with the current curves { newCurves[i] = curves[i]; } } } curves = newCurves; } GUILayout.Label(""); curves = DrawWeatherPropertyCurveArray(weatherPropertyArray, curves, 0, "No weather properties"); GUILayout.Label(""); curves = DrawWeatherPropertyCurveArray(reliantWeatherPropertyArray, curves, weatherPropertyArray.Length, "No reliant weather properties"); //Save curves back to the object curvesField.SetValue(weatherEvent, curves); } else { GUILayout.Label("No assigned weather properties, assign one to edit intensity curves"); } EditorUtility.SetDirty(weatherEvent); serializedObject.ApplyModifiedProperties(); }