Skip to content

Game.Prefabs.ZoneServiceConsumption

Assembly:
Game (game code assembly — exact assembly name may vary)

Namespace:
Game.Prefabs

Type:
class

Base:
ComponentBase, IZoneBuildingComponent

Summary:
ZoneServiceConsumption is a prefab-level component used by zone prefabs to declare generic per-zone service consumption values (upkeep, electricity, water, garbage accumulation, telecom need). When the zone prefab is instantiated it writes a ZoneServiceConsumptionData component to the prefab entity. It also provides data and archetype contributions for building prefabs that inherit service consumption values (via ConsumptionData) unless those building prefabs already supply their own ServiceConsumption.


Fields

  • public float m_Upkeep
    Used to declare the upkeep cost associated with the zone/service. This value is copied into ZoneServiceConsumptionData on prefab initialization and is part of ConsumptionData provided to buildings (note: GetBuildingConsumptionData sets m_Upkeep = 0 for building ConsumptionData — upkeep is kept for zone-level data).

  • public float m_ElectricityConsumption
    Electricity demand value for the zone/service. Copied into ZoneServiceConsumptionData and forwarded to building ConsumptionData so individual buildings can consume electricity accordingly.

  • public float m_WaterConsumption
    Water demand value. Copied into ZoneServiceConsumptionData and forwarded to building ConsumptionData.

  • public float m_GarbageAccumulation
    Garbage accumulation rate. Copied into ZoneServiceConsumptionData and forwarded to building ConsumptionData.

  • public float m_TelecomNeed
    Telecom (communications) need value. Copied into ZoneServiceConsumptionData and forwarded to building ConsumptionData.

Properties

  • This class defines no CLR properties. Its data is exposed through public fields and is transferred into ECS component structs at initialization.

Constructors

  • public ZoneServiceConsumption()
    Default parameterless constructor (implicit). Component instances are typically created/edited in prefab assets or via Unity's inspector; initialization into ECS happens via Initialize(EntityManager, Entity).

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime ECS component types required on the zone prefab entity. Implementation: adds ComponentType.ReadWrite() so the prefab entity carries the zone-level consumption data.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No archetype components are added by this component for prefab archetypes (empty implementation).

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when converting/initializing the prefab entity into ECS. Writes a ZoneServiceConsumptionData instance into the entity with values taken from the public fields (m_Upkeep, m_ElectricityConsumption, m_WaterConsumption, m_GarbageAccumulation, m_TelecomNeed). Also calls base.Initialize.

  • public void GetBuildingPrefabComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
    Adds ComponentType.ReadWrite() for building prefabs that will receive consumption data (This tells the building prefab entity to include a ConsumptionData component).

  • public void GetBuildingArchetypeComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
    If the buildingPrefab does not already have a ServiceConsumption component, this method adds the archetype components required by the ConsumptionData returned by GetBuildingConsumptionData(). Effectively ensures buildings get the ConsumptionData fields in their archetype if they don't override service consumption themselves.

  • public void InitializeBuilding(EntityManager entityManager, Entity entity, BuildingPrefab buildingPrefab, byte level)
    During building prefab/entity initialization, if the building prefab does not already provide ServiceConsumption, this writes a ConsumptionData instance into the building entity using GetBuildingConsumptionData() (populated from this zone component's values).

  • private ConsumptionData GetBuildingConsumptionData()
    Creates and returns a ConsumptionData struct seeded from this component's public fields. Note: this implementation sets ConsumptionData.m_Upkeep = 0 for buildings (upkeep is treated at the zone level), while electricity/water/garbage/telecom values are copied from the zone component.

Usage Example

// Typical usage: configure values on the ZoneServiceConsumption component in the prefab (Inspector).
// At ECS conversion time the component's Initialize method writes ZoneServiceConsumptionData to the prefab entity.

ZoneServiceConsumption zoneComp = /* obtained from prefab or created in code */;
zoneComp.m_Upkeep = 5f;
zoneComp.m_ElectricityConsumption = 2.5f;
zoneComp.m_WaterConsumption = 1.2f;
zoneComp.m_GarbageAccumulation = 0.3f;
zoneComp.m_TelecomNeed = 0.8f;

// When converting the prefab to an ECS entity:
zoneComp.Initialize(entityManager, prefabEntity);

// For building prefabs that don't override ServiceConsumption, the system will:
// - add ConsumptionData to their archetype via GetBuildingArchetypeComponents
// - write ConsumptionData to building entities via InitializeBuilding