Hi Guys,
I’m making a weather system. It’ll include warm/cold fronts, precipitation points, temperature, barometric pressure, day/night system, ect. Things like that.
I’ve begun making a little system, but I’m uncertain how to break it up into pieces, if at all. I was wondering could I get a little deliberation here? ![]()
Here’s my class thus far:
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(WindZone))]
public class EnvironmentManager : CDSFramework.CDSEnvironment.EnvironmentManagerFramework {
// Light Vars
[SerializeField] private Gradient nightDayColour;
[SerializeField] private float minLightIntensity;
[SerializeField] private float maxLightIntensity;
[SerializeField] private float minAmbient;
[SerializeField] private float maxAmbient;
// Fog Vars
[SerializeField] private Gradient nightDayFogColour;
[SerializeField] private AnimationCurve fogDensityCurve;
[SerializeField] private float fogScale;
// Atmos Vars
[SerializeField] private float minAtmosDensity;
[SerializeField] private float maxAtmosDensity;
// Time vars
[SerializeField] [Range(0.1f,100)] private float dayRotateSpeed;
[SerializeField] [Range(0.1f, 100)] private float nightRotateSpeed;
[SerializeField] private Vector3 skySpeed;
[SerializeField] private float renderTimeStep;
// Humidity & Precipitation Vars
[SerializeField] private float maxHumidity;
[SerializeField] private float minHumidity;
[SerializeField] private float maxAirTemperature;
[SerializeField] private float minAirTemperature;
[SerializeField] private float humiditySaturationPoint;
// Air Pressure Vars
[SerializeField] private float airPressure;
private float precipitation = 0;
// Instance Vars
private float skyboxRotation = 0;
private bool rendering = false;
private Light directionalLight;
private Skybox sky;
private Material skyMat;
protected override bool Initialise()
{
if((directionalLight = GetComponent<Light>()) && (skyMat = RenderSettings.skybox) )
{
rendering = true;
StartCoroutine(TickRenderEnvironment());
return base.Initialise();
}
return false;
}
// Update World Time, rotating 'Sun & Skies'
void Update()
{
// World Time
float dot = Mathf.Clamp01(Vector3.Dot(directionalLight.transform.forward, Vector3.down));
Vector3 deltaRot = dot > 0 ? dayRotateSpeed * Time.deltaTime * skySpeed : nightRotateSpeed * Time.deltaTime * skySpeed;
transform.Rotate(deltaRot);
skyboxRotation += deltaRot.magnitude;
RenderSettings.skybox.SetFloat("_Rotation", skyboxRotation);
}
// Ticks Rendering
private IEnumerator TickRenderEnvironment()
{
while(rendering)
{
float dot = Mathf.Clamp01(Vector3.Dot(directionalLight.transform.forward, Vector3.down));
float i = ((maxLightIntensity - minLightIntensity) * Mathf.Clamp01(dot)) + minLightIntensity;
// Light Rendering
directionalLight.color = nightDayColour.Evaluate(dot);
RenderSettings.ambientLight = directionalLight.color;
RenderSettings.ambientIntensity = ((maxAmbient - minAmbient) * dot) + minAmbient;
directionalLight.intensity = i;
// Fog Rendering
RenderSettings.fogColor = nightDayFogColour.Evaluate(dot);
RenderSettings.fogDensity = fogDensityCurve.Evaluate(dot) * fogScale;
// Atmospheric Density Rendering
i = ((maxAtmosDensity - minAtmosDensity) * dot) + minAtmosDensity;
RenderSettings.skybox.SetFloat("_Exposure", i);
// Performance Control
yield return new WaitForSeconds(renderTimeStep);
}
}
}
This is only a very basic system and parts will need to depend on external methods already. Like fog will be dependent on the season, air temperature, humidity, air’s saturation point, current air pressure, incoming fronts, time of day. Blah de blah de blah. Point is there’ll be a fair few different things interacting with each other. I’m wondering whether I could get away with it being all in one class, which maybe references a ScriptableObject for world variables. Or whether I need to make a ‘Wind Module’, ‘Humidity Module’, and a master place where the world’s data is sustained to switch between states.
Any takers on advice for architecting this?