Skip to content

Game.City.DangerLevel

Assembly: Assembly-CSharp
Namespace: Game.City

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents a simple ECS component that stores a single floating-point "danger" value for an entity. The struct is serializable via the Colossal.Serialization system (implements ISerializable) and can be used directly with Unity's ECS (IComponentData). Useful for storing hazard intensity, threat levels, or similar per-entity metrics that need to be persisted or queried.


Fields

  • public float m_DangerLevel Stores the danger value as a single-precision float. Default for a newly constructed struct is 0.0f. The semantic range is context-dependent (for example 0.0–1.0 or any positive/negative scale as defined by the mod/game logic).

Properties

  • None
    This type does not declare any properties. It exposes the raw field m_DangerLevel directly.

Constructors

  • public DangerLevel()
    The struct uses the implicit parameterless constructor provided by C#. No custom constructors are defined in the source. You can initialize the value with an object initializer, e.g. new DangerLevel { m_DangerLevel = 0.5f }.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the single float field m_DangerLevel to the provided writer. This is used by the Colossal.Serialization pipeline to persist the component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads a single float from the provided reader into m_DangerLevel. Used when restoring component state from serialized data.

Usage Example

// Create and add the component to an entity (using Unity.Entities API)
var danger = new Game.City.DangerLevel { m_DangerLevel = 0.85f };
entityManager.AddComponentData(entity, danger);

// Read the component back
var current = entityManager.GetComponentData<Game.City.DangerLevel>(entity);
Debug.Log($"Danger level: {current.m_DangerLevel}");

// Serialization example (pseudo-code; requires a concrete IWriter/IReader)
// Serialize
danger.Serialize(writer);

// Deserialize
var loaded = new Game.City.DangerLevel();
loaded.Deserialize(reader);
Debug.Log($"Loaded danger level: {loaded.m_DangerLevel}");