Skip to content

Game.Prefabs.PollutionPrefab

Assembly:
{{ Likely the main game assembly (e.g. Game.dll). Confirm in your build if different. }}

Namespace: Game.Prefabs

Type:
public class PollutionPrefab : PrefabBase

Base:
PrefabBase

Summary:
Defines the editable pollution tuning values used by the pollution systems. This MonoBehaviour prefab exposes multipliers, radii, fade values and notification settings for air, ground and noise pollution and converts them into a PollutionParameterData component on the prefab entity during LateInitialize. NotificationIconPrefab references are converted to entity handles using the PrefabSystem.


Fields

  • public float m_GroundMultiplier
    Controls strength of ground pollution. Default: 25f.

  • public float m_AirMultiplier
    Controls strength of air pollution. Default: 25f.

  • public float m_NoiseMultiplier
    Controls strength of noise pollution. Default: 100f.

  • public float m_NetAirMultiplier
    Multiplier used for net air pollution calculations. Default: 25f.

  • public float m_NetNoiseMultiplier
    Multiplier used for net noise pollution calculations. Default: 100f.

  • public float m_GroundRadius
    Effective radius for ground pollution. Default: 150f.

  • public float m_AirRadius
    Effective radius for air pollution. Default: 75f.

  • public float m_NoiseRadius
    Effective radius for noise pollution. Default: 200f.

  • public float m_NetNoiseRadius
    Radius for net noise propagation. Default: 50f.

  • public float m_WindAdvectionSpeed
    Speed used for advecting (moving) air pollution with wind. Default: 8f.

  • public short m_AirFade
    Fade parameter for air pollution (short). Default: 5.

  • public short m_GroundFade
    Fade parameter for ground pollution (short). Default: 10.

  • public float m_PlantAirMultiplier
    Multiplier for plant (vegetation) effect on air pollution removal. Default: 0.001f.

  • public float m_PlantGroundMultiplier
    Multiplier for plant effect on ground pollution removal. Default: 0.001f.

  • public float m_PlantFade
    Fade/distance exponent for plant pollution removal. Default: 2f.

  • public float m_FertilityGroundMultiplier
    Multiplier affecting fertility from ground pollution. Default: 1f.

  • public float m_DistanceExponent
    Distance exponent used when calculating falloff. Default: 2f.

  • public NotificationIconPrefab m_AirPollutionNotification
    Notification prefab shown for air pollution events (converted to an entity in LateInitialize).

  • public NotificationIconPrefab m_NoisePollutionNotification
    Notification prefab shown for noise pollution events (converted to an entity in LateInitialize).

  • public NotificationIconPrefab m_GroundPollutionNotification
    Notification prefab shown for ground pollution events (converted to an entity in LateInitialize).

  • public int m_AirPollutionNotificationLimit
    Tooltip: If happiness effect from air pollution is less than this, show notification. Default: -5.

  • public int m_NoisePollutionNotificationLimit
    Tooltip: If happiness effect from noise pollution is less than this, show notification. Default: -5.

  • public int m_GroundPollutionNotificationLimit
    Tooltip: If happiness effect from ground pollution is less than this, show notification. Default: -5.

  • public float m_AbandonedNoisePollutionMultiplier
    Multiplier applied to noise pollution from abandoned buildings. Default: 5f.

  • public int m_HomelessNoisePollution
    Noise pollution contributed by homeless population (integer). Default: 100.

  • public int m_GroundPollutionLandValueDivisor
    The divisor used to compute negative land value effect from ground pollution: (pollutionValue / divisor) is the land value penalty. Default: 500.

Properties

  • None declared in this class.
    {{ This prefab exposes only public fields; it does not define C# properties. The data is transferred to a PollutionParameterData ECS component. }}

Constructors

  • public PollutionPrefab()
    {{ Inherits default constructor from MonoBehaviour/PrefabBase. Typical instances are created as prefab assets in Unity, not via new() in code. No custom constructor logic in this class. }}

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    {{ Adds the PollutionParameterData component type to the set of components required by the prefab. Implementation calls base.GetPrefabComponents and then components.Add(ComponentType.ReadWrite()). This ensures the prefab entity will have PollutionParameterData so the pollution system can read parameter values at runtime. }}

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    {{ Converts this MonoBehaviour prefab into runtime component data. The method:

  • Calls base.LateInitialize.
  • Obtains the PrefabSystem (World.DefaultGameObjectInjectionWorld.GetOrCreateSystemManaged()).
  • Creates a PollutionParameterData instance populated with all the fields from this prefab.
  • Converts each NotificationIconPrefab reference to an entity via PrefabSystem.GetEntity(...) and stores those entity references on the PollutionParameterData.
  • Writes the component to the prefab entity using entityManager.SetComponentData(entity, pollutionParameterData). This is the key bridge between the editor-exposed prefab values and the ECS data used by the pollution simulation. }}

Usage Example

// Example: read PollutionParameterData for the active prefab entity
// (This would run at runtime, after prefabs have been initialized)
using Unity.Entities;

public void PrintPollutionSettings(Entity prefabEntity, EntityManager entityManager)
{
    if (entityManager.HasComponent<PollutionParameterData>(prefabEntity))
    {
        var data = entityManager.GetComponentData<PollutionParameterData>(prefabEntity);
        Debug.Log($"GroundMultiplier: {data.m_GroundMultiplier}, AirRadius: {data.m_AirRadius}");
    }
}

Additional notes: - NotificationIconPrefab fields are converted to entity IDs; ensure referenced notification prefabs exist in the prefab registry so GetEntity(...) returns a valid entity. - Tweak multipliers/radii to balance pollution spread and gameplay effects. The m_GroundPollutionLandValueDivisor controls how strongly ground pollution reduces land value (pollution / divisor). - Because this is a PrefabBase-derived asset, modifications are usually done in the Unity editor on the prefab asset rather than at runtime.