Game.Events.InDanger
Assembly: Assembly-CSharp
Namespace: Game.Events
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Component used to mark an entity as being "in danger" (an active emergency/event). Holds a reference to the event entity, an optional evacuation request entity, flags describing the danger, and an end-frame used to expire the danger state. Implements ISerializable so the component is persisted in saves; note that the end-frame field is only read from older/newer saves when the save version meets the Version.dangerTimeout threshold.
Fields
-
public Entity m_Event
Holds the Entity that represents the underlying event causing the danger (the event instance). -
public Entity m_EvacuationRequest
Optional Entity referencing an evacuation request created for this danger (may be Entity.Null if none). -
public DangerFlags m_Flags
Flags describing details of the danger (stored/serialized as a uint). The DangerFlags enum defines specific behavior/attributes for the danger. -
public uint m_EndFrame
Frame index at which this danger should be considered expired. Only read during deserialization when the save version is at or above Version.dangerTimeout.
Properties
This type does not expose any properties.
Constructors
public InDanger(Entity _event, Entity evacuationRequest, DangerFlags flags, uint endFrame)
Constructs a new InDanger component initializing all fields: event, evacuation request, flags and end-frame timeout.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the component fields in order: m_Event, m_EvacuationRequest, m_Flags (written as uint), then m_EndFrame. Used by the engine's save system. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes component data. Reads m_Event and m_EvacuationRequest, reads flags as a uint and casts to DangerFlags, and conditionally reads m_EndFrame only when reader.context.version >= Version.dangerTimeout. Uses ref locals to write directly into struct fields.
Usage Example
// Create and add an InDanger component to an entity (Unity DOTS / Cities: Skylines 2 style)
Entity eventEntity = /* the event entity */;
Entity evacuationRequest = Entity.Null; // or some evacuation request entity
DangerFlags flags = DangerFlags.Evacuate; // example flag; depends on available enum values
uint lifetimeFrames = 6000;
uint endFrame = SimulationManager.instance.m_currentFrame + lifetimeFrames;
var inDanger = new InDanger(eventEntity, evacuationRequest, flags, endFrame);
// Using an EntityManager to attach the component to a city object entity:
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(targetEntity, inDanger);
// Note: Serialization/deserialization is handled by the game's save system via ISerializable.