Game.Prefabs.WorkVehicleData
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType (struct); implements IComponentData, IQueryTypeParameter, ISerializable
Summary:
WorkVehicleData is an ECS component data struct used to describe a "work" vehicle prefab in Cities: Skylines 2. It stores the vehicle's work type, the map feature it operates on, the resource bitmask it carries (when supported by the game version), and the maximum work amount. The struct provides custom binary serialization/deserialization to pack enum values into small integral representations and to preserve backward compatibility with older save/game protocol versions (it conditionally reads/writes the resources field depending on Version.landfillVehicles).
Fields
-
public VehicleWorkType m_WorkType
Holds the vehicle's work category (enum VehicleWorkType). Serialized as a single byte. -
public MapFeature m_MapFeature
Specifies a map feature (enum MapFeature) that the vehicle interacts with. Serialized as a signed byte (sbyte). -
public Resource m_Resources
Bitmask/enum of Resource values the vehicle carries or uses. Serialized as an unsigned long (ulong) when reading/writing on versions that support landfillVehicles (Version.landfillVehicles or newer). On older versions this field is not read from the stream and remains the default value. -
public float m_MaxWorkAmount
Maximum amount of "work" the vehicle can perform or carry (float). Serialized as a float.
Properties
- This struct exposes no properties; it uses public fields for data access.
Constructors
public WorkVehicleData()
Default compiler-provided value-type constructor. Fields are initialized to their default values (m_WorkType = 0, m_MapFeature = 0, m_Resources = 0, m_MaxWorkAmount = 0f). No explicit custom constructor is defined in the source.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes fields to the provided writer:- Writes m_WorkType as a byte.
- Writes m_MapFeature as an sbyte.
- Writes m_MaxWorkAmount as a float.
-
Writes m_Resources as an ulong. This packs enums into compact representations suitable for save files or network streams.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes fields from the provided reader: - Reads a byte and assigns it to m_WorkType (casts to VehicleWorkType).
- Reads an sbyte and assigns it to m_MapFeature (casts to MapFeature).
- Reads a float into m_MaxWorkAmount.
- If reader.context.version >= Version.landfillVehicles, reads an ulong and assigns it to m_Resources (casts to Resource). Otherwise m_Resources remains the default value. This method ensures backward compatibility by conditionally reading the resources value based on the saved/loaded version.
Usage Example
// Creating and adding a WorkVehicleData component to an entity
var workData = new Game.Prefabs.WorkVehicleData
{
m_WorkType = VehicleWorkType.GarbageCollect, // example enum value
m_MapFeature = MapFeature.Landfill, // example enum value
m_Resources = Resource.Garbage, // example enum/bitmask
m_MaxWorkAmount = 100f
};
entityManager.AddComponentData(vehicleEntity, workData);
// Example: using the serializer (pseudo-objects for illustration)
writer.Write((byte)workData.m_WorkType);
writer.Write((sbyte)workData.m_MapFeature);
writer.Write(workData.m_MaxWorkAmount);
writer.Write((ulong)workData.m_Resources);
// Deserialization will respect reader.context.version to determine whether
// resources is present in the stream (Version.landfillVehicles or newer).