Game.Vehicles.ReturnLoad
Assembly:
Assembly-CSharp (game runtime assembly; exact assembly may vary by build)
Namespace:
Game.Vehicles
Type:
struct ReturnLoad : IComponentData, IQueryTypeParameter, ISerializable
Base:
System.ValueType
Summary:
A lightweight ECS component that represents a resource and an amount a vehicle returns (unloads) back to the economy. The struct is designed to be stored on entities (implements IComponentData), used in query-type parameters (IQueryTypeParameter), and supports custom save/load serialization via ISerializable. Serialization encodes the resource as a single signed byte (resource index) followed by a 32-bit integer amount.
Fields
-
public Resource m_Resource
Holds the type of resource being returned. Resource is an enum (from Game.Economy) representing game resource types. During serialization this is converted to a small index via EconomyUtils.GetResourceIndex. -
public int m_Amount
The integer amount of the resource being returned/unloaded by the vehicle.
Properties
- None. This struct exposes public fields and has no properties.
Constructors
- Implicit parameterless constructor (default)
No explicit constructors are defined in code. The default parameterless constructor provided by C# for structs applies. Initialize fields directly when creating an instance (see usage example).
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to a binary writer. Implementation details:- Converts the Resource to a small index using EconomyUtils.GetResourceIndex(m_Resource) and casts it to sbyte, then writes that sbyte.
- Writes m_Amount as an int.
-
Generic writer must implement IWriter; order and types must match Deserialize.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component from a binary reader. Implementation details: - Reads an sbyte (resource index), then reads an int into m_Amount.
- Maps the sbyte index back to a Resource using EconomyUtils.GetResource(value).
- Generic reader must implement IReader; expects the same byte/order layout produced by Serialize.
Notes and caveats: - The resource index is written as an sbyte. If EconomyUtils.GetResourceIndex can return values outside the sbyte[-128..127] range, data corruption will occur; in practice resource counts are small and fit in a single byte. - Preserve the same write/read order and types when interoperating with other save/load systems or network messages. - This type is intended for in-game state persistence and ECS usage; it is not responsible for transferring the resource to the economy itself — it only describes what/how much is returned.
Usage Example
// Create and attach a ReturnLoad component to an entity
var returnLoad = new ReturnLoad
{
m_Resource = Game.Economy.Resource.Food,
m_Amount = 250
};
entityManager.AddComponentData(vehicleEntity, returnLoad);
// When serialized, the writer will receive:
// 1) sbyte resource index (via EconomyUtils.GetResourceIndex(Resource.Food))
// 2) int 250
{{ Additional notes: - Implementing IQueryTypeParameter allows this struct to be used as a compile-time query parameter in Unity Entities queries where supported by the game's ECS utilities. - When modding, prefer using EconomyUtils helpers for mapping to ensure compatibility with the game's resource indexing and any dynamic resource sets added by other mods. - If you extend or change the serialization order/fields, bump any relevant save format versioning the game or mod uses to avoid load errors. }}