Skip to content

Game.Routes.TransportLine

Assembly:
Namespace: Game.Routes

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
TransportLine is an ECS component representing a public-transport line's runtime data (vehicle request entity, scheduling parameters, flags and ticket price). It provides custom serialization/deserialization logic that is aware of saved-game version differences so older saves remain compatible. The struct is used by routing/line management systems to control vehicle spawn requests, spacing (unbunching) behavior and pricing.


Fields

  • public Unity.Entities.Entity m_VehicleRequest
    Reference to an Entity representing the queued/active vehicle request for this line (or Entity.Null if none). Serialized/deserialized as an Entity.

  • public System.Single m_VehicleInterval
    Float representing the desired interval between vehicles on the line (seconds). The constructor initializes this from TransportLineData.m_DefaultVehicleInterval. The deserialization handles older save versions that may not contain this value.

  • public System.Single m_UnbunchingFactor
    Float factor used to reduce vehicle bunching (spacing control). Initialized from TransportLineData.m_DefaultUnbunchingFactor.

  • public TransportLineFlags m_Flags
    Bitflags storing line-specific options. Serialized as a ushort when the save version supports transportLineFlags.

  • public System.UInt16 m_TicketPrice
    Ticket price for the line (ushort). Present in saves from the transportLinePolicies version onwards.

Properties

  • None (no C# properties are defined; all data members are public fields).

Constructors

  • public TransportLine(TransportLineData transportLineData)
    Initializes a new TransportLine using default parameters from a TransportLineData template:
  • m_VehicleRequest set to Entity.Null
  • m_VehicleInterval set to transportLineData.m_DefaultVehicleInterval
  • m_UnbunchingFactor set to transportLineData.m_DefaultUnbunchingFactor
  • m_Flags set to 0
  • m_TicketPrice set to 0

This constructor is intended for creating a fresh component instance with sensible defaults.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component fields to the provided writer in the following order:
  • m_VehicleRequest (Entity)
  • m_VehicleInterval (float)
  • m_UnbunchingFactor (float)
  • m_Flags written as ushort
  • m_TicketPrice (ushort)

This method ensures the component state is persisted. Writers must implement IWriter.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component data from reader. The method handles multiple save-version cases:
  • Reads m_VehicleRequest as Entity.
  • For saves older than Version.routeVehicleInterval it consumes an extra float (legacy format).
  • Reads m_VehicleInterval and m_UnbunchingFactor.
  • If reader.context.version >= Version.transportLineFlags, reads a ushort and assigns it to m_Flags.
  • If reader.context.version >= Version.transportLinePolicies, reads m_TicketPrice.

This method ensures forward/backward compatibility when loading saves that may lack newer fields.

Usage Example

// Create a TransportLine component from template data (e.g. when creating a new line)
TransportLineData template = /* obtain template */;
TransportLine line = new TransportLine(template);

// Example of serializing the component (writer provided by engine save system)
writer.Write(line.m_VehicleRequest);
writer.Write(line.m_VehicleInterval);
writer.Write(line.m_UnbunchingFactor);
writer.Write((ushort)line.m_Flags);
writer.Write(line.m_TicketPrice);

// Deserialization is typically handled by the engine's ECS serialization system,
// which will call Deserialize<TReader> and provide a reader with a context.version.