Skip to content

Game.Prefabs.TransportLinePrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: RoutePrefab

Summary:
TransportLinePrefab is a prefab definition used by the game to configure transport lines (e.g., bus, tram, train lines). It exposes configuration for access/route connection types, track/road types, vehicle timings and behaviour (default interval, unbunching factor, stop duration), transportable goods (passengers/cargo), and references to related prefabs such as pathfinding and vehicle notification. During entity initialization this prefab writes RouteConnectionData and TransportLineData to the entity and controls what ECS components and archetype components are added for route, waypoint and segment archetypes.


Fields

  • public RouteConnectionType m_AccessConnectionType
    Type: RouteConnectionType — Connection type used by the access lanes (e.g., pedestrian access). Default: RouteConnectionType.Pedestrian. Controls what kind of access connections are used for stops/waypoints.

  • public RouteConnectionType m_RouteConnectionType
    Type: RouteConnectionType — Connection type used by the route itself (e.g., Road, Track). Default: RouteConnectionType.Road. Defines how the route connects to the transportation network.

  • public TrackTypes m_AccessTrackType
    Type: TrackTypes — Track type used for access (when access uses tracks). Controls access lane track classification.

  • public TrackTypes m_RouteTrackType
    Type: TrackTypes — Track type used for the route itself (when route uses tracks). Controls route track classification.

  • public RoadTypes m_AccessRoadType
    Type: RoadTypes — Road type used for access lanes (if access uses roads).

  • public RoadTypes m_RouteRoadType
    Type: RoadTypes — Road type used by the route (if route uses roads).

  • public TransportType m_TransportType
    Type: TransportType — Enum describing the transport vehicle/category (e.g., Bus, Tram, Train). Used by route/vehicle systems to pick vehicle behaviour and visuals.

  • public float m_DefaultVehicleInterval
    Type: float — Default spawn/dispatch interval for vehicles on the line (seconds). Default value in code: 15f.

  • public float m_DefaultUnbunchingFactor
    Type: float — Default unbunching factor used to avoid vehicle bunching. Default: 0.75f.

  • public float m_StopDuration
    Type: float — Default dwell time at stops (seconds). Default: 1f.

  • public SizeClass m_SizeClass
    Type: SizeClass — Size classification for vehicles on the line (e.g., Small, Medium, Large). Default: SizeClass.Large.

  • public bool m_PassengerTransport
    Type: bool — Whether this transport line carries passengers. Default: true. When true, waiting passenger components are added to stops/waypoints.

  • public bool m_CargoTransport
    Type: bool — Whether this transport line carries cargo.

  • public PathfindPrefab m_PathfindPrefab
    Type: PathfindPrefab — Reference to the pathfinding prefab used by vehicles on this line. This is resolved to an entity in LateInitialize.

  • public NotificationIconPrefab m_VehicleNotification
    Type: NotificationIconPrefab — Reference to a notification icon prefab for vehicles; resolved to an entity in LateInitialize.

Properties

  • This class does not declare additional public properties beyond those fields; configuration is done via public fields and the prefab lifecycle methods.

Constructors

  • public TransportLinePrefab()
    Default constructor. Typical prefab instance is configured in the Unity inspector; no special runtime-only construction logic is implemented beyond the base RoutePrefab constructor.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Collects other prefabs that this prefab depends on. Implementation: calls base and then adds m_PathfindPrefab and m_VehicleNotification to the dependency list. This ensures those prefabs are available/resolved before this prefab is initialized.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds runtime component types that this prefab requires on any archetype derived from it. Implementation: calls base then adds RouteConnectionData, TransportLineData and PlaceableInfoviewItem to the component set. These components are required for the prefab entity regardless of whether it becomes a Route, Waypoint or Segment archetype.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds specific components depending on the archetype the prefab will produce (Route, Waypoint, or Segment):

  • If the archetype contains Route: adds TransportLine, VehicleModel, DispatchedRequest, RouteNumber, RouteVehicle, RouteModifier and Policy.
  • Else if it contains Waypoint: conditionally adds AccessLane (if m_AccessConnectionType != None) and RouteLane (if m_RouteConnectionType != None); also adds VehicleTiming if Connected component is present; adds WaitingPassengers if m_PassengerTransport is true.
  • Else if it contains Game.Routes.Segment: adds PathTargets, RouteInfo, PathElement, PathInformation.

This method ensures entities of appropriate archetypes get the correct set of components for route simulation, vehicles and passenger behavior.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Finalizes prefab initialization by writing RouteConnectionData and TransportLineData component data to the prefab entity. Behavior:
  • Resolves referenced prefabs via PrefabSystem (entityManager.World.GetExistingSystemManaged()).
  • Sets RouteConnectionData with the configured access/route connection types, track/road types, size class and default offsets.
  • Sets TransportLineData with a resolved m_PathfindPrefab entity, m_TransportType, default vehicle interval and unbunching factor, stop duration, size class, passenger/cargo booleans and a resolved vehicle notification entity.

This populates the ECS components used by runtime systems to spawn vehicles, route passengers and run pathfinding.

Usage Example

// Example: customizing a TransportLinePrefab in a derived prefab class
[ComponentMenu("Routes/Custom", new Type[] { })]
public class CustomBusLinePrefab : TransportLinePrefab
{
    public override void GetDependencies(List<PrefabBase> prefabs)
    {
        base.GetDependencies(prefabs);
        // add additional dependent prefabs here if needed
    }

    // You can configure fields in the inspector or at construction time:
    public CustomBusLinePrefab()
    {
        m_TransportType = TransportType.Bus;
        m_DefaultVehicleInterval = 12f;
        m_StopDuration = 2f;
        m_PassengerTransport = true;
    }

    // No need to override LateInitialize unless you need custom initialization logic.
}

Notes: - Many fields are intended to be configured in the Unity inspector for the prefab asset. - LateInitialize resolves referenced prefabs to entities and writes the core RouteConnectionData and TransportLineData that runtime systems depend on. If you add custom referenced prefabs, ensure they are returned in GetDependencies so resolution succeeds.