Game.Events.Flooded
Assembly: Assembly-CSharp
Namespace: Game.Events
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a flood event component used with Unity's ECS in Cities: Skylines 2. Stores a reference to an event entity (m_Event) and the flood depth (m_Depth). Implements Colossal.Serialization.Entities.ISerializable to support save/load, and IQueryTypeParameter so it can be used directly in ECS queries. This is a simple, blittable data container intended to be attached to entities to mark them as having a flood-related event and convey depth information to systems that handle flooding logic.
Fields
-
public Unity.Entities.Entity m_Event
Holds the Entity that represents the flood event (e.g., an event entity created elsewhere). Use this to identify or reference the originating event entity when systems process the flood. -
public System.Single m_Depth
Floating-point depth value describing how deep the flooding is at this entity. Systems can use this to determine effects, damage, or visuals based on severity.
Properties
- None.
This struct exposes data via public fields; there are no C# properties.
Constructors
public Flooded(Unity.Entities.Entity _event, float depth)
Constructs a Flooded instance by assigning the event entity and the depth value. Typical usage when adding the component to an entity.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component fields in order: first the Entity (m_Event), then the float depth (m_Depth). This is used by the game's/custom serializer to write component state to disk or network. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes the component fields in the same order as they were written: reads into m_Event then into m_Depth. Note the method reads directly into the struct's fields (using ref) so it restores the component state in-place.
Usage Example
// Add the Flooded component to an entity with a given eventEntity and depth:
Entity floodEventEntity = /* obtain or create the event entity */;
float depth = 2.5f;
var flooded = new Game.Events.Flooded(floodEventEntity, depth);
entityManager.AddComponentData(targetEntity, flooded);
// Example of a system (pseudo) that queries flooded components:
Entities.ForEach((Entity e, ref Game.Events.Flooded floodedComp) =>
{
// Access floodedComp.m_Event and floodedComp.m_Depth
// React to flooding: apply damage, spawn visuals, clear flood when handled, etc.
});
{{ Implementation notes: - The struct is blittable (Entity + float) and suitable for use as IComponentData in Unity's ECS. - Serialization relies on Colossal.Serialization.Entities primitives (IWriter/IReader). Ensure writer/reader implementations used by the game are available when persisting or loading. - Because the fields are public, systems can read and mutate them directly; consider immutability patterns if needed for your use-case. }}