Game.Vehicles.Ambulance
Assembly: Assembly-CSharp (game runtime assembly)
Namespace: Game.Vehicles
Type: struct Ambulance : IComponentData, IQueryTypeParameter, ISerializable
Base: System.ValueType, IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents an ambulance component used by the game's ECS (Unity Entities) for tracking an ambulance vehicle's runtime state. Stores the ambulance's state flags, references to a target patient, a target location, an associated service request (when present), and timing information for the current path element. Implements custom save/load serialization with version-aware deserialization to remain compatible with older save versions.
Fields
-
public AmbulanceFlags m_State
Stores the current state of the ambulance as an AmbulanceFlags enum (e.g., idle, en-route, transporting). Serialized as a uint. -
public Entity m_TargetPatient
Entity reference for the patient the ambulance is (or will be) handling. May be Entity.Null. -
public Entity m_TargetLocation
Entity reference for the target location/destination for the ambulance (e.g., hospital entrance or pickup/dropoff). This field is conditionally read during deserialization depending on save version compatibility. -
public Entity m_TargetRequest
Entity reference for an associated service request. This field is only present and read in newer save versions (controlled by Version.reverseServiceRequests2). May be Entity.Null. -
public float m_PathElementTime
Floating-point time counter tracking progress/time spent on the current path element (used by path-following logic).
Properties
- This type does not define any C# properties. It exposes public fields only.
Constructors
public Ambulance(Entity targetPatient, Entity targetLocation, AmbulanceFlags state)
Creates a new Ambulance value with the given patient, target location, and state. Initializes:- m_TargetRequest = Entity.Null
- m_PathElementTime = 0f
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state to the provided writer in the following order:- m_State (written as uint)
- m_TargetPatient (Entity)
- m_TargetLocation (Entity)
- m_TargetRequest (Entity)
- m_PathElementTime (float)
This order must match the expectations of the corresponding Deserialize implementation for proper save/load.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component state from the provided reader. Deserialization is version-aware:- Reads an unsigned int into a local value (the state) but does not immediately assign it to m_State.
- Always reads m_TargetPatient.
- Reads m_TargetLocation only if reader.context.version >= Version.healthcareImprovement2.
- Reads m_TargetRequest only if reader.context.version >= Version.reverseServiceRequests2.
- Always reads m_PathElementTime.
- Assigns m_State by casting the earlier-read value to AmbulanceFlags.
The conditional reads ensure backward compatibility with older save versions that did not include some fields.
Usage Example
// Constructing an Ambulance component
var ambulance = new Ambulance(targetPatientEntity, targetLocationEntity, AmbulanceFlags.EnRoute);
// Example (pseudo) serialization usage with a writer that implements IWriter:
ambulance.Serialize(someWriter);
// Example (pseudo) deserialization usage with a reader that implements IReader:
// Ambulance a = default;
// a.Deserialize(someReader);
Notes: - Because this struct implements IComponentData it is intended to be attached to entities in the Unity Entities (DOTS) world. - The Deserialize method relies on reader.context.version and Version.* constants to handle compatibility when fields were added in game updates; take care to preserve the read order and conditional logic when changing the serialization format.