Skip to content

Game.Prefabs.PollutionModifier

Assembly: Assembly-CSharp (game code / mod assembly)
Namespace: Game.Prefabs

Type: public class

Base: ComponentBase

Summary:
PollutionModifier is a prefab component applied to building/service upgrade prefabs to modify pollution output. It exposes three configurable multipliers (ground, air, noise) which are written into the ECS component PollutionModifierData when the prefab is initialized. The component is intended for use on service upgrade prefabs and will log an error if attached to a prefab that does not have the ServiceUpgrade component.


Fields

  • public float m_GroundPollutionMultiplier
    Tooltip: "Factor to increase (+) or decrease (-) ground pollution"
    Range: [-1f, 1f]
    {{ Controls how the ground (terrain) pollution contribution of the building is adjusted. The value is written to PollutionModifierData.m_GroundPollutionMultiplier during initialization. Positive values increase pollution, negative values decrease it. }}

  • public float m_AirPollutionMultiplier
    Tooltip: "Factor to increase (+) or decrease (-) air pollution"
    Range: [-1f, 1f]
    {{ Adjusts the building's air pollution contribution. Value is copied into PollutionModifierData.m_AirPollutionMultiplier during Initialize. }}

  • public float m_NoisePollutionMultiplier
    Tooltip: "Factor to increase (+) or decrease (-) noise pollution"
    Range: [-1f, 1f]
    {{ Adjusts the building's noise pollution contribution. Value is copied into PollutionModifierData.m_NoisePollutionMultiplier during Initialize. }}

Properties

  • (none declared)
    {{ This component does not expose C# properties. It only contains public serialized fields that appear in the inspector and are transferred to the ECS component PollutionModifierData at initialization. }}

Constructors

  • public PollutionModifier()
    {{ Uses the default parameterless constructor provided by C#. No custom construction logic is present in the source file. Initialization work is performed in the overridden Initialize method. }}

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    {{ Adds the ECS component type required by this prefab to the set of prefab components. Specifically it adds ComponentType.ReadWrite(), indicating that an instance of PollutionModifierData will be present on entities spawned from this prefab. }}

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {{ Present but empty. The component does not declare additional archetype-only components here. }}

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

  • Verifies that the prefab has a ServiceUpgrade component; if not, logs an error because this modifier is intended for service upgrade prefabs.
  • Writes the inspector-configured multipliers (m_GroundPollutionMultiplier, m_AirPollutionMultiplier, m_NoisePollutionMultiplier) into the PollutionModifierData component on the ECS entity using entityManager.SetComponentData. }}

Notes and Remarks

  • ComponentMenu attribute: [ComponentMenu("Buildings/", typeof(BuildingPrefab), typeof(BuildingExtensionPrefab))] — places this component in the "Buildings/" menu for BuildingPrefab and BuildingExtensionPrefab types in the prefab editor.
  • Range attributes clamp values in the inspector between -1 and 1.
  • The actual runtime effect (how those multipliers are applied to pollution calculations) is implemented elsewhere in the game's systems which read PollutionModifierData.
  • Intended usage is for ServiceUpgrade prefabs; attaching to other prefabs will produce an error log.

Usage Example

// Example: typical setup is done in the inspector by adding PollutionModifier to a ServiceUpgrade prefab
// and setting the multipliers. At runtime, the Initialize method copies these values into the ECS component.
//
// Programmatic example: read the ECS data on a constructed entity (runtime)
PollutionModifierData data = entityManager.GetComponentData<PollutionModifierData>(entity);
float groundMultiplier = data.m_GroundPollutionMultiplier;
float airMultiplier = data.m_AirPollutionMultiplier;
float noiseMultiplier = data.m_NoisePollutionMultiplier;

// Inspector example:
// - Add PollutionModifier to a Building or BuildingExtension prefab (under Buildings/ menu)
// - Set m_GroundPollutionMultiplier = -0.5f  // reduces ground pollution by 50%
// - Set m_AirPollutionMultiplier =  0.2f   // increases air pollution by 20%
// - Set m_NoisePollutionMultiplier = 0f    // no change to noise