Skip to content

Game.Prefabs.ZonePollution

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase, IZoneBuildingComponent

Summary:
Provides configurable pollution values for zone prefabs (ground, air, noise). When a zone prefab is initialized this component writes a ZonePollutionData component to the zone entity. It also provides building-specific pollution initialization by scaling the zone values by the building's lot size and writing a PollutionData component for building entities. Input values are constrained to be non-negative via Unity's [Min(0f)] attribute.


Fields

  • public float m_GroundPollution
    Controls ground pollution contributed by this zone prefab. Value is clamped to be >= 0 via [Min(0f)].

  • public float m_AirPollution
    Controls air pollution contributed by this zone prefab. Value is clamped to be >= 0 via [Min(0f)].

  • public float m_NoisePollution
    Controls noise pollution contributed by this zone prefab. Value is clamped to be >= 0 via [Min(0f)].

Properties

  • This class exposes no public properties.

Constructors

  • public ZonePollution()
    Default parameterless constructor (implicit). Typically the component is configured in the prefab inspector rather than constructed in code.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ZonePollutionData (read/write) to the set of components required by the zone prefab. This ensures zone entities will have the data container that stores the configured pollution values.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty in this implementation. The method is present to allow adding archetype-level components for the zone itself if needed; currently nothing is added here.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the zone prefab is instantiated. Writes a ZonePollutionData struct to the given entity with the values from m_GroundPollution, m_AirPollution, and m_NoisePollution.

  • public void GetBuildingPrefabComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
    Adds PollutionData (read/write) to the component set for building prefabs. This signals that building entities produced from this zone should include PollutionData.

  • public void GetBuildingArchetypeComponents(HashSet<ComponentType> components, BuildingPrefab buildingPrefab, byte level)
    Delegates to the pollution-data helper to add any required archetype components for buildings. Internally calls GetBuildingPollutionData(buildingPrefab).AddArchetypeComponents(components).

  • public void InitializeBuilding(EntityManager entityManager, Entity entity, BuildingPrefab buildingPrefab, byte level)
    Initializes a building entity's pollution data. If the buildingPrefab does not already have a Pollution component, this sets the building entity's PollutionData to the values returned by GetBuildingPollutionData(buildingPrefab). This avoids overwriting explicitly defined building-level pollution.

  • private PollutionData GetBuildingPollutionData(BuildingPrefab buildingPrefab)
    Creates and returns a PollutionData instance computed by multiplying the zone's m_GroundPollution, m_AirPollution, and m_NoisePollution by the building's lotSize. This implements simple scaling of zone pollution to building footprint.

Notes / behavior summary: - Zone-level pollution values are stored in ZonePollutionData on zone entities. - Building pollution uses PollutionData and is only set if the building prefab does not already define its own Pollution. - The scaling uses buildingPrefab.lotSize as an integer multiplier. - The class is annotated with [ComponentMenu("Zones/", typeof(ZonePrefab))] so it appears under Zones in the component add menu.

Usage Example

// Example: initialize a building entity with pollution based on a ZonePollution component

// Assume zonePollution is a ZonePollution component on a zone prefab (configured in inspector)
ZonePollution zonePollution = /* obtain reference from prefab or serialized data */;

// BuildingPrefab and entity setup (obtained from the prefab system)
BuildingPrefab buildingPrefab = /* get building prefab */;
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity buildingEntity = /* created building entity */;
byte level = 0;

// Initialize building pollution data (will scale by lotSize and write PollutionData)
// This will only write the PollutionData if the building prefab does not already have a Pollution component.
zonePollution.InitializeBuilding(entityManager, buildingEntity, buildingPrefab, level);

Additional references: ZonePollutionData, PollutionData, Pollution, BuildingPrefab, ZonePrefab, ComponentType, EntityManager, Entity.