主题
DynamicRectLight
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(5 属性 / 28 函数 / 6 事件)
- DynamicLight(11 属性)
- [DynamicRectLight](3 属性)
- DynamicLight(11 属性)
继承成员
2 个来源 / 16 属性 / 28 函数 / 6 事件
- 来自 DynamicLight(11 属性)
- 来自 Unit(5 属性 / 28 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent、Tags - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetFullPath、GetDebugId、HasTag、AddTag、RemoveTag - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
动态矩形光源以一块矩形发光面照亮场景并投射阴影,照明区域的形状由矩形宽度与高度共同决定,张角则控制光线向外扩散的开口大小。相比点光源的球形照明或聚光灯的锥形照明,它更贴近窗光、门缝光、灯箱这类具有明显长宽比例的发光面。
适用场景
适合把光源贴在窗户、天窗、门缝或广告灯箱的位置,让室内或通道获得与开口形状一致的亮斑与投影,营造有方向感的面光源氛围。
使用要点
通过 game:CreateUnit("DynamicRectLight", ...) 或 World:CreateUnit("DynamicRectLight", ...) 创建实例,创建时在配置表中填写 RectWidth、RectHeight 与 RectConeAngle。拿到实例后直接读写这三个属性,即可在运行时调整发光面的宽高比例与扩散角度。
注意事项
该类型属于单元类型,不能用构造式直接创建,只能由 game:CreateUnit 或 World:CreateUnit 生成,或从公开接口的返回值获取。调节光照形状时需同时兼顾宽度与高度,只改其一容易让光斑比例失真。实例被销毁后属性不再可用,需重新创建后再设置参数。
代码示例
创建 DynamicRectLight 实例
lua
-- @runtime client
local World = game:GetService('World')
local dynamicRectLight = World:CreateUnit('DynamicRectLight', {})
if dynamicRectLight == nil then return end
print('DynamicRectLight 已创建:', dynamicRectLight.Name)属性 (3)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
RectHeight | Float | 5.0 | 矩形光源的矩形高度,Float 类型,用于描述光源发光面的纵向尺寸。 |
RectWidth | Float | 5.0 | 矩形光源的矩形宽度,Float 类型,用于描述光源发光面的横向尺寸。 |
RectConeAngle | Float | 60.0 | 矩形光源的张角,Float 类型,控制矩形光源发射光线的扩散角度。 |
