Game.Prefabs.NetPollution
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Provides per-net (road/rail/etc.) pollution multipliers used when converting prefab settings into ECS component data. This component exposes noise and air pollution factors (editable on the prefab) and ensures the corresponding NetPollutionData component is added to the entity. It also adds the Game.Net.Pollution component to node/edge archetypes when appropriate.
Fields
-
public float m_NoisePollutionFactor = 1f
Multiplier applied to noise pollution generated by the network prefab. Default is 1.0. Used to populate NetPollutionData.m_Factors.x in Initialize. -
public float m_AirPollutionFactor = 1f
Multiplier applied to air pollution generated by the network prefab. Default is 1.0. Used to populate NetPollutionData.m_Factors.y in Initialize.
Properties
- None
Constructors
public NetPollution()
Implicit default constructor. Field initializers set both pollution factors to 1.0.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime ECS component type required for this prefab: ComponentType.ReadWrite(). This ensures the NetPollutionData component exists on entities created from this prefab. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
If the prefab archetype includes a Node or Edge component (ComponentType.ReadWrite() or ComponentType.ReadWrite ()), this method adds ComponentType.ReadWrite () so that node/edge entities will also include the Pollution component used by the net pollution system. -
public override void Initialize(EntityManager entityManager, Entity entity)
Called when the prefab is materialized into an ECS entity. Creates a NetPollutionData instance, sets its m_Factors float2 with (m_NoisePollutionFactor, m_AirPollutionFactor) and writes it to the entity via entityManager.SetComponentData. Calls base.Initialize first.
Usage Example
// Typical behavior implemented by the component — when the prefab is instantiated
// the engine calls Initialize, which writes NetPollutionData with the configured factors.
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
NetPollutionData componentData = default(NetPollutionData);
componentData.m_Factors = new float2(m_NoisePollutionFactor, m_AirPollutionFactor);
entityManager.SetComponentData(entity, componentData);
}
// Example of adjusting factors on a prefab (e.g., in editor or another initializer)
var netPollution = somePrefab.GetComponent<Game.Prefabs.NetPollution>();
netPollution.m_NoisePollutionFactor = 0.75f;
netPollution.m_AirPollutionFactor = 1.25f;