Skip to content

Game.Prefabs.DeliveryTruckData

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: Implements IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents data for a delivery truck prefab in the ECS (Entity Component System). Holds the truck's cargo capacity, driving cost and which Resource it transports. Implements ISerializable to support binary serialization/deserialization used by the game save/load and prefab systems. Serialization writes the transported Resource as an unsigned long followed by the two int fields (cargo capacity, cost).


Fields

  • public int m_CargoCapacity
    Holds the maximum cargo capacity of the delivery truck (in whatever unit the game uses for cargo). Serialized after the Resource value.

  • public int m_CostToDrive
    Cost to operate/drive the delivery truck (game currency/units). Serialized after m_CargoCapacity.

  • public Resource m_TransportedResources
    Enum value (from Game.Economy.Resource) indicating which resource type the truck moves. Serialized first as an unsigned long (cast).

Properties

  • (none)
    This struct exposes only public fields; there are no properties defined in the source.

Constructors

  • (default)
    No explicit constructors are declared — the default parameterless struct constructor is used. Initialize by setting fields directly, e.g. via an object initializer.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the struct to the provided writer. Writes m_TransportedResources cast to ulong first, then m_CargoCapacity, then m_CostToDrive. The writer type must implement IWriter. Important to preserve the same ordering when deserializing.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the struct from the provided reader. Reads a ulong into a temporary and later casts it to Resource, then reads m_CargoCapacity and m_CostToDrive (ints). The reader type must implement IReader. The read order matches the write order used in Serialize.

Usage Example

// Create and populate the DeliveryTruckData
var truckData = new DeliveryTruckData
{
    m_CargoCapacity = 200,
    m_CostToDrive = 15,
    m_TransportedResources = Resource.Food
};

// Example: add to an entity (using Unity.Entities API)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity();
entityManager.AddComponentData(entity, truckData);

// Example: serializing using an IWriter implementation
// (IWriter is provided by the game's serialization system)
writer.Write((ulong)truckData.m_TransportedResources);
writer.Write(truckData.m_CargoCapacity);
writer.Write(truckData.m_CostToDrive);

Notes and tips: - Resource comes from Game.Economy.Resource — treat it as an enum; ensure enum values remain stable across versions to avoid deserialization mismatches. - Maintain the same field ordering in any custom serialization/deserialization to ensure compatibility with saved data. - Because this is an ECS component (IComponentData), use the EntityManager or Systems to add/read this data on entities rather than storing it in MonoBehaviours.