📦 Prop
道具代表一个可以在世界中生成的动态网格体,它拥有物理效果,并可以被角色抓取并移动。

👪Inheritance
🎒 示例
Server/Index.lua
local my_prop = Prop(
Vector(-900, 185, 215),
Rotator(0, 90, 90),
"nanos-world::SM_Crate_07"
)
🛠 构造函数
Default Constructor
No description provided
local my_prop = Prop(location, rotation, asset, collision_type?, gravity_enabled?, grab_mode?, ccd_mode?, spawn_mode?)
Parameters
| Type | Name | Default | Description |
|---|---|---|---|
| Vector | location | Required parameter | 生成的世界坐标位置 |
| Rotator | rotation | Required parameter | 生成的世界坐标旋转 |
| StaticMesh Reference | asset | Required parameter | 要使用的资产 |
| CollisionType | collision_type | CollisionType.Auto | 设为 CollisionType.Auto 时,如果道具的半径小于 40 个单位,它将在 Normal 和 IgnoreOnlyPawn 之间自动切换。 |
| boolean | gravity_enabled | true | 重力是否影响此 Actor |
| GrabMode | grab_mode | GrabMode.Auto | 该道具是否可以被抓取 |
| CCDMode | ccd_mode | CCDMode.Auto | 该道具是否应当启用 CCD(如果道具较小,禁用此项可能会导致其穿透物体)。在“仅限视觉效果”的道具上强制禁用它是明智的选择。 |
| SpawnMode | spawn_mode | SpawnMode.Immediate | 传入 SpawnMode.AfterConstructor 或 SpawnMode.Manual 可避免立即将实体发送至客户端,在需要配置多项设置时使用此选项可提升性能。最后必须调用 FinishSpawn() |
信息
如果 Prop 是由客户端生成的。它的所有交互将被禁用(例如无法被 Character 抓取)。
信息
半径小于 40 单位或非常薄(任何一边小于 20 单位)的 Prop 将自动启用 CCD(连续碰撞检测),以避免穿过地面或其他物体。这会稍微增加它们的性能开销!
🗿 静态函数
Inherited Entity Static Functions
Prop inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
| table of Base Entity | GetAll | 返回一个包含调用此方法的类中所有实体的表 | |
| Base Entity | GetByIndex | 返回该类中指定索引处的特定实体 | |
| integer | GetCount | 返回该类当前存在的实体数量 | |
| table of table | GetInheritedClasses | 获取使用 继承系统 创建的、直接继承自该类的所有子类列表 | |
| iterator | GetPairs | 返回一个包含该类所有实体的迭代器,供 pairs() 使用 | |
| table or nil | GetParentClass | 如果该类是使用 继承系统 创建的,则获取其父类 | |
| table | Inherit | 通过 继承系统 继承此类 | |
| boolean | IsChildOf | 如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类 | |
| function | Subscribe | 为此类的所有实体订阅一个 事件 | |
| function | SubscribeRemote | 订阅从服务器调用的自定义事件 | |
Unsubscribe | 退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调 |
This class doesn't have own static functions.
🦠 函数
Inherited Entity Functions
Prop inherits from Base Entity Class, sharing it's methods and functions:
Base Entityscripting-reference/classes/base-classes/entity
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
BroadcastRemoteEvent | 直接在此实体上向所有玩家调用自定义远程事件 | ||
BroadcastRemoteInRadiusEvent | 直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家 | ||
CallRemoteEvent | 直接在此实体上向特定玩家调用自定义远程事件 | ||
CallRemoteEvent | 直接在此实体上调用自定义远程事件 | ||
CallRemotePlayersEvent | 直接在此实体上调用自定义远程事件,并将事件传递给玩家列表 | ||
Destroy | 销毁此实体 | ||
FinishSpawn | 如果此实体是以延迟 spawn_mode 生成的,则完成生成过程并将该实体发送至客户端 | ||
| table of string | GetAllValuesKeys | 获取所有存储值的键名列表 | |
| table | GetClass | 获取此实体的类 | |
| integer | GetID | 获取此实体的通用网络 ID(客户端和服务器一致) | |
| any | GetValue | 获取存储在此实体上指定键处的 值 | |
| boolean | HasAuthority | 获取本地上下文是否对此实体拥有主控(如果由客户端生成则为 true,由服务器生成则为 false) | |
| boolean | IsA | 递归检查此实体是否继承自某个类 | |
| boolean | IsBeingDestroyed | 如果此实体正在被销毁,则返回 true | |
| boolean | IsSpawned | 获取此实体是否已完成生成 | |
| boolean | IsValid | 如果此实体有效(即未被销毁且指向有效的实体),则返回 true | |
SetSpawnMode | 从继承类的构造函数中覆盖此实体完成生成的时间点 | ||
SetValue | 在此实体中设置一个 值 | ||
| function | Subscribe | 在这个特定实体上订阅一个事件 | |
| function | SubscribeRemote | 在这个特定实体上订阅一个从服务器调用的自定义远程事件 | |
Unsubscribe | 退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调 |
Inherited Actor Functions
Prop inherits from Base Actor Class, sharing it's methods and functions:
Base Actorscripting-reference/classes/base-classes/actor
Base Actorscripting-reference/classes/base-classes/actor
| Returns | Name | Description | |
|---|---|---|---|
AddActorTag | 向该 Actor 添加一个虚幻 Actor 标签 | ||
AddAngularImpulse | 向该 Actor 添加角冲量。适用于单次瞬间爆发 | ||
AddImpulse | 向该 Actor 添加冲量。适用于单次瞬间爆发 | ||
| boolean | AttachTo | 将该 Actor 附加到任何其他 Actor 上,可选择附加在特定骨骼处 | |
Detach | 将该 Actor 从其附加的 Actor 上分离 | ||
| table of string | GetActorTags | 获取该 Actor 上的所有虚幻 Actor 标签 | |
| Vector | GetAngularForce | 获取该 Actor 的角外力(由 SetAngularForce() 设置) | |
| float | GetAngularVelocity | 返回此 Actor 的角速度 | |
| table of Base Actor | GetAttachedEntities | 获取附加到该 Actor 的所有 Actor | |
| Base Actor or nil | GetAttachedTo | 获取该 Actor 所附加到的父级 Actor | |
| string | GetAttachedToSocket | 获取此 Actor 所附加到的骨骼或插槽名称 | |
| table | GetBounds | 获取此 Actor 的包围盒,便于计算其在世界中的尺寸 | |
| CollisionType | GetCollision | 获取该 Actor 的碰撞类型 | |
| integer | GetDimension | 获取该 Actor 的维度 | |
| float | GetDistanceFromCamera | 获取该 Actor 距离相机的距离 | |
| Vector | GetForce | 获取该 Actor 的持续外力(由 SetForce() 设置) | |
| float | GetLifeSpan | 获取此 Actor 被销毁前剩余的时间(秒) | |
| Vector | GetLocation | 获取该 Actor 在游戏世界中的位置 | |
| float | GetMass | 返回此 Actor 的质量 | |
| Player or nil | GetNetworkAuthority | 获取该 Actor 的网络主控玩家 | |
| Vector | GetRelativeLocation | 如果该 Actor 已附加,获取其相对位置 | |
| Rotator | GetRelativeRotation | 如果该 Actor 已附加,获取其相对旋转 | |
| Rotator | GetRotation | 获取该 Actor 在游戏世界中的角度值 | |
| Vector | GetScale | 获取该 Actor 的缩放比例 | |
| float | GetScreenPercentage | 获取该 Actor 在屏幕中所占尺寸的百分比 | |
| table | GetSocketTransform | 在给定骨骼或插槽名称的情况下,获取世界空间中的插槽变换 | |
| Vector | GetVelocity | 获取该 Actor 当前的速度 | |
| boolean | HasNetworkAuthority | 如果本地玩家当前是该 Actor 的网络主控(Network Authority),则返回 true | |
| boolean | IsGravityEnabled | 如果该 Actor 启用了重力,则返回 true | |
| boolean | IsInWater | 如果该 Actor 处于水中,则返回 true | |
| boolean | IsNetworkDistributed | 如果该 Actor 当前处于网络分配状态,则返回 true | |
| boolean | IsVisible | 如果该 Actor 可见,则返回 true | |
RemoveActorTag | 从该 Actor 中移除一个虚幻 Actor 标签 | ||
RotateTo | 在一定时间内平滑旋转该 Actor 到指定角度 | ||
SetAngularForce | 向该 Actor 添加一个永久的角外力,设为 Vector(0, 0, 0) 可以取消 | ||
SetCastShadow | 设置该 Actor 是否投射阴影 | ||
SetCollision | 设置该 Actor 的碰撞类型 | ||
SetDimension | 设置此 Actor 的维度。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 移动到某个位置 | ||
| boolean | WasRecentlyRendered | 获取该 Actor 最近是否在屏幕上被渲染过 |
Inherited Paintable Functions
Prop inherits from Base Paintable Class, sharing it's methods and functions:
Base Paintablescripting-reference/classes/base-classes/paintable
Base Paintablescripting-reference/classes/base-classes/paintable
| Returns | Name | Description | |
|---|---|---|---|
| Color | GetMaterialColorParameter | 从该 Actor 的材质中获取 Color 参数 | |
| float | GetMaterialScalarParameter | 从该 Actor 的材质中获取 Scalar 参数 | |
| string | GetMaterialTextureParameter | 从该 Actor 的材质中获取 Texture 参数 | |
| Vector | GetMaterialVectorParameter | 从该 Actor 的材质中获取 Vector 参数 | |
ResetMaterial | 将指定索引处的材质重置为原始材质 | ||
SetMaterial | 设置该 Actor 指定索引处的材质 | ||
SetMaterialColorParameter | 设置该 Actor 材质中的 Color 参数 | ||
SetMaterialFromCanvas | 将该 Actor 指定索引处的材质设为 Canvas 对象 | ||
SetMaterialFromSceneCapture | 将该 Actor 指定索引处的材质设为 SceneCapture 对象 | ||
SetMaterialFromWebUI | 将该 Actor 指定索引处的材质设为 WebUI 对象 | ||
SetMaterialScalarParameter | 设置该 Actor 材质中的 Scalar 参数 | ||
SetMaterialTextureParameter | 将该 Actor 材质中的纹理参数设为一张图像 | ||
SetMaterialVectorParameter | 设置该 Actor 材质中的 Vector 参数 | ||
SetPhysicalMaterial | 使用新的物理材质覆盖该 Actor 的物理材质 |
| Returns | Name | Description | |
|---|---|---|---|
| GrabMode | GetGrabMode | 获取抓取该道具的能力 | |
| Character or nil | GetHandler | 获取当前正手持该物体的角色(如果存在) | |
| float | GetMassOverride | 获取覆盖的质量 | |
| float | GetMassScale | 获取质量缩放值 | |
| StaticMesh Reference | GetMesh | 获取资产名称 | |
SetBuoyancyPontoons | 设置水体模拟所使用的浮筒 | ||
SetBuoyancySettings | 设置该实体在水中的行为 | ||
SetGrabMode | 设置角色抓取该道具的能力 | ||
SetInteractionToolTipText | 设置角色与该道具交互时显示的交互提示文本 | ||
SetMassOverride | 覆盖该道具的质量(千克) | ||
SetMassScale | 更改用于计算该道具质量的质量缩放值 | ||
SetMesh | 在运行时更改网格体 | ||
SetPhysicsDamping | 设置该道具的物理阻尼 |
Optimal

