Skip to content

Game.Objects.StreetLight

Assembly: Assembly-CSharp (typical Unity game assembly — adjust if this type is in a different mod/game assembly)
Namespace: Game.Objects

Type: struct

Base: System.ValueType

Summary:
StreetLight is a lightweight ECS component (IComponentData) representing the current state of a street light in the game's entity system. It implements ISerializable to allow compact binary serialization (the state is serialized as a single byte) and IQueryTypeParameter to be used in entity queries. The actual state values are defined by the StreetLightState enum (not included in this file) and may represent states such as Off, On, Faulty, etc. This component is intended to be attached to entities representing street light objects and used by systems that drive light behavior, rendering, or persistence.


Fields

  • public StreetLightState m_State
    Holds the current state of the street light. This field is serialized as a single byte by the component's Serialize method. The exact meaning of each enum value depends on the StreetLightState enum definition (e.g., Off, On, Dim, Faulty).

Properties

  • This type does not declare any properties.

Constructors

  • public StreetLight()
    The struct has the default, compiler-provided parameterless constructor. You can also create an instance with an object initializer, e.g.: new StreetLight { m_State = StreetLightState.Off };

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the current state to the provided writer as a single byte: writer.Write((byte)m_State). The generic writer must implement the IWriter interface expected by Colossal.Serialization.Entities.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads a byte from the provided reader and casts it back to StreetLightState: reader.Read(out byte value); m_State = (StreetLightState)value;. Note: there is no explicit validation of the byte value — if the serialized value does not correspond to a valid enum member, it will be assigned as the underlying byte value cast into the enum.

Usage Example

// Create / add the component to an entity (EntityManager example)
var lightComponent = new StreetLight { m_State = StreetLightState.On };
entityManager.AddComponentData(entity, lightComponent);

// Manual serialization example (pseudo-code — depends on your IWriter/IReader implementation)
IWriter writer = ...;
var light = new StreetLight { m_State = StreetLightState.Off };
light.Serialize(writer); // writes a single byte representing the state

// Manual deserialization
IReader reader = ...;
var loaded = new StreetLight();
loaded.Deserialize(reader); // reads a single byte and sets m_State

Notes: - The component is designed for use with Unity's ECS (IComponentData) and the game's serialization utilities (Colossal.Serialization.Entities). Ensure the IWriter/IReader implementations you use match the expected protocol. - Because serialization is done as a single byte, keep the StreetLightState enum values within the byte range (0–255).