Game.Prefabs.CargoTransportVehicleData
Assembly: Game
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents configuration data for cargo transport vehicles used by the game's prefab/ECS systems. Stores which Resource the vehicle handles, its cargo capacity, the maximum resource count it can carry, and a maintenance range. The struct is a value type intended for use as an ECS component (IComponentData) and supports custom binary serialization via Colossal.Serialization.Entities.ISerializable.
Fields
-
public Resource m_Resources
Holds the Resource enum value indicating which resource type this vehicle transports. When serialized, the resource is written as an unsigned long (ulong). -
public int m_CargoCapacity
Maximum cargo capacity (integer) for the vehicle. Serialized immediately after m_Resources. -
public int m_MaxResourceCount
Maximum resource count related to the vehicle (e.g., stack/slot or upper bound for resource units). Serialized after m_CargoCapacity. -
public float m_MaintenanceRange
Float value representing the maintenance range (distance/radius) relevant to the vehicle. Serialized last.
Properties
- This type exposes no managed properties; it exposes public fields and implements interfaces for ECS usage and serialization.
Constructors
public CargoTransportVehicleData(Resource resources, int cargoCapacity, int maxResourceCount, float maintenanceRange)
Initializes a new instance with the specified resource type, cargo capacity, maximum resource count, and maintenance range.
Parameters: - resources: Resource enum value the vehicle handles. - cargoCapacity: Cargo capacity as an int. - maxResourceCount: Maximum resource count as an int. - maintenanceRange: Maintenance range as a float.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct data to a writer in a fixed order: m_Resources (as ulong), m_CargoCapacity, m_MaxResourceCount, m_MaintenanceRange. Use this to persist the component to the game's binary formats. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data from a reader in the same order used by Serialize. It reads an unsigned long for the resource, then reads the ints and float by reference into their respective fields, and finally casts the ulong back to Resource and stores it in m_Resources. Keep read/write order consistent to avoid corrupt data.
Usage Example
// Create an instance
var data = new CargoTransportVehicleData(Resource.Wood, cargoCapacity: 100, maxResourceCount: 10, maintenanceRange: 50f);
// Serialize (writer must implement IWriter)
data.Serialize(writer);
// Deserialize into a new instance (reader must implement IReader)
CargoTransportVehicleData loaded = default;
loaded.Deserialize(reader);
// Use as an ECS component:
// entityManager.AddComponentData(entity, data);