Skip to content

Game.Prefabs.WaterLevelChangeComponent

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
WaterLevelChangeComponent is a prefab component used by event prefabs to configure water-level-related events (floods, rain-controlled water changes, tidal changes, etc.) in Cities: Skylines 2. It exposes editable parameters (targeting, change type, delays and behavioural flags) that are converted into ECS component data (WaterLevelChangeData and, optionally, FloodData) when the prefab is instantiated. The component also declares required archetype component types used by the entity system when creating the runtime entity.


Fields

  • public WaterLevelTargetType m_TargetType
    Determines the target scope for the water level change (how/where the water level change is applied). This value is transferred into WaterLevelChangeData.m_TargetType in Initialize.

  • public WaterLevelChangeType m_ChangeType
    Specifies the kind of water-level change (for example, a direct rise/fall, or a rain-controlled flood). When set to RainControlled, the component requests Flood-related component types be added to the prefab/archetype.

  • public float m_EscalationDelay = 1f
    Delay (in seconds) before the water level change escalates. Copied into WaterLevelChangeData.m_EscalationDelay during Initialize.

  • public bool m_Evacuate
    If true, the resulting WaterLevelChangeData will include DangerFlags.Evacuate, causing cims to consider evacuation behaviour during the event.

  • public bool m_StayIndoors
    If true, the resulting WaterLevelChangeData will include DangerFlags.StayIndoors, encouraging cims to remain sheltered during the event.

  • public float m_DangerLevel = 1f
    A 0..1 value (decorated with Range and Tooltip) indicating how dangerous the disaster is for cims. This influences civ behaviour (how likely they are to leave shelter) and is written to WaterLevelChangeData.m_DangerLevel.

Properties

  • None (this component exposes its configuration via public fields rather than properties).

Constructors

  • public WaterLevelChangeComponent()
    Implicit default constructor. Initialization of runtime ECS data is handled in Initialize rather than in the ctor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the ECS component types required on the prefab entity:
  • Always adds ComponentType.ReadWrite().
  • If m_ChangeType == WaterLevelChangeType.RainControlled, also adds ComponentType.ReadWrite(). This method is called when the prefab's component list is built and ensures the prefab will contain the required component types for conversion.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds component types that should be present on instantiated entities (archetype):

  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
  • ComponentType.ReadWrite()
  • If m_ChangeType == WaterLevelChangeType.RainControlled, also adds ComponentType.ReadWrite() Use: ensures the runtime archetype contains the expected components for systems that process water events.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Populates the ECS component data on the created entity:

  • Creates a WaterLevelChangeData struct and sets:
    • m_TargetType <- m_TargetType
    • m_ChangeType <- m_ChangeType
    • m_EscalationDelay <- m_EscalationDelay
    • m_DangerLevel <- m_DangerLevel
    • m_DangerFlags set based on m_Evacuate and m_StayIndoors (combining flags; default 0)
  • Calls entityManager.SetComponentData(entity, componentData) If m_ChangeType requires Flood/FloodData, GetPrefabComponents/GetArchetypeComponents will have ensured the Flood data type is present; Flood-specific initialization, if required, would be handled elsewhere or by other components.

Notes and dependencies: - This component relies on several game-specific types: WaterLevelChangeData, WaterLevelChange, FloodData, Flood, Duration, DangerLevel, TargetElement, DangerFlags, WaterLevelTargetType, WaterLevelChangeType. - Behaviour when both m_Evacuate and m_StayIndoors are set results in DangerFlags combining both flags (bitwise).

Usage Example

// Example: a prefab component is configured in the editor (inspector):
// - m_TargetType = WaterLevelTargetType.Area
// - m_ChangeType = WaterLevelChangeType.RainControlled
// - m_EscalationDelay = 2f
// - m_Evacuate = true
// - m_StayIndoors = false
// - m_DangerLevel = 0.8f
//
// At runtime, when the prefab is instantiated, the game calls:
protected override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);
    // The implementation in WaterLevelChangeComponent builds and writes
    // a WaterLevelChangeData instance into the entity; this drives systems
    // that perform the actual water-level/flood logic.
}