Game.Prefabs.TrafficLightObject
Assembly:
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
TrafficLightObject is a prefab component used to mark and configure traffic light prefabs (static objects or marker objects) in the game's ECS-based prefab pipeline. The class exposes boolean options for which traffic light directions/crossings are present, an allow-flipped toggle, and a reach offset (Bounds1). On archetype/prefab initialization it ensures the entity has the appropriate ECS component types (TrafficLight and TrafficLightData) and writes a TrafficLightData instance reflecting the configured flags and reach offset. The type is annotated with a ComponentMenu attribute so it is available under "Objects/" for StaticObjectPrefab and MarkerObjectPrefab.
Fields
-
public bool m_VehicleLeft
Indicates whether a vehicle-left traffic light is present on this prefab. When true, the TrafficLightData.m_Type will include TrafficLightType.VehicleLeft during LateInitialize. -
public bool m_VehicleRight
Indicates whether a vehicle-right traffic light is present. When true, the TrafficLightData.m_Type will include TrafficLightType.VehicleRight. -
public bool m_CrossingLeft
Indicates whether a pedestrian crossing (left) traffic light is present. When true, the TrafficLightData.m_Type will include TrafficLightType.CrossingLeft. -
public bool m_CrossingRight
Indicates whether a pedestrian crossing (right) traffic light is present. When true, the TrafficLightData.m_Type will include TrafficLightType.CrossingRight. -
public bool m_AllowFlipped
If true, the TrafficLightData.m_Type will include TrafficLightType.AllowFlipped, permitting mirrored/flipped placement behavior. -
public Bounds1 m_ReachOffset
A Bounds1 value that will be copied into TrafficLightData.m_ReachOffset. This defines the reach/offset area used by the traffic light logic.
Properties
- (none declared by this type)
All configuration is exposed via public fields; the class does not declare additional properties.
Constructors
public TrafficLightObject()
Implicit default constructor. No special construction logic is defined—initialization occurs during LateInitialize when the prefab is converted to an entity.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds ComponentType.ReadWrite() to the supplied components set so the entity prefab will include TrafficLightData as a component on created entities. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds ComponentType.ReadWrite() to the archetype components set, ensuring the created archetype includes the TrafficLight component. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called during prefab -> entity conversion. Creates a TrafficLightData instance, sets m_ReachOffset from this prefab's m_ReachOffset, and sets m_Type flags based on the boolean fields (m_VehicleLeft, m_VehicleRight, m_CrossingLeft, m_CrossingRight, m_AllowFlipped). Finally writes the component to the entity with entityManager.SetComponentData(entity, componentData).
Usage Example
// Example: configuring a prefab's TrafficLightObject in code or editor scripting
var prefab = /* obtain prefab asset that has TrafficLightObject */;
var tlObj = prefab.GetComponent<TrafficLightObject>();
tlObj.m_VehicleLeft = true;
tlObj.m_VehicleRight = true;
tlObj.m_CrossingLeft = false;
tlObj.m_CrossingRight = true;
tlObj.m_AllowFlipped = true;
tlObj.m_ReachOffset = new Bounds1(...);
// When the prefab is converted to an ECS entity, LateInitialize will be called and
// the entity will receive a TrafficLightData component populated with the above values.