跳至正文
版本:最新版 - a1.156.0 ⚖️

🧭 Gizmo

一种用于在运行时变换对象的工具。

👪Inheritance
This class shares methods and events from Base Entity, Base Actor.

🎒 示例​

-- 禁用输入并启用鼠标光标
Input.SetInputEnabled(false)
Input.SetMouseEnabled(true)

-- 生成一个网格体以与之交互
local my_entity = StaticMesh(Vector(0, 0, 100), Rotator(), "nanos-world::SM_Cube")

-- 生成 gizmo
local my_gizmo = Gizmo()

-- 激活位于网格体位置的 gizmo
my_gizmo:Activate(my_entity:GetLocation(), my_entity:GetRotation(), my_entity:GetScale())

-- 订阅 Gizmo 更新
my_gizmo:Subscribe("Transform", function(self, location, rotation, scale)
my_entity:TranslateTo(location, 0.02)
my_entity:RotateTo(rotation, 0.02)
my_entity:SetScale(scale)
end)

-- 鼠标点击时,触发 Gizmo 输入
Input.Subscribe("MouseDown", function(key)
if (key == "LeftMouseButton") then
my_gizmo:PressPointer()
end
end)

-- 鼠标松开时,触发 Gizmo 输入
Input.Subscribe("MouseUp", function (key, b, c)
if (key == "LeftMouseButton") then
my_gizmo:ReleasePointer()
end
end)

🛠 构造函数​

Default Constructor​

No description provided

local my_gizmo = Gizmo()

This constructor doesn't have parameters.

🗿 静态函数​

Inherited Entity Static Functions
Gizmo 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
Gizmo 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
Gizmo 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
stringGetAttachedToSocket获取此 Actor 所附加到的骨骼或插槽名称
tableGetBounds获取此 Actor 的包围盒,便于计算其在世界中的尺寸
CollisionTypeGetCollision获取该 Actor 的碰撞类型
integerGetDimension获取该 Actor 的维度
floatGetDistanceFromCamera获取该 Actor 距离相机的距离
VectorGetForce获取该 Actor 的持续外力(由 SetForce() 设置)
floatGetLifeSpan获取此 Actor 被销毁前剩余的时间(秒)
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 的维度。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
Activate启用交互,并将 Gizmo 放置在给定的变换位置
Deactivate禁用交互
booleanIsInteracting返回当前是否正在交互
PressPointer触发其上的按下指针事件
ReleasePointer触发其上的释放指针事件
SetAlignSpace设置 Gizmo 是对齐到局部空间还是世界空间
SetSnapSettings设置吸附网格大小,设为 0 可禁用吸附
SetTransformMode设置 Gizmo 的模式为平移、旋转还是缩放

Moderate

Activate​

启用交互,并将 Gizmo 放置在给定的变换位置
my_gizmo:Activate(location, rotation, scale)

Parameters

TypeParameterDefaultDescription
Vectorlocation Required parameter Gizmo 的世界位置
Rotatorrotation Required parameter Gizmo 的世界旋转
Vectorscale Required parameter Gizmo 的缩放

Moderate

Deactivate​

禁用交互
my_gizmo:Deactivate()

Moderate

IsInteracting​

返回当前是否正在交互
local is_interacting = my_gizmo:IsInteracting()

Returns

TypeDescription
boolean当前是否正在进行交互

Moderate

PressPointer​

触发其上的按下指针事件
my_gizmo:PressPointer()

Moderate

ReleasePointer​

触发其上的释放指针事件
my_gizmo:ReleasePointer()

Moderate

SetAlignSpace​

设置 Gizmo 是对齐到局部空间还是世界空间
my_gizmo:SetAlignSpace(align_space)

Parameters

TypeParameterDefaultDescription
GizmoAlignSpacealign_space Required parameter 对齐空间

Moderate

SetSnapSettings​

设置吸附网格大小,设为 0 可禁用吸附
my_gizmo:SetSnapSettings(location_grid_size, rotation_grid_size, scale_grid_size)

Parameters

TypeParameterDefaultDescription
floatlocation_grid_size Required parameter 平移吸附大小(单位)
floatrotation_grid_size Required parameter 旋转吸附大小(度)
floatscale_grid_size Required parameter 缩放吸附大小

Moderate

SetTransformMode​

设置 Gizmo 的模式为平移、旋转还是缩放
my_gizmo:SetTransformMode(transform_mode, combine_translate_rotate)

Parameters

TypeParameterDefaultDescription
GizmoTransformModetransform_mode Required parameter 变换模式
booleancombine_translate_rotate Required parameter 是否同时显示平移和旋转轴手柄

🚀 事件​

Inherited Entity Events
Gizmo 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
Gizmo inherits from Base Actor Class, sharing it's events:
Base Actorscripting-reference/classes/base-classes/actor
NameDescription
DimensionChange当 Actor 改变其维度时触发
EnterWater当 Actor 进入水体时触发
LeaveWater当 Actor 离开水体时触发
NetworkAuthorityChange当 Actor 更改其网络主控玩家时触发
NetworkAuthorityChange当本地玩家获得或失去对此 Actor 的网络主控时触发
NameDescription
Transform当 Gizmo 的变换更新时触发

Transform​

当 Gizmo 的变换更新时触发
Gizmo.Subscribe("Transform", function(self, location, rotation, scale)
-- Transform was called
end)

Arguments

TypeArgumentDescription
GizmoselfGizmo 自身
Vectorlocation新的 Gizmo 位置
Rotatorrotation新的 Gizmo 旋转
Vectorscale新的 Gizmo 缩放