Skip to content

Game.Prefabs.WaterPowered

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase, implements IServiceUpgrade

Summary:
Component used on building prefabs that represent water-powered service buildings (works together with a PowerPlant component). Exposes inspector-configurable multipliers for production and capacity which are written into the ECS component WaterPoweredData when the prefab entity is initialized. Ensures the prefab's PowerPlant component does not define a non-zero electricity production (logs an error if it does). Also supplies the required ECS component types for both normal archetypes and upgrade archetypes.


Fields

  • public float m_ProductionFactor
    Multiplier applied to production values for the water-powered variant. The value set in the prefab is copied into WaterPoweredData during Initialize.

  • public float m_CapacityFactor
    Multiplier applied to capacity values for the water-powered variant. The value set in the prefab is copied into WaterPoweredData during Initialize.

Properties

  • None (no public properties defined on this class)

Constructors

  • public WaterPowered()
    Implicit default constructor used by Unity when the component is added to a GameObject. No custom construction logic is provided.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component type required on the prefab entity: WaterPoweredData (read/write). This ensures the ECS prefab includes the data blob for water-powered behavior.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    If the prefab is not an upgrade (i.e., does not have a ServiceUpgrade component), this adds the archetype components required for the full water-powered building at runtime: Game.Buildings.WaterPowered, Efficiency, and RenewableElectricityProduction (all read/write). This defines which components will exist on spawned building entities.

  • public void GetUpgradeComponents(HashSet<ComponentType> components)
    When the prefab represents an upgrade, this method adds the components necessary for the upgrade variant: Game.Buildings.WaterPowered and Efficiency (read/write).

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is converted into an ECS entity. Behavior:

  • If the associated PowerPlant component exists and its m_ElectricityProduction is non-zero, logs an error with the prefab reference (this component is intended for water-powered buildings which should not declare electricity production directly on the PowerPlant).
  • Writes a WaterPoweredData instance into the entity with m_ProductionFactor and m_CapacityFactor copied from the inspector fields.

Usage Example

// Example: read the values that the WaterPowered prefab wrote into the entity after initialization
EntityManager entityManager = ...; // obtained from the world
Entity prefabEntity = ...; // the prefab-converted entity for this building

if (entityManager.HasComponent<WaterPoweredData>(prefabEntity))
{
    var wp = entityManager.GetComponentData<WaterPoweredData>(prefabEntity);
    Debug.Log($"WaterPowered production factor: {wp.m_ProductionFactor}, capacity factor: {wp.m_CapacityFactor}");
}

Additional notes: - The component requires a PowerPlant Unity component on the same GameObject ([RequireComponent(typeof(PowerPlant))]) and is listed in the Unity component menu under "Buildings/CityServices/" with BuildingPrefab and BuildingExtensionPrefab types. - This component is intended to integrate with the game's ECS (Unity.Entities) prefab conversion pipeline; modders should set the multipliers in the inspector and rely on the conversion/Initialize flow to populate the entity data.