Skip to main content

Class TrafficSignalController

The traffic signal controller controls the runtime visual state of a traffic light by updating material shader keywords. This component is responsible for displaying the correct light color (Red, Yellow, Green), as well as enabling or disabling a flashing effect when required.

public class TrafficSignalController : MonoBehaviour, IDataLoggable

Inheritance​

Implements​

IDataLoggable

Remarks​

The controller modifies a material assigned to the traffic light mesh by enabling or disabling local shader keywords. Each keyword corresponds to a specific traffic signal state or flashing mode. Signal and flashing changes are timestamped and can be collected for runtime data logging.

Methods​

Collect()​

Captures a snapshot of this component's current state and returns it as a DataLog subclass.

The log contains timestamped messages of signal state and flashing changes.

public DataLog Collect()

Returns​

DataLog — A DataLog subclass populated with the component's current readings, or null if no data is available.

Remarks​

Return null when the component has no meaningful data to contribute (e.g., it is disabled or in an initialising state). The collector ignores null returns and excludes them from the analysis output, so implementations never need to allocate a placeholder.

SetAmberSignal()​

Sets the traffic signal to yellow (amber).

public void SetAmberSignal()

SetFlashing(bool)​

Sets whether the traffic light should flash.

public void SetFlashing(bool value)

Parameters​

NameTypeDescription
valueboolWhether the light should flash (true) or remain steady (false).

Remarks​

This updates the traffic light material by toggling the FlashingKeyword?text=local+shader+keyword. The flashing state change is also timestamped via IDataLoggable.

SetGreenSignal()​

Sets the traffic signal to green.

public void SetGreenSignal()

SetRedSignal()​

Sets the traffic signal to red.

public void SetRedSignal()

SetSignal(TrafficSignal)​

Sets the visual state of the traffic light to the specified signal.

public void SetSignal(TrafficSignal newSignal)

Parameters​

NameTypeDescription
newSignalTrafficSignalThe new signal to display (e.g., RED, GREEN).

Remarks​

This method enables the shader keyword corresponding to the given signal and disables all others using LocalKeywords. It also records the signal change with a timestamped message for runtime logging via IDataLoggable.

SetSignalOff()​

Disables all signal lights by setting the signal to Off.

public void SetSignalOff()
  • Remarks
  • Methods
    • Collect()
    • SetAmberSignal()
    • SetFlashing(bool)
    • SetGreenSignal()
    • SetRedSignal()
    • SetSignal(TrafficSignal)
    • SetSignalOff()