Game.UI.Editor.TimeOfDayWeightsChart
Assembly: Assembly-CSharp (game)
Namespace: Game.UI.Editor
Type: class
Base: Game.UI.Widgets.Widget
Summary:
A UI widget used by the editor to display and serialize a set of time-of-day weights represented as a Unity.Mathematics.float4. The widget keeps an internally normalized copy of the values (between min and max) using math.unlerp, watches an ITypedValueAccessor
Fields
private Unity.Mathematics.float4 m_Value
Internal cached normalized value (components in 0..1 after math.unlerp). Used to track changes and avoid emitting property changes if the value is unchanged.
Properties
-
public float min { get; set; }
Minimum range used when normalizing the accessor value via math.unlerp. -
public float max { get; set; }
Maximum range used when normalizing the accessor value via math.unlerp. -
public ITypedValueAccessor<float4> accessor { get; set; }
Accessor providing the current raw float4 weights. The widget reads accessor.GetTypedValue() each update and normalizes it against min/max.
Constructors
public TimeOfDayWeightsChart()
No explicit constructor is defined in the source; the class uses the default parameterless constructor. Initialization of fields (if needed) should be done in overrides such as OnCreate or by the consumer after instantiation.
Methods
protected override WidgetChanges Update()
Called each frame (or when the widget system updates). Implementation:- Calls base.Update() and stores the result as widgetChanges.
- Reads the current value from accessor via accessor.GetTypedValue().
- Normalizes the value with math.unlerp(min, max, value) producing a float4 in 0..1 range.
- Compares the normalized float4 with the cached m_Value using object.Equals.
- If different, sets the WidgetChanges.Properties flag on widgetChanges and updates the cached m_Value.
-
Returns the combined WidgetChanges. Notes: Uses Unity.Mathematics.math.unlerp and Unity.Mathematics.float4.
-
protected override void WriteProperties(IJsonWriter writer)
Serializes widget properties to JSON. Implementation: - Calls base.WriteProperties(writer).
- Writes a property named "value" and writes the cached m_Value to JSON via writer.Write(m_Value). This is how the normalized time-of-day weights are exported in the UI/widget JSON.
Usage Example
// Create the widget and configure range and accessor.
var chart = new TimeOfDayWeightsChart();
chart.min = 0f;
chart.max = 24f;
// Example accessor that provides the current weights as a float4.
// In actual code this would be implemented to read your model/state.
chart.accessor = myFloat4Accessor; // ITypedValueAccessor<float4>
// The widget will automatically normalize values between min and max each Update()
// and will emit a "value" property (the normalized float4) when WriteProperties is called.
Notes and tips: - math.unlerp(min, max, value) performs per-component (float4) unlerp, mapping from [min, max] to [0,1]. - Ensure accessor is non-null before the widget is updated (or guard accessors in your accessor implementation). - Because equality is checked with object.Equals on float4, small floating-point changes will be detected; consider smoothing/quantizing if you want to reduce frequent property updates.