跳至正文
版本:bleeding-edge 🩸

💡 光照

Light 代表一个光照源。

Client & Server🔁Not Distributable🧑‍💻API Source
👪Inheritance
This class shares methods and events from Base Entity, Base Actor.

🎒 示例

local my_light = Light(
Vector(-152, 245, 115),
Rotator(0, 90, 90), -- Relevant only for Rect and Spot light types
Color(1, 0, 0), -- Red Tint
LightType.Point, -- Point Light type
100, -- Intensity
250, -- Attenuation Radius
44, -- Cone Angle (Relevant only for Spot light type)
0, -- Inner Cone Angle Percent (Relevant only for Spot light type)
5000, -- Max Draw Distance (Good for performance - 0 for infinite)
true, -- Whether to use physically based inverse squared distance falloff, where Attenuation Radius is only clamping the light's contribution. (Spot and Point types only)
true, -- Cast Shadows?
true -- Enabled?
)

🛠 构造函数

Default Constructor

No description provided

local my_light = Light(location, rotation?, color?, light_type?, intensity?, attenuation_radius?, cone_angle?, inner_cone_angle_percent?, max_draw_distance?, use_inverse_squared_falloff?, cast_shadows?, visible?, source_radius?, spawn_mode?)

Parameters

TypeNameDefaultDescription
Vectorlocation Required parameter No description provided
RotatorrotationRotator(0, 0, 0)仅 Rect 和 Spot 光照类型有效
ColorcolorColor(1, 1, 1)No description provided
LightTypelight_typeLightType.PointNo description provided
floatintensity30No description provided
floatattenuation_radius250No description provided
floatcone_angle44仅对 Spot 光照类型有效
floatinner_cone_angle_percent0内锥角百分比(仅对 Spot 光照类型有效)(0-1)
floatmax_draw_distance10000最大绘制距离(有利于性能)- 0 表示无限远
booleanuse_inverse_squared_fallofftrue是否使用基于物理的平方反比距离衰减,此时衰减半径仅对光照的贡献进行剪裁。(仅限 Spot 和 Point 光源类型)
booleancast_shadowstrueNo description provided
booleanvisibletrueNo description provided
floatsource_radius2光源形状的半径。(仅限 Spot 和 Point 光源类型)
SpawnModespawn_modeSpawnMode.Immediate传入 SpawnMode.AfterConstructorSpawnMode.Manual 可避免立即将实体发送至客户端,在需要配置多项设置时使用此选项可提升性能。最后必须调用 FinishSpawn()
提示

nanos world provides 3 types of lights: Spot, Point and Rect. All lights are Dynamic and because of that, very expensive! Keep that in mind before spawning 1000 lights 😉.

🗿 静态函数

Inherited Entity Static Functions
Light inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
table of Base EntityGetAll返回一个包含调用此方法的类中所有实体的表
Base EntityGetByIndex返回该类中指定索引处的特定实体
integerGetCount返回该类当前存在的实体数量
table of tableGetInheritedClasses获取使用 继承系统 创建的、直接继承自该类的所有子类列表
iteratorGetPairs返回一个包含该类所有实体的迭代器,用于 pairs() 循环
table or nilGetParentClass如果该类是使用 继承系统 创建的,则获取其父类
tableInherit使用 继承系统 继承此类
booleanIsChildOf如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类
functionSubscribe为该类的所有实体订阅一个 事件
functionSubscribeRemote订阅从服务器调用的自定义远程事件
Unsubscribe退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调

This class doesn't have own static functions.

🦠 函数

