Skip to content

Game.Prefabs.StorageAreaData

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents storage area metadata for a prefab: which Resource types the storage accepts and its capacity. The struct is an ECS component (IComponentData) and supports the game's custom serialization (ISerializable) for saving/loading prefab/component data. It is used by storage-related systems to determine resource handling and space limits.


Fields

  • public Resource m_Resources
    Holds the resource type(s) accepted by the storage area. The Resource type (from Game.Economy) is serialized as an unsigned 64-bit value in this implementation; the field is set/read via casting to/from ulong.

  • public int m_Capacity
    Integer capacity of the storage area. Represents how much of the resource can be stored. Serialized immediately after m_Resources in the writer stream.

Properties

  • (none)
    This struct exposes no CLR properties; it uses public fields for data storage.

Constructors

  • (default)
    No explicit constructors are defined. The default parameterless value-type constructor applies (m_Resources default, m_Capacity = 0).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the component into the provided writer. Implementation details:
  • Casts m_Resources to ulong and writes it first.
  • Writes m_Capacity as an int immediately after.
  • Generic writer must implement IWriter.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the component from the provided reader. Implementation details:

  • Reads an ulong value (the serialized Resource) and assigns it to m_Resources by casting.
  • Reads the next int into m_Capacity.
  • The read order must match Serialize: resources first, then capacity.
  • Generic reader must implement IReader.

Notes: - The serialization uses a fixed order and explicit casting between Resource and ulong; ensure compatibility if Resource changes (e.g., size/representation). - Because this is a struct component, systems interacting with it normally use ECS patterns (EntityManager, queries, or IJobEntity).

Usage Example

// Creating and attaching the component to an entity (example ECS usage)
var storage = new Game.Prefabs.StorageAreaData
{
    m_Resources = Resource.Wood, // example Resource enum value
    m_Capacity = 500
};
entityManager.AddComponentData(entity, storage);

// Example of manual serialization (pseudo-code, depends on actual writer implementation)
var writer = /* obtain IWriter instance */;
storage.Serialize(writer);

// Example of manual deserialization
var reader = /* obtain IReader instance */;
var loaded = new Game.Prefabs.StorageAreaData();
loaded.Deserialize(reader);
// loaded.m_Resources and loaded.m_Capacity now populated