Game.UI.Editor.SeasonsField
Assembly:
Assembly-CSharp.dll
Namespace:
Game.UI.Editor
Type:
class SeasonsField
Base:
Widget
Summary:
UI widget used by the in-game editor to present and edit seasonal data (season list and associated environment curves). SeasonsField relies on an external adapter (IAdapter) to supply and persist the current seasons (IEnumerable
Fields
-
private Entity m_SelectedSeason
Holds the currently selected season as an ECS Entity reference. This field is private and is used internally by the widget to track selection state. -
private List<ClimateSystem.SeasonInfo> m_Seasons = new List<ClimateSystem.SeasonInfo>()
Internal cached list of seasons populated from the adapter every Update. The adapter.seasons is copied into this list so the widget can serialize and inspect seasons. -
private SeasonCurves m_SeasonCurves
Cached SeasonCurves structure (contains AnimationCurves for temperature, precipitation, cloudiness, aurora and fog) provided by the adapter each Update and written out during serialization.
Additional nested types (SeasonCurves, Season, IAdapter, Bindings) are defined inside SeasonsField and contain their own fields (listed and described in the Summary / Methods section below).
Properties
public IAdapter adapter { get; set; }
Adapter used to provide and accept seasonal data. Implement this interface to connect SeasonsField to your data/storage layer. The widget expects the adapter to provide:- selectedSeason (Entity)
- seasons (IEnumerable
) - curves (SeasonCurves)
- RebuildCurves() to be called after seasons or curves change so the adapter can recalculate any dependent state.
Constructors
public SeasonsField()
No explicit constructor is declared in the file; the class uses the default parameterless constructor inherited from the base class.
Methods
protected override WidgetChanges Update()
Called by the UI system. This method:- Calls base.Update()
- Refreshes internal caches: m_Seasons = adapter.seasons.ToList(); m_SeasonCurves = adapter.curves;
- Returns the combined WidgetChanges flags (base | WidgetChanges.Properties) to indicate the widget's properties need re-evaluating/rendering.
Usage note: The adapter must be set prior to Update being called; otherwise adapter access will throw.
protected override void WriteProperties(IJsonWriter writer)
Serializes widget properties to JSON. Writes two properties:- "seasons" — serializes IList
from m_Seasons - "curves" — serializes m_SeasonCurves
Calls base.WriteProperties(writer) first.
Nested types and their important methods:
- SeasonCurves (struct)
- Fields:
- AnimationCurve m_Temperature
- AnimationCurve m_Precipitation
- AnimationCurve m_Cloudiness
- AnimationCurve m_Aurora
- AnimationCurve m_Fog
-
Methods:
- void Write(IJsonWriter writer) — Writes a JSON type named "SeasonsCurves" and serializes each curve (temperature, precipitation, cloudiness, aurora, fog). Note: it only writes if m_Temperature != null (so if curves are not initialized this Write is skipped).
- void Read(IJsonReader reader) — Reads a map and expects properties "temperature", "precipitation", "cloudiness", "aurora", and "fog" to populate the AnimationCurve fields.
-
Season (struct)
Represents a season description with many numeric parameters and: - Entity entity
- string m_Name
- float m_StartTime
- float m_TempNightDay
- float m_TempDeviationNightDay
- float m_CloudChance
- float m_CloudAmount
- float m_CloudAmountDeviation
- float m_PrecipitationChance
- float m_PrecipitationAmount
- float m_PrecipitationAmountDeviation
- float m_Turbulence
- float m_AuroraAmount
- float m_AuroraChance
Methods:
- void Write(IJsonWriter writer) — Serializes fields with property names. Note: there is a likely bug in the original code: the writer calls PropertyName("cloudAmountDeviation") twice — the second time it writes m_PrecipitationChance but uses the cloudAmountDeviation property name (so precipitationChance would be serialized under the wrong property name). Keep this in mind if you rely on round-trip JSON.
- Equality and hashing: Equality is based solely on m_Name (IEquatable
- IAdapter (interface)
Adapter contract to be implemented by callers of SeasonsField. Members: - Entity selectedSeason { get; set; }
- IEnumerable
seasons { get; set; } - SeasonCurves curves { get; set; }
-
void RebuildCurves() — called by the widget after changes to seasons/curves so adapter can rebuild any derived data.
-
Bindings (class) : IWidgetBindingFactory
Produces data bindings used by UI binding system. Important behavior: - CreateBindings(...) returns a CallBinding configured for the "onUpdateSeason" event. When that call is invoked (from UI or data layer) it:
- Finds the matching season in seasonsField.m_Seasons by comparing m_NameID on ClimateSystem.SeasonInfo
- Replaces the matched entry with the incoming season and records the index
- Updates seasonsField.adapter.seasons = seasonsField.m_Seasons and calls adapter.RebuildCurves()
- Calls widget.Update()
- Returns the index of the updated season or -1 if not found
Usage note: This binding is meant to allow other code to push changes to a specific season and let the SeasonsField update its internal state and curves accordingly.
Usage Example
// Minimal adapter stub for connecting SeasonsField to your data
class MySeasonsAdapter : Game.UI.Editor.SeasonsField.IAdapter
{
public Entity selectedSeason { get; set; }
public IEnumerable<ClimateSystem.SeasonInfo> seasons { get; set; } = Enumerable.Empty<ClimateSystem.SeasonInfo>();
public Game.UI.Editor.SeasonsField.SeasonCurves curves { get; set; }
public void RebuildCurves()
{
// Rebuild any cached / derived data based on seasons and curves here.
}
}
// Example of creating and wiring up the widget:
var seasonsField = new Game.UI.Editor.SeasonsField();
seasonsField.adapter = new MySeasonsAdapter()
{
seasons = mySeasonInfoList, // IEnumerable<ClimateSystem.SeasonInfo>
curves = new Game.UI.Editor.SeasonsField.SeasonCurves
{
m_Temperature = new AnimationCurve(...),
m_Precipitation = new AnimationCurve(...),
m_Cloudiness = new AnimationCurve(...),
m_Aurora = new AnimationCurve(...),
m_Fog = new AnimationCurve(...)
}
};
// Let the UI system call Update(); or call manually if needed:
seasonsField.Update();
Notes and tips for modders: - Implement IAdapter to connect SeasonsField to your model/storage. The widget reads adapter.seasons and adapter.curves every Update, and writes back by assigning adapter.seasons after changes (see Bindings). - Serialization: SeasonsField writes both "seasons" and "curves" using the provided IJsonWriter. The nested SeasonWrite method contains a duplicated property name entry (cloudAmountDeviation used twice) — if you implement custom JSON consumers, handle this carefully or patch the source if possible. - Season equality is name-based. If you rely on reference equality or other identifiers, ensure m_Name is unique or extend functionality appropriately.