Inherited Entity Functions
Light inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
ReturnsNameDescription
BroadcastRemoteEvent直接在此实体上向所有玩家调用自定义远程事件
BroadcastRemoteInRadiusEvent直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家
CallRemoteEvent直接在此实体上向特定玩家调用自定义远程事件
CallRemoteEvent直接在此实体上调用自定义远程事件
CallRemotePlayersEvent直接在此实体上调用自定义远程事件,并将事件传递给玩家列表
Destroy销毁该实体
FinishSpawn如果此实体是以延迟 spawn_mode 生成的,则完成生成过程并将该实体发送至客户端
table of stringGetAllValuesKeys获取所有值键的列表
tableGetClass获取该实体的类
integerGetID获取该实体的全网通用网络 ID(在客户端和服务器上相同)
anyGetValue获取此实体上存储在给定键处的
booleanHasAuthority获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false)
booleanIsA递归检查此实体是否继承自某个类
booleanIsBeingDestroyed如果该实体正在被销毁,则返回 true
booleanIsSpawned获取此实体是否已完成生成
booleanIsValid如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true
SetSpawnMode从继承类的构造函数中覆盖此实体完成生成的时间点
SetValue在此实体中设置一个
functionSubscribe在这个特定实体上订阅一个事件
functionSubscribeRemote在这个特定实体上订阅一个从服务器调用的自定义远程事件
Unsubscribe退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调
Inherited Actor Functions
Light inherits from Base Actor Class, sharing it's methods and functions:
Base Actorscripting-reference/classes/base-classes/actor
ReturnsNameDescription
AddActorTag向该 Actor 添加一个虚幻 Actor 标签
AddAngularImpulse向该 Actor 添加角冲量。适用于单次瞬间爆发
AddImpulse向该 Actor 添加冲量。适用于单次瞬间爆发
booleanAttachTo将该 Actor 附加到任何其他 Actor 上,可选择附加在特定骨骼处
Detach将该 Actor 从其附加的 Actor 上分离
table of stringGetActorTags获取该 Actor 上的所有虚幻 Actor 标签
VectorGetAngularForce获取该 Actor 的角外力(由 SetAngularForce() 设置)
floatGetAngularVelocity返回此 Actor 的角速度
table of Base ActorGetAttachedEntities获取附加到该 Actor 的所有 Actor
Base Actor or nilGetAttachedTo获取该 Actor 所附加到的父级 Actor
tableGetBounds获取该 Actor 的边界范围
CollisionTypeGetCollision获取该 Actor 的碰撞类型
integerGetDimension获取该 Actor 的维度
floatGetDistanceFromCamera获取该 Actor 距离相机的距离
VectorGetForce获取该 Actor 的持续外力(由 SetForce() 设置)
VectorGetLocation获取该 Actor 在游戏世界中的位置
floatGetMass返回此 Actor 的质量
Player or nilGetNetworkAuthority获取该 Actor 的网络主控玩家
VectorGetRelativeLocation如果该 Actor 已附加,获取其相对位置
RotatorGetRelativeRotation如果该 Actor 已附加,获取其相对旋转
RotatorGetRotation获取该 Actor 在游戏世界中的角度值
VectorGetScale获取该 Actor 的缩放比例
floatGetScreenPercentage获取该 Actor 在屏幕中所占尺寸的百分比
tableGetSocketTransform在给定骨骼或插槽名称的情况下,获取世界空间中的插槽变换
VectorGetVelocity获取该 Actor 当前的速度
booleanHasNetworkAuthority如果本地玩家当前是该 Actor 的网络主控(Network Authority),则返回 true
booleanIsGravityEnabled如果该 Actor 启用了重力,则返回 true
booleanIsInWater如果该 Actor 处于水中,则返回 true
booleanIsNetworkDistributed如果该 Actor 当前处于网络分配状态,则返回 true
booleanIsVisible如果该 Actor 可见,则返回 true
RemoveActorTag从该 Actor 中移除一个虚幻 Actor 标签
RotateTo在一定时间内平滑旋转该 Actor 到指定角度
SetAngularForce向该 Actor 添加一个永久的角外力,设为 Vector(0, 0, 0) 可以取消
SetCastShadow设置该 Actor 是否投射阴影
SetCollision设置该 Actor 的碰撞类型
SetDimension设置该 Actor 的维度
SetDistanceOptimizationMultiplier设置此 Actor 的距离优化系数
SetForce向该 Actor 添加一个永久的外力,设为 Vector(0, 0, 0) 可以取消
SetGravityEnabled设置该 Actor 是否启用重力
SetHighlightEnabled设置该 Actor 是否启用高亮显示,以及使用哪个高亮索引值
SetLifeSpan设置该 Actor 被销毁前的生存时间(秒)。经过这段时间后,Actor 将被自动销毁。
SetLocation设置该 Actor 在游戏世界中的位置
SetNetworkAuthority设置某个玩家拥有此 Actor 的网络主控
SetNetworkAuthorityAutoDistributed设置该 Actor 是否在玩家之间自动分配网络主控
SetOutlineEnabled设置该 Actor 是否启用描边,以及使用哪个描边索引值
SetRelativeLocation在本地空间中设置该 Actor 的相对位置(仅在此 Actor 已附加时生效)
SetRelativeRotation在本地空间中设置该 Actor 的相对旋转(仅在此 Actor 已附加时生效)
SetRenderCullDistance设置该 Actor 的渲染剔除距离
SetRotation设置该 Actor 在游戏世界中的旋转
SetScale设置该 Actor 的缩放比例
SetVisibility设置该 Actor 是否可见
TranslateTo在一定时间内平滑地将该 Actor 移动到某个位置
booleanWasRecentlyRendered获取该 Actor 最近是否在屏幕上被渲染过
ReturnsNameDescription
floatGetAttenuationRadiusNo description provided
booleanGetCastShadowsNo description provided
ColorGetColorNo description provided
floatGetIntensityNo description provided
SetAttenuationRadiusNo description provided
SetCastShadowsNo description provided
SetColor设置光照颜色
SetIntensityNo description provided
SetTextureLightProfile设置光照的纹理轮廓

