Skip to content

Game.Prefabs.PublicTransport

Assembly:
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Represents a public-transport vehicle prefab definition used by the game's ECS/prefab system. Exposes configurable fields for transport type, passenger capacity, purposes (flags), and maintenance range. Controls which components are added to the prefab archetype and sets initial component data on entity initialization. The class is decorated with modding attributes to control menu placement and mod-tag generation.


Fields

  • public TransportType m_TransportType
    The type of public transport (e.g., Bus, Tram, Metro). Determines type-specific behavior and is used in generated mod tags.

  • public int m_PassengerCapacity = 30
    Default passenger capacity for this vehicle. Used to populate the runtime PublicTransportVehicleData component.

  • public PublicTransportPurpose m_Purposes = PublicTransportPurpose.TransportLine
    Flag enum describing the purposes of this prefab (for example, whether it participates in transport lines). Used for mod tag generation and for configuring behavior related to transport lines.

  • public float m_MaintenanceRange
    Maintenance range in game units as configured on the prefab. Note: during initialization this value is multiplied by 1000f when written into PublicTransportVehicleData.

Properties

  • public override IEnumerable<string> modTags { get; }
    Overrides ComponentBase.modTags to yield base mod tags and additional tags when the TransportLine purpose is set. When the TransportLine flag is present this exposes:
  • "PublicTransport"
  • "PublicTransport{m_TransportType}" (e.g., "PublicTransportBus") These tags are used by the mod system to categorize and filter prefabs.

Constructors

  • public PublicTransport()
    No explicit constructor is defined in the source; the class uses the default parameterless constructor provided by C#. Initialization logic is performed in the overridden Initialize method.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components) : System.Void
    Adds component types that should be present on a prefab instance:
  • PublicTransportVehicleData (ReadWrite)
  • UpdateFrameData (ReadWrite)

  • public override void GetArchetypeComponents(HashSet<ComponentType> components) : System.Void
    Adds components that should be included in the prefab's archetype:

  • Game.Vehicles.PublicTransport (ReadWrite)
  • Passenger (ReadWrite)
  • Odometer (ReadWrite) Additionally, if the archetype includes Moving and either does not include Controller or does include LayoutElement, it adds:
  • PathInformation (ReadWrite)
  • ServiceDispatch (ReadWrite) This conditional logic controls which pathfinding / service dispatch components are attached depending on other capabilities of the prefab.

  • public override void Initialize(EntityManager entityManager, Entity entity) : System.Void
    Called when the prefab entity is initialized. Behavior:

  • Calls base.Initialize.
  • Writes a PublicTransportVehicleData component to the entity using m_TransportType, m_PassengerCapacity, m_Purposes, and m_MaintenanceRange * 1000f.
  • If the entity has a CarData component, sets UpdateFrameData(1) on the entity (to configure the update frame scheduling for vehicles derived from car data).

Usage Example

[ExcludeGeneratedModTag]
[ComponentMenu("Vehicles/", new Type[] { typeof(VehiclePrefab) })]
public class PublicTransport : ComponentBase
{
    // fields omitted for brevity

    public override void Initialize(EntityManager entityManager, Entity entity)
    {
        base.Initialize(entityManager, entity);
        // Write transport-specific runtime data
        entityManager.SetComponentData(entity, new PublicTransportVehicleData(
            m_TransportType,
            m_PassengerCapacity,
            m_Purposes,
            m_MaintenanceRange * 1000f
        ));

        // Ensure vehicles derived from car data get the expected update frame
        if (entityManager.HasComponent<CarData>(entity))
        {
            entityManager.SetComponentData(entity, new UpdateFrameData(1));
        }
    }
}