Game.Vehicles.Taxi
Assembly: Assembly-CSharp
Namespace: Game.Vehicles
Type: public struct Taxi : IComponentData, IQueryTypeParameter, ISerializable
Base: System.ValueType (struct) — implements IComponentData, IQueryTypeParameter, ISerializable
Summary:
Taxi is an ECS component that holds runtime state for taxi vehicles. It stores target service request entity, taxi state flags, timing and distance information used by the taxi AI, extra path element bookkeeping, and current/next starting fee values. The struct implements custom binary serialization/deserialization (ISerializable) with conditional reads based on saved game version constants (e.g., reverseServiceRequests, taxiFee, roadPatchImprovements). It is intended to be attached to taxi vehicle entities and used in queries and systems that operate on taxis.
Fields
-
public Unity.Entities.Entity m_TargetRequest
Entity reference to the service/ride request the taxi is targeting. Present in saved data only when the save version supports reverse service requests. -
public TaxiFlags m_State
Bit flags representing the taxi's current state (enum TaxiFlags — not included here). Serialized as a uint. -
public float m_PathElementTime
Timing information for the taxi's current path element. Used to track progress along a path and serialized in all versions. -
public float m_StartDistance
Distance value used for fee or boarding logic. Read/written only when the save/version supports taxi fees. -
public float m_MaxBoardingDistance
Maximum distance allowed for boarding (introduced in roadPatchImprovements version). Read/written only when the save/version supports it. -
public float m_MinWaitingDistance
Minimum waiting distance parameter (introduced in roadPatchImprovements version). Read/written only when the save/version supports it. -
public int m_ExtraPathElementCount
Extra path element counter used for path bookkeeping; serialized in all versions. -
public ushort m_NextStartingFee
Next starting fee amount (introduced with taxiFee). Read/written only when the save/version supports taxi fees. -
public ushort m_CurrentFee
Current fee the taxi charges (introduced with taxiFee). Read/written only when the save/version supports taxi fees.
Properties
- None. This struct exposes only public fields and has no properties.
Constructors
public Taxi(TaxiFlags flags)
Initializes a new Taxi instance with the provided flags. Sets m_TargetRequest to Entity.Null and numeric fields to zero/defaults. Use this constructor when creating a taxi component to attach to an entity or to initialize default state.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the Taxi fields to a writer in a specific order. Always writes:- m_TargetRequest (Entity)
- m_State as a uint
- m_PathElementTime
-
m_ExtraPathElementCount Then writes fee- and distance-related fields (startDistance, nextStartingFee, currentFee, maxBoardingDistance, minWaitingDistance) in that order. The code as written writes all fields unconditionally, but Deserialize contains version checks to support older saves.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads Taxi data from a reader. Uses reader.context.version to conditionally read fields depending on save version: - If version >= Version.reverseServiceRequests: reads m_TargetRequest.
- Always reads uint (m_State), m_PathElementTime, and m_ExtraPathElementCount.
- Converts the read uint to TaxiFlags and assigns to m_State.
- If version >= Version.taxiFee: reads m_StartDistance, m_NextStartingFee, m_CurrentFee.
- If version >= Version.roadPatchImprovements: reads m_MaxBoardingDistance and m_MinWaitingDistance. This method ensures backward compatibility with older save formats by only attempting to read fields present in a particular version.
Notes: - The struct relies on external symbols not included here: TaxiFlags enum and Version static constants (reverseServiceRequests, taxiFee, roadPatchImprovements), and the IWriter/IReader/context types. - Because it implements IComponentData, Taxi is intended to be stored on Unity Entities (ECS). Because it also implements IQueryTypeParameter, it can be used directly in certain ECS queries.
Usage Example
// Create a Taxi component with default flags and set some fields before attaching to an entity.
var taxiComp = new Game.Vehicles.Taxi(TaxiFlags.None);
taxiComp.m_CurrentFee = 100;
taxiComp.m_NextStartingFee = 150;
taxiComp.m_PathElementTime = 0f;
taxiComp.m_ExtraPathElementCount = 0;
// Example: add to an entity using an EntityManager (Unity.Entities)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity taxiEntity = em.CreateEntity();
em.AddComponentData(taxiEntity, taxiComp);
// Serialization is handled by the game's save system calling Serialize/Deserialize via the provided IWriter/IReader.