Game.Prefabs.Workplace
Assembly:
Assembly-CSharp.dll
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase, IServiceUpgrade
Summary:
Workplace is a prefab component used to configure workplace-related data for building prefabs (number of worker slots, minimum workers, complexity and shift probabilities). It registers the runtime components required for employment (WorkProvider and Employee) when appropriate and writes a WorkplaceData component into the entity during prefab initialization. If the prefab has a ServiceUpgrade component attached, archetype registration of WorkProvider/Employee is skipped (upgrades manage these differently).
Fields
-
public int m_Workplaces
Number of worker slots provided by the prefab (max amount of workers). Tooltip indicates that for company buildings the actual max per-company can change dynamically depending on company prefab settings. -
public int m_MinimumWorkersLimit
Minimum number of workers this workplace enforces. -
public WorkplaceComplexity m_Complexity
Complexity classification for this workplace (enum type used by simulation to affect employment behavior). -
public float m_EveningShiftProbability
Probability value controlling whether an evening shift is present/used. -
public float m_NightShiftProbability
Probability value controlling whether a night shift is present/used.
Properties
This type does not declare any public properties.
Constructors
public Workplace()
Implicit public default constructor. Workplace is intended to be used as a component on building prefabs and normally configured in the editor; construction is handled by Unity/engine code.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds WorkplaceData to the prefab's component list so instances will include WorkplaceData. This ensures the runtime entity has a WorkplaceData component populated from the prefab fields. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
When the prefab does not include a ServiceUpgrade component and m_Workplaces > 0, this method adds WorkProvider and Employee to the archetype so runtime entities will allocate storage for those components. If the prefab represents an upgrade (ServiceUpgrade present), archetype registration is intentionally skipped. -
public void GetUpgradeComponents(HashSet<ComponentType> components)
Implementation for IServiceUpgrade. For upgrade cases with m_Workplaces > 0, adds WorkProvider and Employee component types so the upgrade archetype includes them. -
public override void Initialize(EntityManager entityManager, Entity entity)
Writes the WorkplaceData component to the entity using current prefab field values: - m_MaxWorkers = m_Workplaces
- m_MinimumWorkersLimit = m_MinimumWorkersLimit
- m_Complexity = m_Complexity
- m_EveningShiftProbability = m_EveningShiftProbability
- m_NightShiftProbability = m_NightShiftProbability
This is called during prefab/entity creation so the simulation receives the configured workplace parameters.
Usage Example
// Example: a derived prefab component that wants to observe the data written by Workplace.
// Typically Workplace is configured in prefab assets in the editor and Initialize is called by the engine.
// You can access WorkplaceData from the entity after initialization:
public class MyCustomWorkplaceObserver : Workplace
{
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity); // Workplace writes WorkplaceData here
// Read the WorkplaceData just set
var data = entityManager.GetComponentData<WorkplaceData>(entity);
Debug.Log($"Workplace initialized: MaxWorkers={data.m_MaxWorkers}, MinLimit={data.m_MinimumWorkersLimit}");
}
}
Notes and tips: - If your prefab should be treated as an upgrade (ServiceUpgrade), include a ServiceUpgrade component; Workplace will not add WorkProvider/Employee into the base archetype in that caseāuse GetUpgradeComponents during upgrade archetype construction. - To change worker counts at runtime for company-managed workplaces, company prefab settings (m_MaxWorkersPerCell) may also affect actual per-company limits; m_Workplaces is the building's base value.