Game.Prefabs.NetPieceLane
Assembly:
Assembly-CSharp (in-game / modding assembly)
{{ This struct is defined in the main game assembly (commonly Assembly-CSharp) used by Cities: Skylines 2. If you are inspecting a compiled game DLL for exact assembly name, it will usually be Assembly-CSharp or a game-specific assembly. }}
Namespace:
Game.Prefabs
{{ The struct lives under the Game.Prefabs namespace, used for prefab-related ECS types. }}
Type:
public struct NetPieceLane : IBufferElementData, IComparable
{{ This is a value type (struct) used as a dynamic buffer element in Unity Entities (ECS). It also implements IComparable
Base:
System.ValueType (struct)
{{ Implements Unity.Entities.IBufferElementData so instances can be stored in DynamicBuffer
Summary:
NetPieceLane represents a single lane entry associated with a net piece prefab. It stores a reference to the lane entity, the lane's position (float3), and extra lane-specific flags. The struct is intended to be used inside an Entity's DynamicBuffer to hold all lanes belonging to a net piece. Its CompareTo implementation compares lanes by their X coordinate (m_Position.x), enabling sorting of lanes along the X axis.
{{ Typical use-cases: storing lane layout data for a road/rail/track piece, iterating lanes for building/construction logic, or sorting lanes left-to-right by X coordinate. }}
Fields
-
public Entity m_Lane
{{ Entity reference to the lane entity. When stored in a DynamicBuffer on a net-piece entity, this links to the lane entity that represents the lane instance in the world. Use this Entity to query or operate on the lane's components. }} -
public float3 m_Position
{{ Position of the lane (vector). The CompareTo implementation uses the X component of this vector to determine ordering. The coordinate space (local vs world) depends on how the game populates this buffer: typically this will be local piece-space or some normalized coordinate along the net piece. }} -
public LaneFlags m_ExtraFlags
{{ Additional lane-related flags stored as a LaneFlags enum (game-specific). These flags indicate extra attributes of the lane (e.g., vehicle types allowed, turn restrictions, sidewalk/parking flags, or other custom per-lane metadata). Refer to the LaneFlags enum definition in the game's codebase for exact meanings. }}
Properties
- None (no explicit properties are declared)
{{ The struct exposes only public fields and implements interfaces; there are no C# properties. }}
Constructors
public NetPieceLane()
(default struct constructor)
{{ No explicit constructors are declared in the source. Instances are created with the default struct constructor or by object/collection initializers when added to buffers. Example: new NetPieceLane { m_Lane = entity, m_Position = new float3(x,y,z), m_ExtraFlags = flags } }}
Methods
public int CompareTo(NetPieceLane other)
{{ Compares this NetPieceLane to another by the X component of m_Position. Implementation detail: it uses Unity.Mathematics.math.select to produce -1, 0, or 1 based on comparison:- returns -1 if this.m_Position.x < other.m_Position.x
- returns 1 if this.m_Position.x > other.m_Position.x
- returns 0 if equal This is useful for sorting collections of NetPieceLane left-to-right along the X axis. Note it only compares X (not Y or Z). }}
Example behavior explanation of the original implementation: - math.select(-1, 1, m_Position.x > other.m_Position.x) resolves to -1 when this.x <= other.x, or 1 when this.x > other.x. - The outer math.select chooses 0 when m_Position.x == other.m_Position.x, otherwise it returns the -1/1 result from the inner select. This yields the classic three-way comparison (-1, 0, 1) based on X component.
Usage Example
// Adding lanes to a DynamicBuffer on a net-piece entity
var buffer = entityManager.GetBuffer<NetPieceLane>(netPieceEntity);
buffer.Add(new NetPieceLane {
m_Lane = laneEntity,
m_Position = new float3(1.25f, 0f, 0.0f), // position used for ordering
m_ExtraFlags = LaneFlags.None // example flag
});
// Comparing two lanes (IComparable)
NetPieceLane a = buffer[0];
NetPieceLane b = buffer[1];
int cmp = a.CompareTo(b);
if (cmp < 0) {
// a is left of b (a.m_Position.x < b.m_Position.x)
} else if (cmp > 0) {
// a is right of b (a.m_Position.x > b.m_Position.x)
} else {
// same X position
}
// If you need to sort lanes by X, you can copy them to an array and use Array.Sort,
// which will use CompareTo:
var arr = new NetPieceLane[buffer.Length];
for (int i = 0; i < buffer.Length; i++) arr[i] = buffer[i];
Array.Sort(arr); // sorts by m_Position.x via CompareTo
// After sorting you can write back to the buffer or use the ordered array for processing.
{{ Notes and recommendations: - InternalBufferCapacity(0) attribute: this struct is annotated with [InternalBufferCapacity(0)], indicating that no inline buffer capacity is reserved on the entity; the DynamicBuffer will allocate storage externally. This is an optimization/detail relevant to ECS buffering. - Because CompareTo uses only the X component, ensure the intended ordering axis is X in your coordinate system. If you need sort by another axis or a compound key, implement a separate comparer or extend the logic accordingly. - Check the LaneFlags enum in the game code for exact meanings of any flags you set or read. }}