Game.Prefabs.StorageCompanyData
Assembly: Game
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable, ICombineData
Summary:
StorageCompanyData is an ECS component (IComponentData) used on storage company prefabs/buildings. It stores which Resource types the company holds and a packed int2 used for transport interval data. The struct is serializable for prefab/entity persistence and supports combination/merging with other StorageCompanyData instances (used when merging prefab data or resolving multiple data sources). The deserialization contains a version check to maintain backward compatibility with older serialized data that may not include the transport interval.
Fields
-
public Resource m_StoredResources
Represents the set of resources stored by the company. Treated as a flags/bitmask (Resource enum) — when combining two StorageCompanyData instances the stored resources are merged via bitwise OR. -
public int2 m_TransportInterval
A Unity.Mathematics.int2 holding transport-interval related values. The exact semantic (e.g., min/max interval, ticks, or start/end) is defined by game logic; this field is read/written only when serialized data version supports it (see Deserialize).
Properties
- None (this type exposes fields directly and implements its behavior via interfaces).
Constructors
public StorageCompanyData()
Default value-type constructor (implicit). Fields will be default-initialized (m_StoredResources = 0, m_TransportInterval = (0,0)) unless explicitly set.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to a writer for persistence. It writes m_StoredResources (as ulong) and then writes m_TransportInterval. Used when saving prefabs/entities.
Behavior: - Writes the stored resources as an unsigned long (casting from Resource). - Writes the int2 transport interval following the resource value.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component from a reader. Restores m_StoredResources from an unsigned long value. The transport interval is only read if the reader.context.version indicates the data format contains it.
Behavior: - Reads an ulong and casts to Resource for m_StoredResources. - If reader.context.version > Version.transportInterval, reads an int2 into m_TransportInterval. - This version check preserves compatibility with older saved data that lacked the transport interval.
public void Combine(StorageCompanyData otherData)
Merges another StorageCompanyData into this instance. Currently this operation ORs the stored resource flags:- m_StoredResources |= otherData.m_StoredResources
- The transport interval is not modified by Combine in the current implementation.
Usage Example
using Unity.Mathematics;
using Unity.Entities;
using Game.Prefabs;
using Game.Economy;
// Create and initialize component data
var storageData = new StorageCompanyData {
m_StoredResources = Resource.Wood | Resource.Stone,
m_TransportInterval = new int2(60, 120) // example values (semantics depend on game logic)
};
// Combine with another data instance
var other = new StorageCompanyData {
m_StoredResources = Resource.Ore
};
storageData.Combine(other); // now includes Wood, Stone, and Ore
// Add to an entity in ECS
// entityManager.AddComponentData(entity, storageData);
// Serialization example (pseudo-code)
// writer.Context.version must be set appropriately
// storageData.Serialize(writer);
// Deserialization example (pseudo-code)
// storageData.Deserialize(reader);
Notes: - Because StorageCompanyData implements IComponentData it can be attached to Entities via the ECS EntityManager. - The Version.transportInterval check in Deserialize indicates that older serialized blobs may not contain the transport interval; ensure reader.context.version is managed correctly when reading saved data.