Game.Prefabs.Modes.PollutionMode
Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Modes
Type: class
Base: LocalModePrefab
Summary:
A prefab mode component that applies pollution multipliers to target prefabs. Each entry in m_ModeDatas references a Prefab (PrefabBase) that must have a Pollution component; the mode multiplies the prefab's runtime PollutionData (ECS component) values for ground, air and noise pollution by the configured multipliers. When restoring defaults the original values from the Pollution component on the prefab are copied back into the ECS PollutionData.
Fields
public ModeData[] m_ModeDatas
An array of ModeData entries. Each entry pairs a PrefabBase (target prefab that should contain a Pollution component) with multipliers for ground, air and noise pollution. The array is iterated by the mode to find targets and apply or restore pollution values.
Nested type ModeData and its fields:
- public PrefabBase m_Prefab
The target prefab. Expected to contain a Pollution component. If missing, the mode logs a critical error and skips the entry.
- [Min(0f)] public float m_GroundPollutionMultiplier
Multiplier applied to the prefab's ground pollution value in PollutionData during ApplyModeData. Must be >= 0.
- [Min(0f)] public float m_AirPollutionMultiplier
Multiplier applied to the prefab's air pollution value in PollutionData during ApplyModeData. Must be >= 0.
- [Min(0f)] public float m_NoisePollutionMultiplier
Multiplier applied to the prefab's noise pollution value in PollutionData during ApplyModeData. Must be >= 0.
Properties
This class declares no public properties.
Constructors
public PollutionMode()
Default constructor (implicit). The component is intended to be used as a prefab component configured in prefabs or via editor scripts.
Methods
-
public override void RecordChanges(EntityManager entityManager, PrefabSystem prefabSystem)
Records or accesses the PollutionData component for each target prefab's Entity so that the prefab system knows this component will be changed. For each ModeData entry it resolves the target Prefab's Pollution component and calls entityManager.GetComponentData(entity) to touch the component. If the Pollution component is missing on the target prefab, a critical log message is emitted and that entry is skipped. -
public override void ApplyModeData(EntityManager entityManager, PrefabSystem prefabSystem)
Applies the configured multipliers to each target prefab's PollutionData ECS component. For each ModeData entry: - Resolve the target prefab's Pollution component; if missing, log critically and skip.
- Get the Entity for the target prefab via prefabSystem.GetEntity(component.prefab).
- Read the PollutionData component, multiply m_GroundPollution, m_AirPollution and m_NoisePollution by the corresponding multipliers from ModeData.
-
Write the modified PollutionData back to the entity with entityManager.SetComponentData.
-
public override void RestoreDefaultData(EntityManager entityManager, PrefabSystem prefabSystem)
Restores original pollution values from the target prefab's Pollution MonoBehaviour into the PollutionData ECS component. For each ModeData entry: - Resolve the target prefab's Pollution component; if missing, log critically and skip.
- Get the Entity for the target prefab.
- Read PollutionData, set its m_GroundPollution/m_AirPollution/m_NoisePollution fields to the values from the Pollution component stored on the prefab (component.m_GroundPollution, etc.).
- Write the restored PollutionData back to the entity.
Notes: - The component relies on the target prefab having a Pollution MonoBehaviour/component. Missing targets are logged via ComponentBase.baseLog.Critical and skipped. - The mode operates on ECS component PollutionData; ensure the prefab system and ECS entity exist for the prefab before calling methods (this component assumes prefabSystem.GetEntity returns a valid Entity).
Usage Example
// Example: configure a PollutionMode instance (e.g. from an editor script or another prefab component)
var mode = new PollutionMode();
mode.m_ModeDatas = new PollutionMode.ModeData[]
{
new PollutionMode.ModeData
{
m_Prefab = somePrefabBase, // prefab that has a Pollution component
m_GroundPollutionMultiplier = 0.5f, // halve ground pollution
m_AirPollutionMultiplier = 1.0f, // keep air pollution
m_NoisePollutionMultiplier = 0.8f // reduce noise
}
};
// At runtime the prefab system will call RecordChanges/ApplyModeData/RestoreDefaultData
// as appropriate. You can also invoke them manually if you have an EntityManager and PrefabSystem:
mode.RecordChanges(entityManager, prefabSystem);
mode.ApplyModeData(entityManager, prefabSystem);
// ... later to revert:
mode.RestoreDefaultData(entityManager, prefabSystem);