Class LightsManager
Manages all vehicle lights including headlights, brake lights, turn signals, and auxiliary lighting.
Inherited Members
Namespace: NWH.VehiclePhysics2.Effects
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class LightsManager : Effect
Remarks
LightsManager automatically controls vehicle lights based on driving inputs and vehicle state. Brake lights activate when braking, reverse lights when in reverse gear, and beam lights respond to input toggles.
Light hierarchy and dependencies: - Tail lights automatically turn on when low beam lights are enabled - High beam lights require low beam lights to be on (high beam enables both) - Brake lights take priority over tail lights (share same physical lights with higher intensity) - Blinkers can operate independently or as hazard lights (both sides synchronized)
Blinker behavior: Blinkers flash at 2Hz (twice per second). Left and right blinkers are mutually exclusive - activating one side automatically deactivates the other. Hazard lights override individual blinkers and flash both sides synchronously. The LeftBlinkerState and RightBlinkerState properties provide the current on/off state for each frame based on elapsed time.
Multiplayer support: The GetIntState() and SetStateFromInt() methods serialize all light states into a single integer for efficient network synchronization. Each bit represents one light type (8 light types total), allowing the entire lighting state to be transmitted with minimal bandwidth.
Fields
brakeLights
Rear brake lights that illuminate when braking is active. Typically red and brighter than tail lights. Often share the same physical light housing as tail lights but with higher intensity when brakes are applied.
Declaration
[FormerlySerializedAs("stopLights")]
[Tooltip("Rear lights that will light up when the brake is pressed. Always red.")]
public VehicleLight brakeLights
Field Value
| Type | Description |
|---|---|
| VehicleLight |
extraLights
Extra lights for special purposes such as fog lights, beacons, light bars, or decorative lighting. Toggled via input and does not interact with other light systems.
Declaration
[Tooltip("Can be used for any type of special lights, e.g., beacons.")]
public VehicleLight extraLights
Field Value
| Type | Description |
|---|---|
| VehicleLight |
highBeamLights
High beam (full beam) headlights for maximum forward illumination. Automatically enables low beam and tail lights when turned on. Typically used on unlit roads without oncoming traffic. Requires low beam to be on first.
Declaration
[FormerlySerializedAs("fullBeams")]
[Tooltip("High (full) beam lights.")]
public VehicleLight highBeamLights
Field Value
| Type | Description |
|---|---|
| VehicleLight |
leftBlinkers
Left turn signal indicators (blinkers) on the left side of the vehicle. Flash at 2Hz when activated. Mutually exclusive with right blinkers - activating left turns off right. Can be overridden by hazard lights.
Declaration
[Tooltip("Blinkers on the left side of the vehicle.")]
public VehicleLight leftBlinkers
Field Value
| Type | Description |
|---|---|
| VehicleLight |
lowBeamLights
Low beam (dipped beam) headlights for normal night driving. Automatically enables tail lights when turned on. These are the primary forward-facing lights used in urban environments and when other vehicles are present.
Declaration
[FormerlySerializedAs("headLights")]
[Tooltip("Low-beam lights.")]
public VehicleLight lowBeamLights
Field Value
| Type | Description |
|---|---|
| VehicleLight |
reverseLights
Reverse lights that illuminate when the vehicle is in reverse gear. Typically white, located at the rear to provide illumination behind the vehicle and warn others that the vehicle is backing up. Automatically controlled by transmission gear state.
Declaration
[Tooltip("Rear Lights that will light up when the vehicle is in reverse gear(s). Usually white.")]
public VehicleLight reverseLights
Field Value
| Type | Description |
|---|---|
| VehicleLight |
rightBlinkers
Right turn signal indicators (blinkers) on the right side of the vehicle. Flash at 2Hz when activated. Mutually exclusive with left blinkers - activating right turns off left. Can be overridden by hazard lights.
Declaration
[Tooltip("Blinkers on the right side of the vehicle.")]
public VehicleLight rightBlinkers
Field Value
| Type | Description |
|---|---|
| VehicleLight |
tailLights
Rear tail lights that illuminate when low beam or high beam headlights are on. Always red, lower intensity than brake lights. Used to make the vehicle visible from behind at night. Automatically managed by the beam light states.
Declaration
[FormerlySerializedAs("rearLights")]
[Tooltip("Rear Lights that will light up when headlights are on. Always red.")]
public VehicleLight tailLights
Field Value
| Type | Description |
|---|---|
| VehicleLight |
Properties
LeftBlinkerState
Current on/off state of the left blinker based on 2Hz flashing cycle. True when the light should be visible, false during the off phase of the blink cycle.
Declaration
public bool LeftBlinkerState { get; }
Property Value
| Type | Description |
|---|---|
| bool |
RightBlinkerState
Current on/off state of the right blinker based on 2Hz flashing cycle. True when the light should be visible, false during the off phase of the blink cycle.
Declaration
public bool RightBlinkerState { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
GetIntState()
Serializes all light states into a single integer with each bit representing one light type. Used for efficient network synchronization in multiplayer scenarios. The 8 light types are packed into bits 0-7 of the integer (brake, tail, reverse, low beam, high beam, left blinker, right blinker, extra).
Declaration
public int GetIntState()
Returns
| Type | Description |
|---|---|
| int | Integer with bit flags representing the on/off state of each light type. |
SetStateFromInt(int)
Deserializes light states from a single integer where each bit represents one light type. Used to apply received network state in multiplayer scenarios. Should be called with values obtained from GetIntState() on another instance.
Declaration
public void SetStateFromInt(int intState)
Parameters
| Type | Name | Description |
|---|---|---|
| int | intState | Integer with bit flags representing the desired on/off state of each light type. |
TurnOffAllLights()
Turns off all lights and emission on all meshes.
Declaration
public void TurnOffAllLights()
VC_Disable(bool)
Disables the component and stops updates. Override to add component-specific disable logic.
Declaration
public override bool VC_Disable(bool calledByParent)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | calledByParent | True if called by parent component or LOD system |
Returns
| Type | Description |
|---|---|
| bool | True if successfully disabled, false otherwise |
Overrides
Remarks
Component must be initialized before it can be disabled. Tracks whether disable was called by parent to manage LOD system interaction.
VC_Update(float)
Frame-rate dependent update called every frame. Override for visual updates and input handling.
Declaration
public override void VC_Update(float DeltaTime)
Parameters
| Type | Name | Description |
|---|---|---|
| float | DeltaTime | Time elapsed since last Update in seconds |
Overrides
Remarks
Only called when the component is active (initialized and enabled). Use for visual effects, UI updates, and other frame-dependent operations. Avoid physics calculations here - use VC_FixedUpdate instead.