Class LightSource
Vehicle light source, either a Unity Light component or an emissive mesh material. Used for headlights, brake lights, turn signals, and other vehicle illumination.
Namespace: NWH.VehiclePhysics2.Effects
Assembly: NWH.VehiclePhysics2.dll
Syntax
[Serializable]
public class LightSource
Remarks
Light mode lights the scene through a Unity Light, which is what headlights need. Mesh mode only drives material emission, cheaper and enough for brake lights, indicators and markers. Mesh sources register their color on the renderer slot they share, so a lens driven by several groups (brake over tail) shows the brightest active request rather than whichever group wrote last. TurnOn/TurnOff are no-ops unless the logical isOn state actually changes; only Reconcile(bool) re-applies against the physical state.
Fields
emissionColor
HDR emission color of the emissive material. Mesh mode only - written to the material's emission color and the renderer's property block override. Light mode ignores this field; it uses the Light component's own color and only toggles Light.enabled.
Declaration
[ColorUsage(true, true)]
[Tooltip("The color of the emitted light.")]
public Color emissionColor
Field Value
| Type | Description |
|---|---|
| Color |
isOn
Gets whether the light source is currently turned on. Updated by TurnOn() and TurnOff() methods.
Declaration
[NonSerialized]
public bool isOn
Field Value
| Type | Description |
|---|---|
| bool |
light
Unity Light component (point, spot or directional) used only when type is Light.
Declaration
[Tooltip("Light (point/spot/directional/etc.) representing the vehicle light. Will only be used if light type is set to\r\nLight.")]
public Light light
Field Value
| Type | Description |
|---|---|
| Light |
meshRenderer
MeshRenderer whose material emission is toggled. Used only when type is Mesh, and the material must support emission (Standard shader or HDRP Lit).
Declaration
[Tooltip("Mesh renderer using standard shader. Emission on the material will be turned on or off depending on light state.")]
public MeshRenderer meshRenderer
Field Value
| Type | Description |
|---|---|
| MeshRenderer |
onLightTurnedOff
Called when the light is turned off.
Declaration
[Tooltip("Called when the light is turned off.")]
public UnityEvent onLightTurnedOff
Field Value
| Type | Description |
|---|---|
| UnityEvent |
onLightTurnedOn
Called when the light is turned on.
Declaration
[Tooltip("Called when the light is turned on.")]
public UnityEvent onLightTurnedOn
Field Value
| Type | Description |
|---|---|
| UnityEvent |
rendererMaterialIndex
Material array index to modify when the MeshRenderer has multiple materials. Use 0 for single-material meshes. Only relevant when type is set to Mesh.
Declaration
[Tooltip("If your mesh has more than one material, set this number to the index of the required material.")]
public int rendererMaterialIndex
Field Value
| Type | Description |
|---|---|
| int |
type
Type of the light.
Declaration
[Tooltip("Type of the light.")]
public LightSource.LightType type
Field Value
| Type | Description |
|---|---|
| LightSource.LightType |
Properties
IsOn
Pre-14.0 name of isOn.
Declaration
[Obsolete("Renamed to isOn.")]
public bool IsOn { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
Reconcile(bool)
Applies a logical state to the backing Light or material without publishing a transition event. Used when a manager is enabled so authored component/material state cannot disagree with isOn.
Declaration
public void Reconcile(bool turnOn)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | turnOn |
ReleaseMaterialInstance()
Restores the renderer's original shared material and destroys this source's runtime material reference. The shared instance is released only after every LightSource using the same renderer slot lets it go.
Declaration
public void ReleaseMaterialInstance()
TurnOff()
Turns off the light source by disabling the Light component or removing material emission. Invokes onLightTurnedOff event. Has no effect if already off.
Declaration
public virtual void TurnOff()
TurnOn()
Turns on the light source by enabling the Light component or applying material emission. Invokes onLightTurnedOn event. Has no effect if already on.
Declaration
public virtual void TurnOn()