Skip to content

Game.Prefabs.StorageArea

Assembly: Assembly-CSharp (typical Unity user assembly)
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
A prefab Component used to define storage/warehouse lots in the game. Exposes editable fields for which resources the storage accepts and its capacity, and initializes the ECS component data (StorageAreaData) and archetype components (Storage, OwnedVehicle) for the entity. This prefab is intended to be added to lot prefabs so the entity will have the necessary runtime ECS components for storage behavior.


Fields

  • public ResourceInEditor[] m_StoredResources
    Array of resources (editor-facing resource descriptors) that this storage lot will accept. During Initialize these entries are converted (via EconomyUtils.GetResource) into the internal Resource bitmask stored in StorageAreaData.m_Resources. This field may be null — in that case no resources are set (Resource.NoResource).

  • public int m_Capacity
    The integer capacity value used to initialize StorageAreaData.m_Capacity. Represents how much the storage can hold (unit semantics determined by the game's economy/storage systems).

Properties

  • This class does not declare any public properties. It exposes public fields for editor configuration that are used to populate ECS component data at initialization.

Constructors

  • public StorageArea()
    Default constructor (generated by C#; no explicit constructor logic in the source). Initialization logic for ECS data is performed in the overridden Initialize method rather than in a constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component types that should be present on the prefab instance. Specifically adds:
  • ComponentType.ReadWrite()
    This ensures the StorageAreaData component exists on entities created from this prefab.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype component types required for the storage lot runtime behavior. Specifically adds:

  • ComponentType.ReadWrite() — identifies the entity as a storage container
  • ComponentType.ReadWrite() — used to track vehicles owned/assigned to this lot

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Initializes the entity's StorageAreaData component based on this prefab's inspector fields:

  • Calls base.Initialize(entityManager, entity).
  • Converts each entry in m_StoredResources (if not null) to the internal Resource enum/bitmask using EconomyUtils.GetResource and combines them using bitwise OR into a single Resource value.
  • Creates a StorageAreaData instance with m_Resources set to the combined Resource bitmask and m_Capacity set from this.m_Capacity.
  • Writes the StorageAreaData into the entity using entityManager.SetComponentData(entity, componentData). Notes: If m_StoredResources is null or empty the resulting m_Resources will be Resource.NoResource. This method does not add components (that is done via GetPrefabComponents/GetArchetypeComponents) but it sets the component data values.

Usage Example

// Example: a custom prefab class or editor code might configure the StorageArea fields in the inspector.
// At runtime, when the prefab entity is created the Initialize method is invoked and the StorageAreaData is set.

public class MyCustomStoragePrefab : StorageArea
{
    // In the Unity Editor, m_StoredResources and m_Capacity are set on the prefab.
    // The base Initialize will convert those editor entries into StorageAreaData on the entity.
}

// Example of what Initialize does (logic mirrored from StorageArea.Initialize):
[Preserve]
public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    Resource resourceMask = Resource.NoResource;
    if (m_StoredResources != null)
    {
        for (int i = 0; i < m_StoredResources.Length; i++)
        {
            resourceMask |= EconomyUtils.GetResource(m_StoredResources[i]);
        }
    }

    StorageAreaData data = default(StorageAreaData);
    data.m_Resources = resourceMask;
    data.m_Capacity = m_Capacity;
    entityManager.SetComponentData(entity, data);
}

Additional notes for modders: - The mapping from ResourceInEditor to the internal Resource enum is handled by EconomyUtils.GetResource; ensure custom ResourceInEditor entries are supported by EconomyUtils if you add new resource types. - Storage capacity units and behavior are driven by Storage/StorageAreaData systems; changing m_Capacity affects how much the storage can hold but other systems determine consumption/production rates. - This class relies on Unity.Entities API (EntityManager, Entity, ComponentType). Make sure your mod's assembly references the correct Entities package and matches the game's DOTS/ECS version.