Version: 2023.2

Light

class in UnityEngine

/

继承自:Behaviour

切换到手册

描述

light components 的脚本接口。

它用于对 Unity 光源进行全面控制。这些属性与 Inspector 中显示 的值完全匹配。

通常光源仅在 Editor 中创建,但是有时需要通过脚本创建光源:

using UnityEngine;

public class Example : MonoBehaviour { void Start() { // Make a game object GameObject lightGameObject = new GameObject("The Light");

// Add the light component Light lightComp = lightGameObject.AddComponent<Light>();

// Set color and position lightComp.color = Color.blue;

// Set the position (or any transform property) lightGameObject.transform.position = new Vector3(0, 5, 0); } }

变量

areaSize面光源的大小(仅限编辑器)。
bakingOutput此属性描述最后一个全局光照烘焙的输出。
bounceIntensity定义反弹光照强度的乘数。
boundingSphereOverride用于在剔除期间覆盖常规光源包围球体的包围球体。
color光的颜色。
colorTemperature The color temperature of the light. Correlated Color Temperature (abbreviated as CCT) is multiplied with the color filter when calculating the final color of a light source. The color temperature of the electromagnetic radiation emitted from an ideal black body is defined as its surface temperature in Kelvin. White is 6500K according to the D65 standard. A candle light is 1800K and a soft warm light bulb is 2700K. If you want to use colorTemperature, GraphicsSettings.lightsUseLinearIntensity and Light.useColorTemperature has to be enabled. Additional resources: GraphicsSettings.lightsUseLinearIntensity, GraphicsSettings.useColorTemperature.
commandBufferCount此光源上设置的命令缓冲区数(只读)。
cookie光投射的阴影的剪影纹理。
cookieSize方向光剪影的大小。
cullingMask这用于有选择性地对场景中的特定对象进行照明。
dilatedRange The Light.range property describes the range of each point on the light. However, area lights consist of several light-emitting points, and so the effective range is a bit larger, and depends on the size of the area light. This property returns this larger range. Use this property to find whether a given world-space point will be lit by the area light. If not an area light, then returns the same value as Light.range.
flare要用于此光的 flare asset。
innerSpotAngleThe angle of the spot light's inner cone in degrees.
intensity光的强度乘以光颜色。
layerShadowCullDistancesPer-light, per-layer shadow culling distances. Directional lights only.
lightmapBakeType此属性描述可以对光贡献的哪个部分进行烘培(仅限编辑器)。
lightShadowCasterMode允许您根据光源来覆盖全局阴影遮罩模式。该属性只能用于能够处理每个光源阴影遮罩模式的渲染管线。与旧版渲染器不兼容。
range The range of each point of the light. Since area lights have a light emitting surface instead of a single point, the cumulative range of the light is larger than this property. This larger range can be read from the Light.dilatedRange property. For non-area lights, Light.range and Light.dilatedRange return the same value.
renderingLayerMask确定光源影响的渲染 LayerMask。
renderMode如何渲染光。
shadowAngleControls the amount of artificial softening applied to the edges of shadows cast by directional lights (Editor only).
shadowBias阴影贴图恒定偏差。
shadowCustomResolution阴影贴图的自定义分辨率。
shadowMatrixOverrideMatrix that overrides the regular light projection matrix during shadow culling. Unity uses this matrix if you set Light.useShadowMatrixOverride to true.
shadowNearPlane要用于阴影视锥体的近平面值。
shadowNormalBias阴影贴图基于法线的偏差。
shadowRadiusControls the amount of artificial softening applied to the edges of shadows cast by the Point or Spot light (Editor only).
shadowResolution阴影贴图的分辨率。
shadows此光如何投射阴影。
shadowStrength光阴影的强度。
spotAngleThe angle of the spot light's cone in degrees.
type光源类型。
useBoundingSphereOverride将其设置为 true 可覆盖进行剔除的光源包围球体。
useColorTemperature设置为 true 可使用该色温。
useShadowMatrixOverride设置为 true 可启用在阴影期间进行剔除的自定义矩阵。
useViewFrustumForShadowCasterCullWhether to cull shadows for this Light when the Light is outside of the view frustum.

公共函数

AddCommandBuffer添加要在指定位置执行的命令缓冲区。
AddCommandBufferAsync向 GPU 的异步计算队列添加命令缓冲区,并在图形处理到达给定点时执行该命令缓冲区。
GetCommandBuffers获取要在指定位置执行的命令缓冲区。
RemoveAllCommandBuffers删除在此光源上设置的所有命令缓冲区。
RemoveCommandBuffer从指定位置的执行中删除一个命令缓冲区。
RemoveCommandBuffers从指定位置的执行中删除多个命令缓冲区。
Reset将所有光源参数恢复为默认值。
SetLightDirty将光源设置为“脏”可通知光照烘培后端更新其内部光源表示形式(仅限编辑器)。

继承的成员

变量

enabled启用的 Behaviour 可更新,禁用的 Behaviour 不可更新。
isActiveAndEnabledReports whether a GameObject and its associated Behaviour is active and enabled.
gameObject此组件附加到的游戏对象。始终将组件附加到游戏对象。
tag此游戏对象的标签。
transform附加到此 GameObject 的 Transform。
hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

BroadcastMessage调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentGets a reference to a component of type T on the same GameObject as the component specified.
GetComponentInChildrenGets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject.
GetComponentInParentGets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the same GameObject as the component specified.
GetComponentsInChildrenGets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject.
SendMessage调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。
SendMessageUpwards调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。
TryGetComponent获取指定类型的组件(如果存在)。
GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。