Game.Vehicles.TrainNavigation
Assembly: Assembly-CSharp
Namespace: Game.Vehicles
Type: public struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents navigation data for a train in the ECS (DOTS) world. Stores the front and rear bogie positions and the current speed. Implements ISerializable so the struct can be written to / read from the game's serialization streams (save/load), and implements IComponentData / IQueryTypeParameter so it can be used as a component in entity queries and systems.
Fields
-
public TrainBogiePosition m_Front
Represents the front bogie position for the train. TrainBogiePosition is a value type that encodes position/orientation/state for a bogie (wheelset) used by the train navigation system. -
public TrainBogiePosition m_Rear
Represents the rear bogie position for the train. -
public float m_Speed
Current speed of the train; stored as a floating-point value in game units per second. Interpreted by the train movement systems to advance train position each update.
Properties
- This type has no properties. All data is exposed via public fields and serialization methods.
Constructors
public TrainNavigation()
No explicit constructor is declared. As a struct, TrainNavigation has the default parameterless constructor which initializes m_Front and m_Rear to their default TrainBogiePosition values and m_Speed to 0.0f. You can instantiate it with an object initializer to set fields.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the TrainNavigation instance into a writer. The implementation writes m_Front, m_Rear, and m_Speed in that order. The generic TWriter must implement the IWriter interface used by the game's Colossal.Serialization system. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes data from a reader into this TrainNavigation instance. Uses ref locals to read m_Front, m_Rear and m_Speed via reader.Read(out ...). The generic TReader must implement the IReader interface.
Remarks on serialization: - Order of writes and reads must match (front, rear, speed). - The methods rely on TrainBogiePosition being serializable by the same writer/reader infrastructure. - These methods are typically invoked by the game's serialization framework during save/load operations.
Usage Example
// Create and set up a TrainNavigation component (ECS style)
var nav = new TrainNavigation {
m_Front = new TrainBogiePosition { /* set fields */ },
m_Rear = new TrainBogiePosition { /* set fields */ },
m_Speed = 10.5f
};
// Add to an entity (using Unity.Entities EntityManager)
entityManager.AddComponentData(trainEntity, nav);
// Serialization example (pseudocode, depending on available writer implementation)
using (var writer = someSerializationStream.GetWriter())
{
nav.Serialize(writer);
}
// Deserialization example (pseudocode)
var readNav = new TrainNavigation();
using (var reader = someSerializationStream.GetReader())
{
readNav.Deserialize(reader);
}
Notes: - As an IComponentData type, TrainNavigation is intended for use with Unity's DOTS workflows (systems/jobs). Use EntityManager or component queries to read and write this component in game systems. - Ensure TrainBogiePosition serialization compatibility when saving/loading.