Game.UI.InGame.RoadSection
Assembly: Assembly-CSharp (game assembly)
Namespace: Game.UI.InGame
Type: class
Base: InfoSectionBase
Summary:
RoadSection is a UI info panel section that aggregates and reports statistics for a selected road "aggregate" (an aggregate entity composed of multiple net edges). It collects per-edge data (length, traffic volume, traffic flow/speed, condition/wear and upkeep cost) using ECS components (AggregateElement, Road, Curve, NetCondition, PrefabRef / PlaceableNetData) and produces normalized arrays and scalar values suitable for the UI and JSON serialization. The class uses internal buffers of length 5 for volume/flow data (the 5th entry duplicates the first for UI graphing convenience). Methods include lifecycle hooks to initialize, reset, update visibility and process the aggregated data, and writing the results to a JSON writer.
Fields
-
private float[] m_Volume
Array (length 5) storing aggregated traffic volume buckets. Indices 0..3 hold averaged values computed from per-edge flow distances; index 4 is set to the same value as index 0 (presumably for graph wrapping). -
private float[] m_Flow
Array (length 5) storing aggregated traffic flow/speed buckets. Indices 0..3 hold averaged speeds, index 4 mirrors index 0.
Properties
-
protected override string group { get; }
Returns the UI group id/name used by the base InfoSection. In this class it returns the constant "RoadSection". This property identifies this section to the parent UI. -
private float length { get; set; }
Total accumulated length of all edges in the aggregate (sum of Curve.m_Length). -
private float bestCondition { get; set; }
Computed best (minimum wear) condition across edges, converted into a percentage (0..100). Internally computed from NetCondition.m_Wear values and converted at the end of processing. -
private float worstCondition { get; set; }
Computed worst (maximum wear) condition across edges, converted into a percentage (0..100). -
private float condition { get; set; }
Average condition across the aggregate, converted into a percentage (0..100) after processing. -
private float upkeep { get; set; }
Accumulated upkeep cost for the aggregate: sum of PlaceableNetData.m_DefaultUpkeepCost for each edge's prefab.
Constructors
public RoadSection()
Parameterless constructor. Marked with [Preserve] attribute in the source. Does not perform initialization of the arrays — initialization happens in OnCreate.
Methods
protected override void OnCreate() : System.Void
Initializes the section. Allocates the internal arrays used for volume and flow aggregation:- m_Volume = new float[5];
-
m_Flow = new float[5]; This method calls base.OnCreate() first. Marked with [Preserve].
-
protected override void Reset() : System.Void
Resets aggregated state between uses: zeroes the m_Volume and m_Flow arrays, sets length = 0f, bestCondition = 100f, worstCondition = 0f, condition = 0f and upkeep = 0f. This prepares the section to receive fresh data on the next process pass. -
protected override void OnUpdate() : System.Void
Updates visibility of this UI section. The code sets visible to true only when the currently selected entity has both Aggregate and AggregateElement components in the EntityManager: base.visible = base.EntityManager.HasComponent(selectedEntity) && base.EntityManager.HasComponent (selectedEntity); -
protected override void OnProcess() : System.Void
Core data aggregation routine. It: - Retrieves the DynamicBuffer
for the selected aggregate entity. - Iterates each AggregateElement (each references an edge Entity).
- For edges that have Road and Curve components:
- Adds Curve.m_Length to total length.
- Computes per-lane/segment flow distances as (m_TrafficFlowDistance0 + m_TrafficFlowDistance1) * 16f (produces a float4).
- Computes per-lane speeds via NetUtils.GetTrafficFlowSpeed(component) * 100f (float4).
- Increments m_Volume[0..3] using the float4 components multiplied by 4f/24f (scaling used by the game); m_Flow[0..3] incremented by the corresponding speeds.
- For edges that have NetCondition component:
- Reads wear (float2). Updates bestCondition/worstCondition based on wear.x/wear.y (bestCondition keeps the minimum wear value, worstCondition keeps the maximum).
- Accumulates average wear (math.csum(wear) * 0.5f) into condition.
- For edges that have PrefabRef and a PlaceableNetData prefab:
- Adds the prefab's m_DefaultUpkeepCost into upkeep.
- After the loop the method normalizes the m_Volume and m_Flow arrays by dividing the first four entries by buffer.Length and sets the 5th entry equal to the 1st (m_Volume[4] = m_Volume[0], m_Flow[4] = m_Flow[0]).
- Converts bestCondition and worstCondition from raw wear values into percentages: bestCondition = 100f - bestCondition / 10f * 100f; worstCondition = 100f - worstCondition / 10f * 100f;
- Converts the accumulated condition into an average percentage: condition = condition / 10f * 100f; condition = 100f - condition / (float)buffer.Length;
Notes: wear values are interpreted on a 0..10 scale; the conversions produce 0..100 percentage values where higher means better condition.
public override void OnWriteProperties(IJsonWriter writer) : System.Void
Serializes aggregated properties into the provided IJsonWriter. It emits:- "volumeData": array of m_Volume values (length 5)
- "flowData": array of m_Flow values (length 5)
- "length": total length (float)
- "bestCondition": best condition percent (float)
- "worstCondition": worst condition percent (float)
- "condition": average condition percent (float)
- "upkeep": total upkeep cost (float)
All arrays and scalars are written as JSON numeric values.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_Volume = new float[5];
m_Flow = new float[5];
}
Notes and implementation details: - The class is marked [CompilerGenerated] in the source and some members/constructor are marked [Preserve] to prevent stripping. - It depends on several ECS component types: Aggregate, AggregateElement, Road, Curve, NetCondition, PrefabRef, PlaceableNetData, and uses NetUtils.GetTrafficFlowSpeed for speed data. - The m_Volume and m_Flow arrays are averaged over the number of elements (buffer.Length), so for small aggregates the values reflect per-aggregate averages rather than raw sums. - The volume scaling (multiplying by 16f, then 4f/24f) and speed 100 are game-specific conversions to make the raw data suitable for UI display.