Version: 2021.3

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. See Also: GraphicsSettings.lightsUseLinearIntensity, GraphicsSettings.useColorTemperature.
commandBufferCount此光源上设置的命令缓冲区数(只读)。
cookie光投射的阴影的剪影纹理。
cookieSize方向光剪影的大小。
cullingMask这用于有选择性地对场景中的特定对象进行照明。
flare要用于此光的 flare asset。
innerSpotAngle光源的聚光灯内锥角的角度(以度为单位)。
intensity光的强度乘以光颜色。
layerShadowCullDistancesPer-light, per-layer shadow culling distances. Directional lights only.
lightmapBakeType此属性描述可以对光贡献的哪个部分进行烘培(仅限编辑器)。
lightShadowCasterMode允许您根据光源来覆盖全局阴影遮罩模式。该属性只能用于能够处理每个光源阴影遮罩模式的渲染管线。与旧版渲染器不兼容。
range光照范围。
renderingLayerMask确定光源影响的渲染 LayerMask。
renderMode如何渲染光。
shadowAngle控制由方向光应用于阴影投射边缘的人工柔化量。
shadowBias阴影贴图恒定偏差。
shadowCustomResolution阴影贴图的自定义分辨率。
shadowMatrixOverride用于在阴影剔除期间覆盖常规光源矩阵的投影矩阵。
shadowNearPlane要用于阴影视锥体的近平面值。
shadowNormalBias阴影贴图基于法线的偏差。
shadowRadius控制由点光源或聚光灯应用于阴影投射边缘的人工柔化量。
shadowResolution阴影贴图的分辨率。
shadows此光如何投射阴影。
shadowStrength光阴影的强度。
shape该属性描述聚光灯的形状。仅可编程渲染管线使用该属性;内置渲染器支持该属性。
spotAngle光的聚光灯锥体的角度(以度为单位)。
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.
GetComponentReturns the component of type if the GameObject has one attached.
GetComponentInChildrenReturns the Component of type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the Component of type in the GameObject or any of its parents.
GetComponents返回 GameObject 中类型为 type 的所有组件。
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children using depth first search. Works recursively.
GetComponentsInParent返回 GameObject 或其任何父项中类型为 type 的所有组件。
SendMessage调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。
SendMessageUpwards调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。
TryGetComponent获取指定类型的组件(如果存在)。
GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindObjectOfType返回第一个类型为 type 的已加载的激活对象。
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

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