Skip to content

Game.Companies.StorageTransferRequest

Assembly: Assembly-CSharp
Namespace: Game.Companies

Type: struct (implements IBufferElementData, ISerializable)

Base: System.ValueType

Summary: Represents a single request to transfer a resource amount to/from a storage target in the game's economy. Designed to be stored in an ECS dynamic buffer (IBufferElementData) and supports manual binary serialization via the ISerializable interface. The struct contains transfer flags, the resource type, amount, and the target Entity. Serialization writes compact typed values and deserialization reconstructs the enum/Resource using EconomyUtils helpers.


Fields

  • public StorageTransferFlags m_Flags
    Holds flags that qualify this transfer request (direction, priority, or other transfer-related metadata). Serialized as a single byte.

  • public Resource m_Resource
    Represents the resource type being transferred (uses the game's Resource abstraction). During serialization the resource is converted to an sbyte index via EconomyUtils.GetResourceIndex and reconstructed with EconomyUtils.GetResource.

  • public int m_Amount
    Quantity of the resource to transfer. Serialized as a 32-bit int.

  • public Entity m_Target
    The ECS Entity that is the target of the transfer. Serialized/deserialized via the provided writer/reader for Entity values.

Properties

  • This type defines no C# auto-properties. All data is exposed via public fields to support efficient buffer storage and serialization.

Constructors

  • public StorageTransferRequest()
    Default struct constructor (value-type default initialization). Consumers typically create and populate instances inline or via initializers before adding to a DynamicBuffer.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the struct to a binary writer in the following order:
  • m_Flags as a single byte
  • m_Resource as an sbyte resource index (EconomyUtils.GetResourceIndex)
  • m_Amount as an int
  • m_Target as an Entity
    The explicit casts and ordering must be matched exactly by Deserialize.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the values in the same order that Serialize writes them and restores the field values. After reading the raw byte and sbyte values it maps them back to strongly typed values:

  • m_Flags is reconstructed from the byte
  • m_Resource is reconstructed using EconomyUtils.GetResource(sbyte)
  • m_Amount and m_Target are read directly into their fields

Usage Example

// Creating and adding a transfer request to an entity's DynamicBuffer
var request = new StorageTransferRequest {
    m_Flags = StorageTransferFlags.None,
    m_Resource = EconomyUtils.GetResource( (sbyte)0 ), // or assign a known Resource
    m_Amount = 100,
    m_Target = someTargetEntity
};

var buffer = EntityManager.GetBuffer<StorageTransferRequest>(ownerEntity);
buffer.Add(request);

// Example sketch of manual serialization (writer provided by engine serialization pipeline)
request.Serialize(writer);

// And deserialization usage (reader provided by engine)
var deserialized = new StorageTransferRequest();
deserialized.Deserialize(reader);

Notes: - The Serialize/Deserialize implementations must remain consistent in order and types (byte, sbyte, int, Entity). - EconomyUtils.GetResourceIndex and EconomyUtils.GetResource are used to compactly store Resource values as small integers. Ensure the resource index range fits in sbyte for safe serialization.