Game.Prefabs.DisasterFacility
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase, IServiceUpgrade
Summary:
DisasterFacility is a prefab component used for disaster-related city service buildings. It declares which ECS components should be present on the prefab and on created archetypes, and it performs initial per-entity setup (initializing UpdateFrameData). The class is decorated with a ComponentMenu attribute, placing it under "Buildings/CityServices/" for prefab tooling and indicating it is applicable to BuildingPrefab and BuildingExtensionPrefab types.
Fields
- This type declares no instance fields.
The class is stateless and only adds component types and performs initialization via EntityManager.
Properties
- This type declares no properties.
Constructors
public DisasterFacility()
No explicit constructor is declared; the default parameterless constructor is used.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types that should exist on the prefab instance. Specifically:- Adds
ComponentType.ReadWrite<DisasterFacilityData>()
-
Adds
ComponentType.ReadWrite<UpdateFrameData>()
These indicate that prefab instances will carry the disaster facility data and an update-timing component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds component types that should be present on the entity archetype for this prefab. Specifically: - Adds
ComponentType.ReadWrite<Game.Buildings.DisasterFacility>()
-
Conditionally adds
ComponentType.ReadWrite<Efficiency>()
when this prefab does NOT have a ServiceUpgrade component but DOES have a CityServiceBuilding component:- Condition in source:
if (GetComponent<ServiceUpgrade>() == null && GetComponent<CityServiceBuilding>() != null) { components.Add(ComponentType.ReadWrite<Efficiency>()); }
This controls whether an Efficiency component is included on the building archetype (useful for service buildings that support efficiency).
- Condition in source:
-
public void GetUpgradeComponents(HashSet<ComponentType> components)
(From IServiceUpgrade) Adds components required for the upgraded variant: -
Adds
ComponentType.ReadWrite<Game.Buildings.DisasterFacility>()
This lists the components necessary when applying upgrades to the service building. -
public override void Initialize(EntityManager entityManager, Entity entity)
Per-entity initialization executed when an entity is created from the prefab. Implementation sets the UpdateFrameData component to 0: entityManager.SetComponentData(entity, new UpdateFrameData(0));
Ensures newly created disaster facility entities start with a defined update-frame state.
Usage Example
// The prefab system calls these methods when building entities/archetypes.
// Example: the prefab's Initialize method ensures UpdateFrameData is set.
public class DisasterFacility : ComponentBase, IServiceUpgrade
{
public override void Initialize(EntityManager entityManager, Entity entity)
{
// Ensure the update-frame timer/data is initialized for newly created entities.
entityManager.SetComponentData(entity, new UpdateFrameData(0));
}
// Other methods shown in the class add the required ECS component types
// to prefabs and archetypes (DisasterFacilityData, UpdateFrameData, etc.)
}
Notes and remarks: - The class relies on several ECS and game-specific types: DisasterFacilityData, UpdateFrameData, Game.Buildings.DisasterFacility, Efficiency, ServiceUpgrade, CityServiceBuilding. - The ComponentMenu attribute places this component under the editor menu path "Buildings/CityServices/" and marks it relevant for BuildingPrefab and BuildingExtensionPrefab objects. This affects how the prefab editor and tooling present and use the component.