Game.Vehicles.PostVan
Assembly:
Assembly-CSharp
Namespace:
Game.Vehicles
Type:
struct PostVan
Base:
IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents the runtime state of a postal delivery vehicle (post van) in the game's ECS. The struct stores the current target request (as an Entity reference), state flags describing the van's current behavior, counts of requests and mail being carried/collected, timing for path traversal, and estimated times for delivery/collection. It implements ISerializable to control save/load behavior and includes version-aware deserialization to maintain compatibility between game versions.
Fields
-
public Entity m_TargetRequest
Reference to the Entity representing the current service/request target for this van. May be Entity.Null if there is no target. Written and read by serialization (present only when save version >= reverseServiceRequests2). -
public PostVanFlags m_State
Flags describing the van's current state (idle, en route, delivering, etc.). Stored as an integer during serialization. -
public int m_RequestCount
Number of outstanding requests assigned to or tracked by this van. -
public float m_PathElementTime
Runtime time value used when traversing path elements (float). Typically used by path-following logic to track progress along the route. -
public int m_DeliveringMail
Count of mail items currently being delivered by this van. -
public int m_CollectedMail
Count of mail items collected (picked up to be transported) by this van. -
public int m_DeliveryEstimate
Estimated time/steps remaining to complete current deliveries. Only serialized/deserialized when save version >= policeShiftEstimate. -
public int m_CollectEstimate
Estimated time/steps remaining to complete current collections. Only serialized/deserialized when save version >= policeShiftEstimate.
Properties
- (none)
Constructors
public PostVan(PostVanFlags flags, int requestCount, int deliveringMail)
Initializes a new PostVan instance:- m_TargetRequest is set to Entity.Null.
- m_State is set to the provided flags value.
- m_RequestCount is set to requestCount.
- m_PathElementTime is set to 0f.
- m_DeliveringMail is set to deliveringMail.
- m_CollectedMail, m_DeliveryEstimate, and m_CollectEstimate are initialized to 0. This constructor is useful for creating a fresh component for a new or reset vehicle.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct fields to the provided writer in a fixed order:- m_TargetRequest (Entity)
- m_State (written as uint)
- m_RequestCount (int)
- m_PathElementTime (float)
- m_DeliveringMail (int)
- m_CollectedMail (int)
- m_DeliveryEstimate (int)
- m_CollectEstimate (int)
The explicit casting of m_State to uint preserves enum value across serialization.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads values back in a version-aware manner. Key behaviors:- If reader.context.version >= Version.reverseServiceRequests2, the code reads m_TargetRequest (Entity). Older saves do not contain this field.
- Always reads the uint backing value for m_State (read first after the optional target).
- Reads m_RequestCount and m_PathElementTime.
- If reader.context.version < Version.taxiDispatchCenter, an extra int is read and ignored (this preserves compatibility with an older data layout where an additional integer was present).
- Reads m_DeliveringMail and m_CollectedMail.
- m_State is reconstructed from the read uint.
- If reader.context.version >= Version.policeShiftEstimate, m_DeliveryEstimate and m_CollectEstimate are read (older saves do not include these values).
These conditional reads ensure backward and forward compatibility across multiple save format versions.
Usage Example
// Create and add a PostVan component to an entity (EntityManager usage)
var postVan = new PostVan(PostVanFlags.None, requestCount: 0, deliveringMail: 0);
// entity is assumed to be a previously created Entity representing a vehicle
entityManager.AddComponentData(entity, postVan);
// Example: update some fields at runtime
var existing = entityManager.GetComponentData<PostVan>(entity);
existing.m_TargetRequest = someRequestEntity;
existing.m_State = PostVanFlags.EnRoute;
existing.m_PathElementTime = 0f;
entityManager.SetComponentData(entity, existing);
Notes: - Because PostVan implements ISerializable, the Serialize/Deserialize methods are used by the save/load system. The Deserialize method must handle older save formats — pay attention to the Version checks (reverseServiceRequests2, taxiDispatchCenter, policeShiftEstimate) when changing the data layout. - The struct is designed to be stored as an ECS component (IComponentData). Access and modification should follow the usual EntityManager/Systems patterns to remain thread-safe and consistent with Unity's ECS.