Skip to content

Game.Companies.StorageTransfer

Assembly:
Namespace: Game.Companies

Type: struct (value type)

Base: System.ValueType, implements IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents a serializable ECS component that describes a transfer of a specific economy Resource and an integer Amount. Used by the game's company systems to record/resource transfers in entity components and to persist those transfers through the game's serialization system. Serialization encodes the resource as a signed byte index and the amount as a 32-bit integer.


Fields

  • public Resource m_Resource Holds the resource type being transferred. The Resource type is defined in Game.Economy. When serialized, the resource is converted to a compact sbyte index via EconomyUtils.GetResourceIndex and restored with EconomyUtils.GetResource.

  • public int m_Amount The amount/quantity of the resource to transfer. Serialized as a 32-bit integer.

Properties

  • This type defines no properties. It exposes data via public fields and implements serialization methods for persistence.

Constructors

  • public StorageTransfer() Default parameterless struct constructor (implicit). By default m_Resource will be the default Resource value and m_Amount will be 0. Typical usage initializes fields directly via an object/collection initializer.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Serializes this instance. Implementation details:
  • Converts m_Resource to a resource index using EconomyUtils.GetResourceIndex and casts it to sbyte, then writes that sbyte.
  • Writes m_Amount as an int. This produces a compact representation suitable for the game's save/serialization pipeline.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Deserializes into this instance. Implementation details:

  • Reads a sbyte resource index and an int amount from the reader.
  • Looks up the corresponding Resource via EconomyUtils.GetResource(index) and assigns it to m_Resource.
  • Assigns the read int to m_Amount.

Notes: - The resource index is stored as an sbyte. The set of resources in the game is expected to fit within that range; if custom mods add resources with indexes outside sbyte range, serialization may be truncated or corrupted. - The struct implements IComponentData / IQueryTypeParameter so it is usable as an ECS component in Unity's Data-Oriented Tech Stack (DOTS) contexts used by the game.

Usage Example

// Create and initialize a StorageTransfer instance
var transfer = new Game.Companies.StorageTransfer {
    m_Resource = Game.Economy.Resource.Wood,
    m_Amount = 250
};

// Add as an ECS component to an entity (EntityManager usage)
entityManager.AddComponentData(entity, transfer);

// Serialization example (calls the component's Serialize). 
// TWriter must implement Colossal.Serialization.Entities.IWriter (game save system writer).
// This is a conceptual example; actual writer type depends on the game's serialization API.
TWriter writer = /* obtain writer from game save system */;
transfer.Serialize(writer);

// Deserialization example (reads back the data)
Game.Companies.StorageTransfer loaded = default;
TReader reader = /* obtain reader from game save system */;
loaded.Deserialize(reader);
// loaded.m_Resource and loaded.m_Amount now contain persisted values