Game.UI.InGame.ClimateUISystem
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: UISystemBase
Summary:
ClimateUISystem is a UI system that exposes climate-related data (temperature, weather, and current season name) to the UI via GetterValueBinding instances. It queries the game's ClimateSystem each frame and keeps UI bindings up to date, converting the game's internal weather classification and precipitation flags into simple UI-friendly values. The system uses a small amount of smoothing/rounding for temperature and triggers season updates when the current season entity changes.
Fields
-
public const string kGroup = "climate"
Contains the binding group name used when registering GetterValueBinding entries. UI elements use this group name to reference climate bindings. -
private ClimateSystem m_ClimateSystem
Reference to the game's ClimateSystem (retrieved from the ECS world). Used to read temperature, precipitation, classification, and current season info. -
private EntityQuery m_ClimateQuery
EntityQuery intended for climate-related queries. (Declared but not used in the shown code; likely reserved for future ECS queries.) -
private EntityQuery m_ClimateSeasonQuery
EntityQuery intended for season-related queries. (Declared but not used in the shown code; likely reserved.) -
private EntityQuery m_SeasonChangedQuery
EntityQuery intended to detect season changes. (Declared but not used in the shown code; likely reserved.) -
private GetterValueBinding<float> m_TemperatureBinding
Binding that exposes the current temperature (rounded) to the UI under group "climate" and key "temperature". -
private GetterValueBinding<WeatherType> m_WeatherBinding
Binding that exposes the current weather to the UI under group "climate" and key "weather". Uses a delegate writer to serialize the WeatherType. -
private GetterValueBinding<string> m_SeasonBinding
Binding that exposes the current season name ID to the UI under group "climate" and key "seasonNameId". Uses a nullable string writer. -
private Entity m_CurrentSeason
Caches the current season Entity to detect when the season changes so the season binding can be triggered.
Properties
private float m_TemperatureBindingValue { get }
Returns the ClimateSystem.temperature snapped to one decimal place via MathUtils.Snap(..., 0.1f). This is the value supplied to m_TemperatureBinding. The rounding helps avoid frequent tiny UI updates when temperature fluctuates very slightly.
Constructors
public ClimateUISystem()
Default constructor. Marked with [Preserve] (via the attribute on the class methods) so it's preserved for runtime/IL2CPP usage. No custom initialization is performed here; initialization occurs in OnCreate.
Methods
protected override void OnCreate()
Initializes references and registers UI bindings:- Retrieves the ClimateSystem from the ECS World.
-
Creates and registers three GetterValueBinding instances:
- temperature — uses m_TemperatureBindingValue getter.
- weather — uses GetWeather() and a DelegateWriter to write WeatherType.
- seasonNameId — uses GetCurrentSeasonNameID() and a nullable string writer. The bindings are added with group "climate" (kGroup) and the appropriate key names.
-
protected override void OnUpdate()
Called each update to refresh UI bindings: - Calls Update() on temperature and weather bindings.
- Calls Update() on season binding; if Update() returns false (no internal change) but the season entity has changed compared to the cached m_CurrentSeason, it forces an update via TriggerUpdate().
-
Updates m_CurrentSeason to the currentClimateSystem.currentSeason.
-
public WeatherType GetWeather()
Determines the WeatherType to expose to the UI based on ClimateSystem state: - If m_ClimateSystem.isPrecipitating is true, returns Rain if isRaining, Snow if isSnowing, otherwise Clear.
-
If not precipitating, maps the ClimateSystem.classification to WeatherType using FromWeatherClassification().
-
private static WeatherType FromWeatherClassification(ClimateSystem.WeatherClassification classification)
Maps ClimateSystem.WeatherClassification enum values to WeatherType enum values (Clear, Few, Scattered, Broken, Overcast, Storm). Defaults to WeatherType.Clear for unknown classifications. -
private string GetCurrentSeasonNameID()
Returns m_ClimateSystem.currentSeasonNameID — the season name identifier string used for UI localization/display. -
private static void WriteWeatherType(IJsonWriter writer, WeatherType type)
Serializes WeatherType to JSON by writing its integer value. Used as the DelegateWriter for the weather binding.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Typical initialization: get ClimateSystem and register bindings.
m_ClimateSystem = base.World.GetOrCreateSystemManaged<ClimateSystem>();
AddBinding(m_TemperatureBinding = new GetterValueBinding<float>("climate", "temperature", () => MathUtils.Snap(m_ClimateSystem.temperature, 0.1f)));
AddBinding(m_WeatherBinding = new GetterValueBinding<WeatherType>("climate", "weather", GetWeather, new DelegateWriter<WeatherType>(WriteWeatherType)));
AddBinding(m_SeasonBinding = new GetterValueBinding<string>("climate", "seasonNameId", GetCurrentSeasonNameID, ValueWriters.Nullable(new StringWriter())));
}
Notes and modding tips: - GetterValueBinding objects are the bridge between game data and UI. Use AddBinding(...) to expose values and custom writers to control serialization for the UI layer. - The system reduces noise for temperature by snapping to 0.1 increments. If you need finer resolution, modify the snapping behavior (but be cautious of frequent UI updates). - Season updates are detected by comparing the season Entity; TriggerUpdate() is called to force the UI to refresh when a new season entity is observed. - GetWeather() prioritizes precipitation flags (isPrecipitating/isRaining/isSnowing) before falling back to the general classification.