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 | 光的色温。 在计算光源的最终颜色时,会将相对色温(缩写为 CCT)乘以颜色过滤器。从理想黑体发出的电磁辐射的色温定义为其以开尔文为单位的表面温度。根据 D65 标准,白色光色温为 6500K。蜡烛光色温为 1800K。 如果要使用 lightsUseCCT,必须启用 lightsUseLinearIntensity 以确保物理上的正确输出。 另请参阅:GraphicsSettings.lightsUseLinearIntensity、GraphicsSettings.lightsUseCCT。 |
commandBufferCount | 此光源上设置的命令缓冲区数(只读)。 |
cookie | 光投射的阴影的剪影纹理。 |
cookieSize | 方向光剪影的大小。 |
cullingMask | 这用于有选择性地对场景中的特定对象进行照明。 |
flare | 要用于此光的 flare asset。 |
innerSpotAngle | 光源的聚光灯内锥角的角度(以度为单位)。 |
intensity | 光的强度乘以光颜色。 |
layerShadowCullDistances | 每光源、每层阴影剔除距离。 |
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 可启用在阴影期间进行剔除的自定义矩阵。 |
AddCommandBuffer | 添加要在指定位置执行的命令缓冲区。 |
AddCommandBufferAsync | 向 GPU 的异步计算队列添加命令缓冲区,并在图形处理到达给定点时执行该命令缓冲区。 |
GetCommandBuffers | 获取要在指定位置执行的命令缓冲区。 |
RemoveAllCommandBuffers | 删除在此光源上设置的所有命令缓冲区。 |
RemoveCommandBuffer | 从指定位置的执行中删除一个命令缓冲区。 |
RemoveCommandBuffers | 从指定位置的执行中删除多个命令缓冲区。 |
Reset | 将所有光源参数恢复为默认值。 |
SetLightDirty | 将光源设置为“脏”可通知光照烘培后端更新其内部光源表示形式(仅限编辑器)。 |
enabled | 启用的 Behaviour 可更新,禁用的 Behaviour 不可更新。 |
isActiveAndEnabled | 是否已激活并启用 Behaviour? |
gameObject | 此组件附加到的游戏对象。始终将组件附加到游戏对象。 |
tag | 此游戏对象的标签。 |
transform | 附加到此 GameObject 的 Transform。 |
hideFlags | 该对象应该隐藏、随场景一起保存还是由用户修改? |
name | 对象的名称。 |
BroadcastMessage | 调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。 |
CompareTag | 此游戏对象是否使用 tag 进行了标记? |
GetComponent | 如果游戏对象附加了类型为 type 的组件,则将其返回,否则返回 null。 |
GetComponentInChildren | 使用深度首次搜索返回 GameObject 或其任何子项中类型为 type 的组件。 |
GetComponentInParent | 返回 GameObject 或其任何父项中类型为 type 的组件。 |
GetComponents | 返回 GameObject 中类型为 type 的所有组件。 |
GetComponentsInChildren | 返回 GameObject 或其任何子项中类型为 type 的所有组件。 |
GetComponentsInParent | 返回 GameObject 或其任何父项中类型为 type 的所有组件。 |
SendMessage | 调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。 |
SendMessageUpwards | 调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。 |
TryGetComponent | 获取指定类型的组件(如果存在)。 |
GetInstanceID | 返回对象的实例 ID。 |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsOfType | 返回所有类型为 type 的已加载的激活对象的列表。 |
Instantiate | 克隆 original 对象并返回克隆对象。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.