Skip to content

Game.Prefabs.Modes.NetPollutionGlobalMode

Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes

Type: class NetPollutionGlobalMode

Base: EntityQueryModePrefab

Summary:
NetPollutionGlobalMode is a mode prefab used to apply global multipliers to net pollution factors for all entities that contain NetPollutionData. It schedules a Burst-compiled IJobChunk (ModeJob) that multiplies the existing noise and air pollution factors (stored in NetPollutionData.m_Factors as a float2) by the configured m_NoisePollutionFactorMultiplier and m_AirPollutionFactorMultiplier. The class also provides logic to restore the original prefab values for those entities via RestoreDefaultData.


Fields

  • public float m_NoisePollutionFactorMultiplier
    Multiplier applied to the noise pollution factor (m_Factors.x) when the mode is applied. Default value is defined in the prefab (editable in inspector).

  • public float m_AirPollutionFactorMultiplier
    Multiplier applied to the air pollution factor (m_Factors.y) when the mode is applied. Default value is defined in the prefab (editable in inspector).

(Nested ModeJob fields — internal to the job)

  • public float m_NoisePollutionFactorMultiplier
  • public float m_AirPollutionFactorMultiplier
  • public ComponentTypeHandle<NetPollutionData> m_NetPollutionType
    These are the data members used by the Burst-compiled ModeJob to perform parallel updates to NetPollutionData.

Properties

  • None (no public properties declared on the class)

Constructors

  • public NetPollutionGlobalMode()
    No explicit constructor is defined in the source — the default parameterless constructor is used. Typical usage is via prefab/component instantiation in the Unity editor or via prefab system.

Methods

  • public override EntityQueryDesc GetEntityQueryDesc()
    Returns an EntityQueryDesc that selects entities which contain NetPollutionData. Specifically sets All = new ComponentType[] { ComponentType.ReadOnly() }. This query is used to determine which entities the mode job will operate on.

  • protected override void RecordChanges(EntityManager entityManager, Entity entity)
    Calls entityManager.GetComponentData<NetPollutionData>(entity). This appears to read/record the current NetPollutionData for change tracking (used by the mode/prefab system to know what was modified), even though the value is not stored here.

  • public override JobHandle ApplyModeData(EntityManager entityManager, EntityQuery requestedQuery, JobHandle deps)
    Schedules and returns a JobHandle for the Burst-compiled ModeJob using JobChunkExtensions.ScheduleParallel. The job receives the configured multipliers and a writable ComponentTypeHandle for NetPollutionData (isReadOnly: false). The scheduled job will multiply existing m_Factors values on the matched entities' NetPollutionData components.

  • public override void RestoreDefaultData(EntityManager entityManager, ref NativeArray<Entity> entities, PrefabSystem prefabSystem)
    Iterates over the provided entities and attempts to look up the original PrefabBase for each entity via the prefabSystem. If the prefab contains a NetPollution component (Prefab-side component), it reads the prefab's original m_NoisePollutionFactor and m_AirPollutionFactor values and writes them back into the entity's NetPollutionData.m_Factors. If the prefab data is not available, the code logs a warning and skips that entity.

(Nested ModeJob methods)

  • ModeJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Implements the IJobChunk logic. Retrieves a NativeArray for the chunk and multiplies each element's m_Factors by the configured multipliers: value.m_Factors = new float2(value.m_Factors.x * m_NoisePollutionFactorMultiplier, value.m_Factors.y * m_AirPollutionFactorMultiplier);

  • ModeJob also implements the explicit interface method void IJobChunk.Execute(...) which forwards to the strongly-typed Execute method above. The job is Burst-compiled (BurstCompile attribute) for performance.

Remarks / Implementation notes: - The job uses ComponentTypeHandle with isReadOnly: false because it writes back modified component data. - The ModeJob is scheduled with ScheduleParallel allowing parallel modification across chunks — ensure the EntityQuery used matches GetEntityQueryDesc or equivalent to avoid mismatches. - RestoreDefaultData depends on PrefabSystem.TryGetPrefab and expects a Prefab-side NetPollution component (PrefabBase.TryGetExactly), which provides the original factor values to restore.

Usage Example

// Example: using the prefab/component in code
// Typically this component is added to a Mode prefab in the Unity editor.
// But you can also configure it at runtime:

var mode = entityPrefabSystem.InstantiateMode<NetPollutionGlobalMode>(/* ... */);
mode.m_NoisePollutionFactorMultiplier = 0.8f; // reduce noise pollution to 80%
mode.m_AirPollutionFactorMultiplier = 1.2f;   // increase air pollution to 120%

// When the mode system applies this mode it will call ApplyModeData,
// scheduling the ModeJob which multiplies NetPollutionData.m_Factors accordingly.