Optimal

GetAttenuationRadius

local attenuation_radius = my_light:GetAttenuationRadius()

Returns

TypeDescription
floatattenuation_radius

See also SetAttenuationRadius.


Optimal

GetCastShadows

local is_shadows_enabled = my_light:GetCastShadows()

Returns

TypeDescription
booleanis_shadows_enabled

See also SetCastShadows.


Optimal

GetColor

local color = my_light:GetColor()

Returns

TypeDescription
Colorcolor

See also SetColor.


Optimal

GetIntensity

local intensity = my_light:GetIntensity()

Returns

TypeDescription
floatintensity

See also SetIntensity.


Optimal

SetAttenuationRadius

my_light:SetAttenuationRadius(attenuation_radius)

Parameters

TypeParameterDefaultDescription
floatattenuation_radius Required parameter No description provided

See also GetAttenuationRadius.


Optimal

SetCastShadows

my_light:SetCastShadows(is_shadows_enabled)

Parameters

TypeParameterDefaultDescription
booleanis_shadows_enabled Required parameter No description provided

See also GetCastShadows.


Optimal

SetColor

设置光照颜色
my_light:SetColor(color)

Parameters

TypeParameterDefaultDescription
Colorcolor Required parameter 光照颜色

See also GetColor.


Optimal

SetIntensity

my_light:SetIntensity(intensity)

Parameters

TypeParameterDefaultDescription
floatintensity Required parameter No description provided

See also GetIntensity.


Optimal

SetTextureLightProfile

设置光照的纹理轮廓
my_light:SetTextureLightProfile(light_profile)

Parameters

TypeParameterDefaultDescription
LightProfilelight_profile Required parameter 要使用的光照轮廓

See also 💡 Light Profiles.

🚀 事件

Inherited Entity Events
Light inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
NameDescription
ClassRegister当使用 继承系统 注册一个新类时触发
Destroy当实体被销毁时触发
Spawn当实体被生成/创建时触发
ValueChange当实体通过 :SetValue() 改变了值时触发
Inherited Actor Events
Light inherits from Base Actor Class, sharing it's events:
Base Actorscripting-reference/classes/base-classes/actor
NameDescription
DimensionChange当 Actor 改变其维度时触发
EnterWaterTriggered when an Actor enters a water body
LeaveWaterTriggered when an Actor leaves a water body
NetworkAuthorityChangeTriggered when an Actor changes its network authority Player
NetworkAuthorityChangeTriggered when the local Player gets/loses network authority over this actor

This class doesn't have own events.

💡 Light Profiles

Light Profiles are texture files which describes a light's distribution from a light source using real world measured data.

提示

Please check Unreal Engine Light Profile documentation for more information about Light Profiles!

nanos world provides 50 Light Profiles included in the base game which you can use to enhance your Lights. You can set them using :SetTextureLightProfile() with the enum LightProfile.