Game.Prefabs.PowerPlant
Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase, IServiceUpgrade
Summary:
Represents a power plant building prefab component used by the game to configure electricity-producing buildings. The class exposes a configurable integer m_ElectricityProduction and is responsible for adding the appropriate ECS component types for power plants (PowerPlantData, ElectricityProducer, Efficiency, ServiceUsage) and initializing the PowerPlantData component when an entity is created. The class is decorated with a ComponentMenu attribute so it appears under Buildings/CityServices in the editor and tooling.
Fields
public int m_ElectricityProduction
Number of electricity units this prefab produces (serialized/configurable on the prefab). This value is written into the PowerPlantData component during Initialize.
Properties
- (none declared in this class)
This class does not define properties. It implements IServiceUpgrade via a method (GetUpgradeComponents) rather than exposing upgrade-related properties.
Constructors
public PowerPlant()
Default constructor (implicit). Typical usage is through the prefab/inspector rather than constructing directly in code.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds runtime/prefab component types required for this prefab. Specifically, this method adds ComponentType.ReadWrite() to the provided set so the entity will have the PowerPlantData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds component types to the entity archetype used when instantiating the prefab. Behavior: - If the prefab does NOT already have a ServiceUpgrade component, the method will:
- Add Efficiency if the prefab has a CityServiceBuilding component.
- Add ElectricityProducer.
- Add ServiceUsage.
-
If a ServiceUpgrade component is present, the method skips adding those archetype components (upgrade handling is delegated elsewhere).
-
public void GetUpgradeComponents(HashSet<ComponentType> components)
Implementation of IServiceUpgrade to specify components that should be present when the building is upgraded. This adds ElectricityProducer, Efficiency, and ServiceUsage component types so an upgraded building gains production, efficiency, and service usage data. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the entity for this prefab is created. Writes the prefab configuration into the entity by setting PowerPlantData with m_ElectricityProduction: - entityManager.SetComponentData(entity, new PowerPlantData { m_ElectricityProduction = m_ElectricityProduction });
Additional notes: - The class assumes the existence of ECS component types: PowerPlantData, ElectricityProducer, Efficiency, ServiceUsage, and also checks for CityServiceBuilding and ServiceUpgrade components on the prefab to determine which archetype components to include. - The ComponentMenu attribute: [ComponentMenu("Buildings/CityServices/", new Type[] { typeof(BuildingPrefab), typeof(BuildingExtensionPrefab) })] places this component under the Buildings/CityServices menu and indicates it is associated with BuildingPrefab and BuildingExtensionPrefab types.
Usage Example
// Example: set production on a derived prefab class or via inspector
public class MySmallPowerPlant : PowerPlant
{
public MySmallPowerPlant()
{
// Configure production for this prefab (could also be set in the prefab inspector)
m_ElectricityProduction = 500;
}
}
// During entity creation the system will call Initialize and write PowerPlantData:
// entityManager.SetComponentData(entity, new PowerPlantData { m_ElectricityProduction = 500 });