Game.Prefabs.Prison
Assembly:
Assembly-CSharp (Unity game assembly)
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase, IServiceUpgrade
Summary:
Prison is a prefab Component used by the game to configure prison buildings. It exposes editable fields for van capacity, prisoner capacity, prisoner wellbeing and health. During instantiation it supplies component types required for the entity archetype (such as Prison, ServiceDispatch, OwnedVehicle, Occupant, Efficiency, ServiceDistrict) and writes initial PrisonData and UpdateFrameData into the entity. The archetype composition depends on whether the prefab has other components (ServiceUpgrade, CityServiceBuilding, UniqueObject) and whether prisoner capacity is non-zero.
Fields
-
public int m_PrisonVanCapacity
Default: 10. Number of prisoner transport vans the prison supports; copied into PrisonData.m_PrisonVanCapacity during Initialize. -
public int m_PrisonerCapacity
Default: 500. Number of prisoners the building can hold; if non-zero the archetype includes an Occupant component and this value is written into PrisonData.m_PrisonerCapacity during Initialize. -
public sbyte m_PrisonerWellbeing
Prisoner wellbeing value copied into PrisonData.m_PrisonerWellbeing during Initialize. -
public sbyte m_PrisonerHealth
Prisoner health value copied into PrisonData.m_PrisonerHealth during Initialize.
Properties
- None (no properties are declared in this prefab)
Constructors
public Prison()
Implicit default constructor. Field defaults are defined inline (m_PrisonVanCapacity = 10, m_PrisonerCapacity = 500). No custom constructor logic is present.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types required by the prefab asset itself (PrisonData and UpdateFrameData). This is used by the prefab system to know which component data blobs the prefab will provide or require. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds component types that should be present on entities created from this prefab. Always adds the runtime Game.Buildings.Prison type. If the prefab does not include a ServiceUpgrade component: - If the prefab has CityServiceBuilding, Efficiency is added.
- ServiceDispatch and OwnedVehicle are added.
- If the prefab does not have UniqueObject, ServiceDistrict is added.
-
If m_PrisonerCapacity != 0, Occupant is added. This conditional logic allows the same prefab to be used as base building or as an upgrade and to adapt its archetype accordingly.
-
public void GetUpgradeComponents(HashSet<ComponentType> components)
Called for service upgrades; adds Game.Buildings.Prison, ServiceDispatch, OwnedVehicle and, when m_PrisonerCapacity != 0, Occupant. Similar to GetArchetypeComponents but tailored for upgrade prefabs. -
public override void Initialize(EntityManager entityManager, Entity entity)
Writes instance data into the newly created entity: - Creates a PrisonData struct and sets m_PrisonVanCapacity, m_PrisonerCapacity, m_PrisonerWellbeing, m_PrisonerHealth from the prefab fields, then writes it with entityManager.SetComponentData.
- Writes an UpdateFrameData with value 3 into the entity. This ensures the runtime components hold the values configured on the prefab.
Usage Example
// Example: create an entity from a prison prefab (pseudocode; actual prefab retrieval depends on game systems)
Prison prisonPrefab = /* obtain prefab instance from game's prefab manager */;
EntityManager entityManager = /* get EntityManager */;
EntityArchetype archetype = /* build archetype using prefab.GetArchetypeComponents(...) */;
Entity prisonEntity = entityManager.CreateEntity(archetype);
// Initialize component data on the created entity using the prefab's values
prisonPrefab.Initialize(entityManager, prisonEntity);
// After Initialize, the entity will have PrisonData (with capacities/health/wellbeing) and UpdateFrameData(3)