Game.Prefabs.Taxi
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Taxi is a prefab component that configures entity components and archetype requirements for taxi vehicles. It exposes a passenger capacity and a maintenance range (editable on the prefab) and, during initialization, writes TaxiData and UpdateFrameData component values to the entity. The class also declares which ECS ComponentTypes should be present on the prefab and on created archetypes (including a conditional ServiceDispatch component when Moving is present).
Fields
-
public int m_PassengerCapacity = 4
This public field sets the number of passengers the taxi can carry. Default value is 4. The value is stored into the TaxiData component during Initialize and therefore determines runtime capacity for the entity. -
public float m_MaintenanceRange = 600f
A public field that represents the maintenance range exposed on the prefab. In Initialize this value is multiplied by 1000f before being written into TaxiData (i.e., the stored value is m_MaintenanceRange * 1000f). This multiplication implies a unit scaling/conversion at setup (ensure you account for that when setting the prefab value).
Properties
- None.
This class does not expose C# properties.
Constructors
public Taxi()
Default parameterless constructor (implicit). The prefab fields are intended to be configured via the inspector or by modifying the instance before initialization in code.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Registers which ComponentTypes are required by the prefab itself. This implementation adds:- TaxiData (read/write)
-
UpdateFrameData (read/write)
These indicate that any entity created from this prefab should have TaxiData and UpdateFrameData components. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Registers which ComponentTypes should be present on the runtime archetype for this vehicle type. This implementation adds: - Game.Vehicles.Taxi (read/write)
- Passenger (read/write)
-
Odometer (read/write) Additionally, if the archetype already contains Moving (read/write), this method also adds ServiceDispatch (read/write). The conditional ensures ServiceDispatch is only added for archetypes that include movement.
-
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is initialized into an entity. Behavior: - Calls base.Initialize(entityManager, entity)
- Writes TaxiData to the entity using the prefab fields: new TaxiData(m_PassengerCapacity, m_MaintenanceRange * 1000f)
- Writes UpdateFrameData with a hardcoded value of 6 (new UpdateFrameData(6)), which implies the taxi entity will be scheduled/updated every 6 frames according to the game's update frame mechanism. Notes:
- The method uses EntityManager.SetComponentData to set component values on the created entity.
- Be aware of the scaling applied to m_MaintenanceRange when reading or setting that value in other systems.
Usage Example
// Example: reading TaxiData and UpdateFrameData from an entity created from the Taxi prefab
public void InspectTaxi(EntityManager em, Entity taxiEntity)
{
if (em.HasComponent<TaxiData>(taxiEntity))
{
TaxiData data = em.GetComponentData<TaxiData>(taxiEntity);
UnityEngine.Debug.Log($"Taxi passenger capacity: {data.passengerCapacity}, maintenanceRangeStored: {data.maintenanceRange}");
// Note: maintenanceRangeStored was set to m_MaintenanceRange * 1000f during Initialize.
}
if (em.HasComponent<UpdateFrameData>(taxiEntity))
{
UpdateFrameData uf = em.GetComponentData<UpdateFrameData>(taxiEntity);
UnityEngine.Debug.Log($"Taxi update interval (frames): {uf.updateInterval}");
}
}
Additional notes and modding tips: - The attribute [ComponentMenu("Vehicles/", new Type[] { typeof(CarPrefab) })] is used for editor/menu grouping and to link the prefab type in the component menu; it does not affect runtime behavior directly. - If you change m_MaintenanceRange in the prefab, remember Initialize multiplies by 1000f before storing; adjust other systems accordingly. - The conditional addition of ServiceDispatch in GetArchetypeComponents means that if you create a custom archetype for taxis that includes Moving, you will automatically get ServiceDispatch included. If you need ServiceDispatch under other circumstances, explicitly add it to your archetype or modify GetArchetypeComponents. - UpdateFrameData(6) implies an update cadence — change the literal if you need different scheduling for taxi simulation.