Game.Prefabs.TransportStop
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: public class TransportStop : ComponentBase
Base: ComponentBase
Summary:
TransportStop is a prefab component used to configure and create transport stop entities for different transportation modes (bus, train, tram, ship, airplane, taxi, subway, helicopter, rocket, etc.). It exposes configuration fields (transport type, connection/track/road types, distances, boarding times, comfort/loading factors, and transport capabilities) that determine which ECS components are added to the prefab archetype and what component data is initialized at entity creation time. The class overrides the prefab/component lifecycle methods to declare required components and to write initial RouteConnectionData and TransportStopData into the created entity.
Fields
-
public TransportType m_TransportType
Specifies the transport mode for this stop (e.g., Bus, Train, Tram, Ship, Airplane, Taxi, Subway, Helicopter, Rocket, Post). Affects which archetype components are added. -
public RouteConnectionType m_AccessConnectionType = RouteConnectionType.Pedestrian
The type of connection used to access the stop (pedestrian, road, track, none, etc.). Used to populate RouteConnectionData.m_AccessConnectionType. -
public RouteConnectionType m_RouteConnectionType = RouteConnectionType.Road
The type of route connection for vehicles using the stop. Used to populate RouteConnectionData.m_RouteConnectionType. -
public TrackTypes m_AccessTrackType
Track type used for access connections (if applicable). Written to RouteConnectionData.m_AccessTrackType. -
public TrackTypes m_RouteTrackType
Track type used for the route connection (if applicable). Written to RouteConnectionData.m_RouteTrackType. -
public RoadTypes m_AccessRoadType
Road type used for access lanes (if applicable). Written to RouteConnectionData.m_AccessRoadType. -
public RoadTypes m_RouteRoadType
Road type used for route lanes (if applicable). Written to RouteConnectionData.m_RouteRoadType. -
public float m_EnterDistance
Enter/start offset distance used to populate RouteConnectionData.m_StartLaneOffset. -
public float m_ExitDistance
Exit/end margin distance used to populate RouteConnectionData.m_EndMargin. -
public float m_AccessDistance
Maximum access distance for passengers/cargo; written to TransportStopData.m_AccessDistance. -
public float m_BoardingTime
Time required to board; written to TransportStopData.m_BoardingTime. -
public float m_ComfortFactor
Comfort factor for the stop; written to TransportStopData.m_ComfortFactor. -
public float m_LoadingFactor
Loading factor (affects how quickly loading/unloading occurs); written to TransportStopData.m_LoadingFactor. -
public bool m_PassengerTransport = true
If true, this stop handles passengers. Used to set TransportStopData.m_PassengerTransport and to add WaitingPassengers component for certain transport types (e.g., Taxi). -
public bool m_CargoTransport
If true, this stop handles cargo; written to TransportStopData.m_CargoTransport.
Properties
- (no public properties declared)
Constructors
public TransportStop()
Default parameterless constructor is implicit. Initialization of default field values (e.g., m_AccessConnectionType, m_RouteConnectionType, m_PassengerTransport) occurs via field initializers in the class.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types required for this prefab at the most basic level. This implementation always adds TransportStopData and RouteConnectionData (read/write) to the prefab component set. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds additional component types to the prefab archetype depending on the configured m_TransportType and other settings. Examples: - Bus, Train, Tram, Ship, Subway: adds ConnectedRoute, BoardingVehicle and a transport-specific stop component (e.g., BusStop, TrainStop).
- Taxi: adds BoardingVehicle, RouteVehicle, TaxiStand, DispatchedRequest, optionally AccessLane/RouteLane, and WaitingPassengers when m_PassengerTransport is true.
- Airplane: adds BoardingVehicle, ConnectedRoute, AirplaneStop, and (if an OutsideConnection component exists on the prefab) Game.Net.SubLane.
-
Helicopter/Rocket: adds BoardingVehicle and ConnectedRoute. The method ensures the prefab archetype includes all runtime components required by that transport type.
-
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is instantiated as an entity. This method constructs and writes: - RouteConnectionData: fills access/route connection types, track/road types, RouteSizeClass = Undefined, m_StartLaneOffset = m_EnterDistance, m_EndMargin = m_ExitDistance.
- TransportStopData: fills m_ComfortFactor, m_LoadingFactor, m_AccessDistance, m_BoardingTime, m_TransportType, m_PassengerTransport, m_CargoTransport. Then writes both component data structs into the entity via entityManager.SetComponentData.
Usage Example
// Example: reading the data that TransportStop.Initialize writes to the entity
using Unity.Entities;
using Game.Routes; // for TransportStopData, RouteConnectionData
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity stopEntity = /* obtain entity created from TransportStop prefab */;
// Read initialized stop data
var stopData = em.GetComponentData<TransportStopData>(stopEntity);
float boardingTime = stopData.m_BoardingTime;
bool acceptsPassengers = stopData.m_PassengerTransport;
// Read route connection data
var connData = em.GetComponentData<RouteConnectionData>(stopEntity);
var accessType = connData.m_AccessConnectionType;
float enterOffset = connData.m_StartLaneOffset;
Notes: - TransportStop is a prefab-side component: in the editor you configure its public fields on the prefab GameObject; when the prefab is converted to an ECS entity the class controls which ECS component types are included and what initial component data is written. - If you add or change fields in the prefab, ensure corresponding component data is populated in Initialize or declared in GetPrefabComponents/GetArchetypeComponents as appropriate.