Game.Objects.TrafficLight
Assembly: Assembly-CSharp
Namespace: Game.Objects
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents the traffic light component data attached to an entity in the game's ECS. Holds the current light state and two group mask fields used to group or categorize traffic lights (e.g., for coordinated signal groups). Implements ISerializable to allow versioned save/load behavior and IQueryTypeParameter to be usable in entity queries.
Fields
-
public TrafficLightState m_State
Holds the current state of the traffic light (stored as a TrafficLightState enum). When serialized this value is written as a ushort. During deserialization the raw ushort is read first and then cast back into TrafficLightState. -
public ushort m_GroupMask0
First group mask (16 bits) used to mark group membership or flags for the traffic light. This field is serialized unconditionally by Serialize; Deserialize only reads this field when the read context's version is at least Version.trafficLightGroups (backwards compatibility). -
public ushort m_GroupMask1
Second group mask (16 bits), same usage and versioning behavior as m_GroupMask0.
Properties
- No public properties. (All data is exposed via public fields on the struct.)
Constructors
public TrafficLight()
Default parameterless struct constructor (implicit). Initialize fields directly when creating an instance, e.g.:
var tl = new TrafficLight {
m_State = TrafficLightState.Red,
m_GroupMask0 = 0,
m_GroupMask1 = 0
};
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component to the provided writer in the following order: state (as ushort), m_GroupMask0, m_GroupMask1. The method casts the TrafficLightState to ushort before writing. This Serialize implementation does not check versions (it writes the masks unconditionally), so serialized data will always include masks for the current code path. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data back from reader. It first reads a ushort into a temporary variable representing the state. It then checks reader.context.version and if that version is >= Version.trafficLightGroups it reads m_GroupMask0 and m_GroupMask1 into the struct fields. Finally it assigns the m_State field by casting the earlier-read ushort back into TrafficLightState. This ordering ensures compatibility with older save versions that lack group mask data.
Remarks: - The conditional read of group masks allows older saved versions (pre-trafficLightGroups) to be loaded without expecting those extra fields. - Because Serialize always writes the masks, saved data from a newer game/mod will include them; older readers will ignore them based on the version check.
Usage Example
// Create and add the component to an entity (using the ECS EntityManager)
var trafficLight = new TrafficLight {
m_State = TrafficLightState.Green,
m_GroupMask0 = 0x0001,
m_GroupMask1 = 0x0000
};
entityManager.AddComponentData(entity, trafficLight);
// During save, the game's IWriter will receive the following from Serialize:
// (ushort)TrafficLightState.Green, 0x0001, 0x0000
// During load, Deserialize will:
// - read the state ushort
// - if reader.context.version >= Version.trafficLightGroups, read the two masks
// - assign m_State from the read ushort