Game.Events.DangerLevel
Assembly: Assembly-CSharp (game)
Namespace: Game.Events
Type: struct
Base: System.ValueType
Implements: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary: A small ECS component that holds a single floating-point "danger level" value. It is blittable (single float), serializable via the game's Colossal.Serialization system, and can be used as a query parameter in Unity Entities queries. Typical usage is to attach this component to an entity to represent how dangerous something is (for events, AI, or other game logic).
Fields
public System.Single m_DangerLevel
This field stores the numeric danger level. The meaning and range are determined by game logic (the struct itself does not enforce any bounds). It is the only data carried by this component and is what gets read/written during serialization.
Properties
- This type has no properties.
Constructors
public DangerLevel(float dangerLevel)
Initializes the component with the provided dangerLevel value and assigns it to m_DangerLevel.
Methods
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads a single float value from the provided reader and stores it into m_DangerLevel. This is used by the game's serialization pipeline (Colossal.Serialization). -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the current m_DangerLevel value to the provided writer so the component can be persisted/streamed by the game's serialization pipeline.
Usage Example
// Create an entity and add the DangerLevel component
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = em.CreateEntity();
em.AddComponentData(entity, new Game.Events.DangerLevel(2.5f));
// Read the value from an entity
var current = em.GetComponentData<Game.Events.DangerLevel>(entity);
float danger = current.m_DangerLevel;
// Example: constructing the component directly
var dl = new Game.Events.DangerLevel(4.0f);
Additional notes: - Because this is a struct with a single float field, it's cheap to copy and safe to use as a component in DOTS/ECS contexts. - Serialization methods integrate with Colossal.Serialization; custom readers/writers supplied by the game's serialization system will call Serialize/Deserialize when saving/loading.