Game.Prefabs.StorageCompany
Assembly: Assembly-CSharp (game)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
StorageCompany is a prefab component used to create and initialize storage-type company entities in the ECS world. It configures the industrial process data (inputs, output, max workers), storage data (which resource is stored), and optionally transport-related data (number of transports) and archetype components needed for transport-capable storage companies. It relies on EconomyUtils to resolve resource identifiers from the serialized IndustrialProcess definition.
Fields
-
public IndustrialProcess process
Holds the serialized industrial process description used by the storage company prefab. The data from this field (input resources/amounts, output resource/amount, max workers per cell) is converted into IndustrialProcessData and written to the entity in Initialize. -
public int transports
Number of transports to make available for this company. When greater than 0, the prefab adds transport-related components (TransportCompanyData in prefab components and TransportCompany / OwnedVehicle in archetype components) and sets TransportCompanyData.m_MaxTransports to this value during Initialize.
Properties
- (none)
Constructors
public StorageCompany()
Implicit default constructor. No special initialization beyond default field values; fields are typically configured in the prefab inspector.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types that should be attached to the entity instance created from this prefab:- Always adds StorageCompanyData and IndustrialProcessData (read/write).
-
Adds TransportCompanyData (read/write) only if transports > 0.
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds component types that must be part of the entity archetype (structural requirements) for this prefab: - If transports > 0, adds TransportCompany and OwnedVehicle (read/write).
-
Always adds Game.Companies.StorageCompany, TradeCost, ResourceSeller, and StorageTransferRequest (read/write).
-
public override void Initialize(EntityManager entityManager, Entity entity)
Populates the entity's component data based on the prefab's serialized fields: - Writes an IndustrialProcessData instance constructed from the prefab's process field. Resource references are resolved via EconomyUtils.GetResource.
- Writes StorageCompanyData with m_StoredResources set to the process output resource.
- If transports > 0, writes TransportCompanyData with m_MaxTransports set to the transports value.
Additional notes: - Uses EconomyUtils.GetResource(...) to translate serialized resource references into the runtime resource identifiers expected by component data. - The prefab class is annotated with [ComponentMenu("Companies/", new Type[] { typeof(CompanyPrefab) })], making it available under that menu path in the editor.
Usage Example
// Example: configuration via prefab fields (usually set in the Unity inspector).
// When the prefab system creates an entity from this prefab, Initialize(...) is invoked
// and the entity receives IndustrialProcessData, StorageCompanyData, and optionally
// TransportCompanyData (if transports > 0).
[ComponentMenu("Companies/", new Type[] { typeof(CompanyPrefab) })]
public class MyStoragePrefab : StorageCompany
{
// In the inspector set:
// process: input/output resources and amounts, max workers per cell
// transports: e.g. 4 to enable transports for this company
}
// The underlying Initialize implementation will do roughly:
protected void ExampleInitialize(EntityManager em, Entity e)
{
// IndustrialProcessData and StorageCompanyData are written based on `process`
// TransportCompanyData.m_MaxTransports is written if transports > 0
}