Skip to content

Game.Prefabs.Modes.PollutionGlobalMode

Assembly:
Assembly-CSharp

Namespace:
Game.Prefabs.Modes

Type:
class

Base:
EntityQueryModePrefab

Summary:
A mode prefab that applies global multipliers to building pollution values (ground, air and noise) for matching entities using Unity's ECS jobs. The mode excludes zone (spawnable) buildings and targets entities that have PollutionData and are either BuildingData or BuildingExtensionData. It schedules a Burst-compiled IJobChunk (ModeJob) to multiply the PollutionData fields in parallel and provides a RestoreDefaultData implementation to restore values from prefab data.


Fields

  • public float m_GroundPollutionMultiplier
    Multiplier applied to PollutionData.m_GroundPollution when this mode is applied. Typical values <1 reduce ground pollution, >1 increase it.

  • public float m_AirPollutionMultiplier
    Multiplier applied to PollutionData.m_AirPollution when this mode is applied.

  • public float m_NoisePollutionMultiplier
    Multiplier applied to PollutionData.m_NoisePollution when this mode is applied.

(Internal) Nested type: - private struct ModeJob : IJobChunk (Burst compiled)
Job that iterates chunks of entities, reads/writes PollutionData and multiplies the three pollution fields by the configured multipliers. Uses ComponentTypeHandle to access component arrays and writes back the modified values.

Properties

This class does not declare any C# properties. It uses public fields for configuration and ECS job handles/types within ApplyModeData.

Constructors

  • public PollutionGlobalMode()
    Default constructor (no custom initialization in the source). Instances are typically created/managed by the prefab/system that owns mode prefabs.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns the EntityQueryDesc used to select entities affected by the mode:
  • All: PollutionData (read-only in the query definition)
  • Any: BuildingData or BuildingExtensionData
  • None: SpawnableBuildingData (excludes zone/spawnable buildings) This ensures only appropriate building entities are modified.

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Records a change on the entity's PollutionData to allow the prefab/mode system to track that the component was touched (it calls GetComponentData(entity) - retrieving the component registers it with the recording system).

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Creates and schedules the Burst-compiled ModeJob in parallel over the requestedQuery. The job is constructed with the multipliers and a non-readonly ComponentTypeHandle obtained from the provided EntityManager. Returns the combined JobHandle.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    For each entity provided, attempts to find the original prefab Pollution component and restores the PollutionData fields (m_GroundPollution, m_AirPollution, m_NoisePollution) to their prefab-default values. Logs a warning via ComponentBase.baseLog if the prefab data is not found.

  • (ModeJob) public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Job execution: obtains native array of PollutionData for the chunk and multiplies each entry's three pollution fields by the configured multipliers, then writes the entry back to the array.

  • (ModeJob) void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Explicit interface implementation forwarding to the public Execute method.

Usage Example

// Example: configure a PollutionGlobalMode instance (typically done in prefab authoring)
var mode = new PollutionGlobalMode();
mode.m_GroundPollutionMultiplier = 0.5f; // cut ground pollution in half
mode.m_AirPollutionMultiplier = 0.8f;    // reduce air pollution by 20%
mode.m_NoisePollutionMultiplier = 1.0f;  // leave noise unchanged

// When the mode system schedules ApplyModeData, ApplyModeData will build and schedule
// the Burst ModeJob which multiplies PollutionData components for matching entities.

Notes and tips: - The ModeJob is Burst-compiled and scheduled with ScheduleParallel to maximize throughput over many building entities. - The EntityQuery produced excludes SpawnableBuildingData so zone/spawnable buildings are not affected. - RestoreDefaultData relies on PrefabSystem and PrefabBase to fetch original Pollution values; ensure prefabs include the Pollution component for correct restoration. - Because ApplyModeData obtains a non-readonly ComponentTypeHandle, it writes back modified component data directly in the job. Ensure other concurrent systems respect this scheduling.