Game.Prefabs.GarbageTruckData
Assembly:
Namespace: Game.Prefabs
Type: struct (public)
Base: System.ValueType
Summary:
Represents configuration and runtime data for a garbage truck in the ECS world. Stores capacity and unload rate and implements IComponentData for use as an ECS component, IQueryTypeParameter to be used in queries, and ISerializable for custom binary (de)serialization used by the game's save/load and networking systems. Fields are simple integer values and are serialized in a fixed order (capacity then unload rate).
Fields
-
public int m_GarbageCapacity
Stores the maximum amount of garbage the truck can carry. Serialized as the first integer in Serialize. Typically a non-negative integer representing units of garbage. -
public int m_UnloadRate
Stores how quickly the truck unloads garbage (units per tick or per second depending on game logic). Serialized as the second integer in Serialize. Typically a non-negative integer.
Properties
- This type has no public properties. All data is stored in public fields and accessed directly.
Constructors
public GarbageTruckData(int garbageCapacity, int unloadRate)
Initializes a new GarbageTruckData instance with the given capacity and unload rate.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state to the provided writer. The method writes two integers in this order:- m_GarbageCapacity
-
m_UnloadRate This deterministic ordering must be preserved to maintain compatibility with Deserialize.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component state from the provided reader and stores values into the fields. It reads two integers in the same order they were written: - m_GarbageCapacity
- m_UnloadRate Note: Deserialize uses ref locals to assign directly into the struct's fields.
Usage Example
// Constructing the component
var truckData = new GarbageTruckData(garbageCapacity: 1000, unloadRate: 50);
// Serializing (pseudo-code; IWriter implementation depends on the engine)
using (var writer = new SomeBinaryWriterStream())
{
truckData.Serialize(writer);
// writer now contains two ints in order: capacity, unloadRate
}
// Deserializing (pseudo-code; IReader implementation depends on the engine)
var loadedTruck = new GarbageTruckData();
using (var reader = new SomeBinaryReaderStream(existingStream))
{
loadedTruck.Deserialize(reader);
// loadedTruck.m_GarbageCapacity and loadedTruck.m_UnloadRate are populated
}
Additional notes: - Because serialization is positional, adding/removing fields requires careful versioning to avoid breaking saves or network compatibility. - As an IComponentData, instances are intended to be stored in ECS component arrays (native containers) rather than referenced directly on managed game objects.