GetGrabMode
获取抓取该道具的能力
local grab_mode = my_prop:GetGrabMode()
Returns
| Type | Description |
|---|---|
| GrabMode | 抓取此道具的能力 |
See also SetGrabMode.
Optimal

GetHandler
获取当前正手持该物体的角色(如果存在)
local handler = my_prop:GetHandler()
Optimal

GetMassOverride
获取覆盖的质量
local ret = my_prop:GetMassOverride()
Returns
| Type | Description |
|---|---|
| float | 覆盖的质量 |
See also SetMassOverride.
Moderate

GetMassScale
获取质量缩放值
local ret = my_prop:GetMassScale()
Returns
| Type | Description |
|---|---|
| float | 质量缩放值 |
See also SetMassScale.
Optimal

GetMesh
获取资产名称
local asset = my_prop:GetMesh()
Returns
| Type | Description |
|---|---|
| StaticMesh Reference | 资产名称 |
See also SetMesh.
Moderate

SetBuoyancyPontoons
设置用于让该实体浮于水面上的球形浮筒,这将覆盖根据网格体边界和质量自动计算出的浮筒。
不传值(或传入空表)可恢复为自动计算的浮筒。
浮筒仅在启用了水体浮力的地图中生效
my_prop:SetBuoyancyPontoons(pontoons?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| table | pontoons? | nil | 包含浮筒数据的数组,传入 nil 可恢复自动计算的浮筒 with this format |
Moderate

SetBuoyancySettings
传入 nil 值将恢复该设置的默认值。
在自动计算浮筒时,修改 buoyancy_coefficient 也会同步重新计算浮筒,因为浮筒半径是由该系数推算出来的。
my_prop:SetBuoyancySettings(enabled?, buoyancy_coefficient?, buoyancy_damp?, max_buoyant_force?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| boolean | enabled? | true | 是否施加浮力 |
| float | buoyancy_coefficient? | 0.1 | 漂浮的程度,越高程度越大 |
| float | buoyancy_damp? | 1000 | 垂直速度的一阶阻尼,用于减少起伏 |
| float | max_buoyant_force? | 5000000 | 向上力的最大限制值,防止较轻的物体被直接弹飞出水面 |
Optimal

SetGrabMode
设置角色抓取该道具的能力
my_prop:SetGrabMode(grab_mode)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| GrabMode | grab_mode | Required parameter | 该道具是否可以被抓取。设为 Auto 将根据道具的大小自动决定。 |
See also GetGrabMode.
Optimal

SetInteractionToolTipText
设置角色与该道具交互时显示的交互提示文本
my_prop:SetInteractionToolTipText(tool_tip_text)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | tool_tip_text | Required parameter | 要在交互提示中显示的文本 |
Optimal

SetMassOverride
覆盖该道具的质量(千克)
my_prop:SetMassOverride(mass)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | mass | Required parameter | 要覆盖的质量(千克)。传入 -1 可重置为默认值 |
See also GetMassOverride.
Moderate

SetMassScale
更改用于计算该道具质量的质量缩放值
my_prop:SetMassScale(scale)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | scale | Required parameter | 用于计算此道具质量的新质量缩放比例 |
See also GetMassScale.
Slow

SetMesh
在运行时更改网格体
my_prop:SetMesh(asset)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| StaticMesh Reference | asset | Required parameter | 资产 |
See also GetMesh.
Optimal

SetPhysicsDamping
设置该道具的物理阻尼
my_prop:SetPhysicsDamping(linear_damping, angular_damping)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| float | linear_damping | Required parameter | 线速度阻尼值 |
| float | angular_damping | Required parameter | 角速度阻尼值 |
🚀 事件
Inherited Entity Events
Prop inherits from Base Entity Class, sharing it's events:
Base Entityscripting-reference/classes/base-classes/entity
Base Entityscripting-reference/classes/base-classes/entity
| Name | Description | |
|---|---|---|
ClassRegister | 当使用 继承系统 注册一个新类时触发 | |
Destroy | 当实体被销毁时触发 | |
Spawn | 当实体被生成/创建时触发 | |
ValueChange | 当实体通过 :SetValue() 改变了值时触发 |
Inherited Actor Events
Prop inherits from Base Actor Class, sharing it's events:
Base Actorscripting-reference/classes/base-classes/actor
Base Actorscripting-reference/classes/base-classes/actor
| Name | Description | |
|---|---|---|
DimensionChange | 当 Actor 改变其维度时触发 | |
EnterWater | 当 Actor 进入水体时触发 | |
LeaveWater | 当 Actor 离开水体时触发 | |
NetworkAuthorityChange | 当 Actor 更改其网络主控玩家时触发 | |
NetworkAuthorityChange | 当本地玩家获得或失去对此 Actor 的网络主控时触发 |
| Name | Description | |
|---|---|---|
Grab | 当角色抓取道具时触发 | |
Hit | 当该道具撞击到某种物体时触发 | |
Interact | 当角色与该道具交互时触发(即尝试抓取它) | |
TakeDamage | 当道具受到伤害时触发 | |
UnGrab | 当该道具被取消抓取时触发 |

Grab
当角色抓取道具时触发
Prop.Subscribe("Grab", function(self, character)
-- Grab was called
end)

Hit
当该道具撞击到某种物体时触发
Prop.Subscribe("Hit", function(self, impact_force, normal_impulse, impact_location, velocity, other_actor)
-- Hit was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Prop | self | 被撞击的道具 |
| float | impact_force | 撞击力度,已根据道具的重量进行归一化处理 |
| Vector | normal_impulse | 撞击的冲量方向 |
| Vector | impact_location | 撞击在世界 3D 空间中的位置 |
| Vector | velocity | 撞击瞬间该道具的速度 |
| Base Actor or nil | other_actor | 与该道具发生撞击的另一个 Actor |

Interact
当角色与该道具交互时触发(即尝试抓取它)
返回 false 以阻止该交互(例如防止被抓取)
Prop.Subscribe("Interact", function(self, character)
-- Interact was called
return true
end)

TakeDamage
当道具受到伤害时触发
Prop.Subscribe("TakeDamage", function(self, damage, bone, type, from_direction, instigator, causer)
-- TakeDamage was called
end)
Arguments
| Type | Argument | Description |
|---|---|---|
| Prop | self | 受到伤害的对象 |
| integer | damage | 伤害量 |
| string | bone | 受损的骨骼 |
| DamageType | type | 伤害类型 |
| Vector | from_direction | 伤害相对于受伤 Actor 的方向 |
| Player or nil | instigator | 造成伤害的玩家 |
| Base Actor or nil | causer | 造成伤害的对象 |

UnGrab
当该道具被取消抓取时触发
Prop.Subscribe("UnGrab", function(self, character)
-- UnGrab was called
end)


