Skip to content

Game.Vehicles.DeliveryTruck

Assembly: Assembly-CSharp
Namespace: Game.Vehicles

Type: public struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the delivery-truck component data used by the game's ECS. Stores the truck's current state, the resource type it carries, and the amount. Implements custom binary serialization/deserialization (Colossal Serialization) for saving/networking of the component state. This struct is intended to be attached to vehicle entities handled by the game's systems and used by delivery/supply logic.


Fields

  • public DeliveryTruckFlags m_State
    Holds the truck's state flags (e.g., idle, en route, unloading). Uses the DeliveryTruckFlags enum (not included here). Serialized as a uint in the Serialize method.

  • public Resource m_Resource
    The resource type carried by the truck. The Resource value is converted to and from an sbyte index via EconomyUtils.GetResourceIndex / EconomyUtils.GetResource when serializing/deserializing.

  • public int m_Amount
    The numeric amount of resource currently loaded (or remaining) on the truck. Serialized as an int.

Properties

  • None declared.
    This struct exposes its data as public fields and does not define C# properties.

Constructors

  • No explicit constructors declared.
    As a struct, it has the default value-type constructor (all fields defaulted). Initialize fields inline or via object initializer when creating instances.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the component to a writer in the following order:
  • Writes m_State as a uint (casts DeliveryTruckFlags to uint).
  • Writes the resource index as an sbyte using EconomyUtils.GetResourceIndex(m_Resource).
  • Writes m_Amount as an int. Notes:
  • The resource is stored as an sbyte index — this constrains resource count to the sbyte range when serialized.
  • The order and primitive types are important for compatibility with the corresponding Deserialize implementation.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the component from a reader in the same order used for serialization:

  • Reads a uint and assigns it to m_State (cast to DeliveryTruckFlags).
  • Reads an sbyte and resolves it to a Resource via EconomyUtils.GetResource(...).
  • Reads an int and assigns it to m_Amount. Notes:
  • Uses EconomyUtils.GetResource to map the stored resource index back to the Resource enum/struct.
  • Ensure the reader contains data written in the same format/order to avoid corruption.

Usage Example

// Example: creating and serializing a delivery truck component
var truck = new DeliveryTruck
{
    m_State = DeliveryTruckFlags.Idle,
    m_Resource = Resource.Wood, // example resource
    m_Amount = 50
};

// writer must implement IWriter (provided by the game's serialization framework)
truck.Serialize(writer);

// Later, or on load, reconstruct from a reader (IReader)
var loadedTruck = new DeliveryTruck();
loadedTruck.Deserialize(reader);

Additional notes: - This struct implements IComponentData and is therefore usable in Unity ECS entity components (blittable value type expected). - Serialization methods conform to the Colossal.Serialization.Entities pattern used across the game's data types; follow the same ordering and types when updating serialization to maintain save/load compatibility. - Related types to check: DeliveryTruckFlags, Resource, EconomyUtils, IWriter, IReader.