Skip to content

Lighting ​

Lighting 光照服务。通过 editor:GetService("Lighting") 获取,读写场景光照属性(环境光、主光源、阴影淡化、反射贴图、天空背景)。

概览 ​

场景光照服务,通过 editor:GetService("Lighting") 获取。属性名与运行时 LightingService 一致,直接读写属性即可调整场景光照:环境光颜色/强度、主光源颜色/强度/朝向、阴影淡化、反射立方体贴图、电影色调映射、天空背景。属性修改支持撤销/重做。颜色属性以打包整数 0xRRGGBB 读写,写入时也接受 Color3 / Color 实例(如 Color3.New(r, g, b))。

Get by:

lua
-- @runtime editor
local service = editor:GetService("Lighting")

函数 ​

GetSkyBackgrounds ​

返回当前所有可选择的天空背景(官方预设),每项包含 id 与 name。

返回值

类型说明
Array每项 { id = 天空背景 ID, name = 天空背景名称 }

获取并遍历全部可选天空背景

lua
-- @runtime editor
local lighting = editor:GetService("Lighting")
-- 返回天空背景列表,每项包含 id 与 name,可直接用于选择器或预览
local backgrounds = lighting:GetSkyBackgrounds()
if backgrounds == nil or #backgrounds == 0 then
    print("没有可用的天空背景")
    return
end
for index, background in ipairs(backgrounds) do
    print(index, background.id, background.name)
end

属性 ​

名称类型默认值说明
AmbientColorColor36842472环境光颜色。读回为打包整数 0xRRGGBB;写入接受整数或 Color3 实例(如 Color3.New(r, g, b))。
AmbientIntensityFloat1.0环境光强度,取值范围 0~2。
ColorColor14803425主光源颜色。读回为打包整数 0xRRGGBB;写入接受整数或 Color 实例(如 Color.New(r, g, b, a))。
IntensityFloat2.0主光源强度,取值范围 0~8。
OrientationVector3[45, -45, 0]主光源朝向,通过 Vector3.New(x, y, z) 构造。
FilmicTonemapEnabledBoolfalse是否开启电影色调映射。
EnvironmentMapStringofficial://cube/28场景反射立方体贴图资源(立方体资源 id)。
ShadowFadeFloat0.0阴影淡化程度,取值范围 0~1。
SkyBackgroundInt-1场景天空背景。传官方预设的数字 ID;可用 GetSkyBackgrounds 获取全部可选值。