Game.TrainCurrentLane
Assembly:
Assembly-CSharp
Namespace:
Game.Vehicles
Type:
struct TrainCurrentLane : IComponentData, IQueryTypeParameter, ISerializable
Base:
IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents the current lane/position information for a train; used by the vehicle/trains systems to track the front and rear bogie (wheelset) lane positions, their cached lookups, and simple timing/distance bookkeeping. This component is designed to be used with Unity's DOTS ECS (IComponentData) and supports custom game serialization via Colossal.Serialization.Entities (ISerializable). It provides constructors for initializing from a PathElement (in-transit train) or a ParkedTrain (stationary/parked train) and implements Serialize/Deserialize that are version-aware.
Fields
-
public TrainBogieLane m_Front
Holds lane and curve information for the front bogie of the train. Constructed from a PathElement or ParkedTrain lane/curve position. -
public TrainBogieLane m_Rear
Holds lane and curve information for the rear bogie of the train. -
public TrainBogieCache m_FrontCache
Cached lookup data for the front bogie (likely used to speed up repeated lane/curve queries). -
public TrainBogieCache m_RearCache
Cached lookup data for the rear bogie. -
public float m_Duration
A float tracking elapsed time/duration related to the current lane state. Note: this field is serialized/deserialized only when reader.context.version >= Version.trafficFlowFixes (backwards compatibility). -
public float m_Distance
A float tracking travelled distance or offset related to the current lane state. Also conditionally serialized/deserialized depending on save version (Version.trafficFlowFixes).
Properties
- This type does not declare any C# properties. It exposes public fields only.
Constructors
-
public TrainCurrentLane(PathElement pathElement)
Initializes front/rear bogie lane and cache from a PathElement (used for trains that are currently moving on a path). Sets m_Duration and m_Distance to 0. -
public TrainCurrentLane(ParkedTrain parkedTrain)
Initializes front/rear bogie lane and cache from a ParkedTrain (used for parked trains, using parkedTrain.m_FrontLane / m_RearLane and parkedTrain.m_CurvePosition components). Sets m_Duration and m_Distance to 0.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component fields into the provided writer in the following order: m_Front, m_Rear, m_FrontCache, m_RearCache, m_Duration, m_Distance. The writer is from Colossal.Serialization; used when saving/serializing entity/component data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component fields from the provided reader in the same order as Serialize. The method checks reader.context.version and will only read m_Duration and m_Distance if the save version is >= Version.trafficFlowFixes to preserve compatibility with older saves.
Notes: - The struct implements ISerializable to allow it to be persisted in save files. The conditional read of m_Duration/m_Distance is important for modders who manipulate save compatibility or need to be aware of versioned serialization. - TrainBogieLane and TrainBogieCache are helper/struct types (not shown here) that represent lane + curve position and any cached lane lookup data; consult their definitions for details when interacting with these fields.
Usage Example
// Create from a path element (moving train)
PathElement pathElement = /* obtain path element from pathfinding/vehicle system */;
TrainCurrentLane current = new TrainCurrentLane(pathElement);
// Create from a parked train (stationary)
ParkedTrain parked = /* obtain parked train data */;
TrainCurrentLane parkedCurrent = new TrainCurrentLane(parked);
// Example: reset or inspect duration/distance
current.m_Duration = 0f;
float traveled = current.m_Distance;
// Serialization example (inside a system that has a writer/reader)
writer.Write(current.m_Front);
writer.Write(current.m_Rear);
// or call the struct's Serialize when a generic writer is available:
current.Serialize(writer);