Skip to content

EUINodeBase ​

概览 ​

字段值
KindUnit · 单位 Unit
Realmcommon

继承关系 ​

继承成员 ​

1 个来源 / 4 属性 / 24 函数 / 6 事件

EUINodeBase 是 EUI 界面体系中可挂载的通用节点,负责承载界面元素的位置、尺寸、锚点、旋转、透明度、可见性、缩放以及层级与布局序号等显示状态。它同时提供触摸交互能力,包括触摸与拖动开关、触摸吞噬设置,以及触摸开始、触摸移动、触摸结束和点击的事件回调。节点还支持位移、尺寸、尺寸加位置、透明度四类补间动画,并提供引用计数式的保留与释放管理。

适用场景 ​

常用于在玩家界面上搭建自定义控件或容器:从界面根节点下创建节点,再用补间动画和触摸事件驱动其外观变化与交互反馈。

使用要点 ​

在客户端取得 Players.LocalPlayer 与 PlayerGui.EuiManager 的根节点,再用 World:CreateUnit("EUINodeBase", { Parent = rootNode }) 创建节点。通过 Visible、Position、Size、Anchor、Opacity 等属性控制布局,TweenPosition/TweenSize/TweenOpacity 用于动画。节点不再挂载时可调用 RemoveFromParent;只有先调用过 Retain 的节点才调用对应的 Release。

注意事项 ​

EUI 节点通过 World:CreateUnit 创建时,必须把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode();不能自行直接构造(Unit 不可直接构造)。本页公开且可写的属性支持 node.Property = value,也支持隐式 SetProperty(value) 访问器;读取可使用 node.Property 或 GetProperty()。readOnly=true 的属性只允许读取/Get,不允许直接赋值或 Set。普通属性修改优先使用直接赋值,TweenPosition/TweenSize 等带动画语义的方法不属于等价属性写入。Release 必须与此前的 Retain 成对调用。

代码示例 ​

创建基础 EUI 节点并设置显示区域 ​

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil or localPlayer.PlayerGui == nil then return end
local manager = localPlayer.PlayerGui.EuiManager
if manager == nil then return end
local rootNode = manager:GetRootNode()
if rootNode == nil then return end
local node = World:CreateUnit("EUINodeBase", {
    Parent = rootNode,
    Position = Vector2.New(0, 0),
    Size = Vector2.New(100, 40),
})
if node == nil then return end
node.Visible = true
node.Opacity = 0.9

属性 (35) ​

Name类型默认值说明
VisibleBooltrueEUINodeBase 的是否可见属性,类型为 Bool,用于控制节点是否显示。
PositionVector2[0, 0]Position 是 EUINodeBase 上的 Vector2 类型属性,用于表示节点在父节点坐标系中的位置,默认值为 (0, 0)。
AnchorVector2[0.5, 0.5]Anchor 是 EUINodeBase 上的 Vector2 类型属性,用于表示节点自身的锚点,即节点在定位时作为对齐基准的那个点,默认值为 (0.5, 0.5)。
FlippedXBoolfalseEUINodeBase 的横向反转开关,类型为 Bool,用于标记节点是否沿横向翻转。
FlippedYBoolfalseEUINodeBase 的纵向反转开关,类型为 Bool,用于标记节点是否沿纵向翻转。
SizeVector2[0, 0]节点的显示尺寸。
RotationFloat0.0EUINodeBase 的旋转属性,类型为 Float,以数值表示节点的旋转量。
OpacityFloat1.0EUINodeBase 的透明度属性,类型为 Float,以数值表示节点的透明程度。
TouchBeginAudioString""EUINodeBase 的按下音效属性,类型为 String,用于保存按下操作对应的音效标识。
TouchEndAudioString""EUINodeBase 的抬起音效属性,类型为 String,用于保存抬起操作对应的音效标识。
TouchClickAudioString""EUINodeBase 的点击音效属性,类型为 String,用于保存点击操作对应的音效标识。
TouchbeginEventString""EUINodeBase 的触摸开始事件属性,类型为 String,用于保存与触摸开始关联的事件标识。
ClickEventString""EUINodeBase 的点击事件属性,类型为 String,用于保存与点击关联的事件标识。
TouchendEventString""EUINodeBase 的触摸结束事件属性,类型为 String,用于保存与触摸结束关联的事件标识。
LongtouchEventString""EUINodeBase 的长按事件属性,类型为 String,用于保存与长按行为关联的事件标识。
ShowEventString""EUINodeBase 的显示事件属性,类型为 String,用于保存与显示行为关联的事件标识。
HideEventString""EUINodeBase 的隐藏事件属性,类型为 String,用于保存与隐藏行为关联的事件标识。
TouchEnabledBoolfalseEUINodeBase 的是否可触摸属性,类型为 Bool,用于标记节点是否接收触摸操作。
TouchDragEnabledBoolfalseTouchDragEnabled 是 EUINodeBase 上的 Bool 类型属性,用于表示该节点是否允许拖动,默认值为 false。
SwallowTouchEnabledBooltrueEUINodeBase 的是否吞噬触摸属性,类型为 Bool,用于标记节点是否吞掉触摸输入。
TopAdaptModeEUIAdaptModeEnums.EUIAdaptMode.NoneEUINodeBase 的顶部自适应模式属性,类型为 EUIAdaptMode,用于指定顶边的自适应方式。
TopAdaptionFloat0.0EUINodeBase 的顶部自适应量属性,类型为 Float,用于配合 TopAdaptMode 描述顶边的适配数值。
BottomAdaptModeEUIAdaptModeEnums.EUIAdaptMode.NoneEUINodeBase 的底部自适应模式属性,类型为 EUIAdaptMode,用于指定底边的自适应方式。
BottomAdaptionFloat0.0EUINodeBase 的底部自适应量属性,类型为 Float,用于配合 BottomAdaptMode 描述底边的适配数值。
LeftAdaptModeEUIAdaptModeEnums.EUIAdaptMode.NoneEUINodeBase 的左边自适应模式属性,类型为 EUIAdaptMode,用于指定左边的自适应方式。
LeftAdaptionFloat0.0EUINodeBase 的左边自适应量属性,类型为 Float,用于配合 LeftAdaptMode 描述左边的适配数值。
RightAdaptModeEUIAdaptModeEnums.EUIAdaptMode.NoneEUINodeBase 的右边自适应模式属性,类型为 EUIAdaptMode,用于指定右边的自适应方式。
RightAdaptionFloat0.0EUINodeBase 的右边自适应量属性,类型为 Float,用于配合 RightAdaptMode 描述右边的适配数值。
AnchorXAdaptModeEUIAnchorAdaptModeEnums.EUIAnchorAdaptMode.NoneEUINodeBase 的锚点 X 自适应模式属性,类型为 EUIAnchorAdaptMode,用于指定锚点在横向上的自适应方式。
AnchorXAdaptionFloat-EUINodeBase 的锚点 X 自适应量属性,类型为 Float,用于配合 AnchorXAdaptMode 描述横向锚点的适配数值。
AnchorYAdaptModeEUIAnchorAdaptModeEnums.EUIAnchorAdaptMode.NoneEUINodeBase 的锚点 Y 自适应模式属性,类型为 EUIAnchorAdaptMode,用于指定锚点在纵向上的自适应方式。
AnchorYAdaptionFloat-EUINodeBase 的锚点 Y 自适应量属性,类型为 Float,用于配合 AnchorYAdaptMode 描述纵向锚点的适配数值。
LocalZOrderInt0EUINodeBase 的层级序号属性,类型为 Int,用于描述节点在同一父级中的层级顺序。
LayoutOrderInt0EUINodeBase 的布局序号属性,类型为 Int,用于给节点在自动布局中提供排序依据。
ScaleVector2[1.0, 1.0]Scale 是 EUINodeBase 上的 Vector2 类型属性,用于表示节点的缩放比例,默认值为 (1, 1)。

关联类型 ​

事件 (4) ​

OnTouchBegan ​

签名:OnTouchBegan(euiTouchInfo: EUITouchInfo, player: Player) 触发:local

EUINodeBase 提供的触摸开始事件,当玩家在节点上开始触摸时触发,回调参数依次为 euiTouchInfo(EUITouchInfo 类型)与 player(Player 类型)。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 TouchEnabled=true 的节点。注册回调本身不代表触摸行为已验证。

回调参数类型说明
euiTouchInfoEUITouchInfo交互参数
playerPlayer玩家

示例代码

启用交互后监听 OnTouchBegan

lua
-- @runtime client
local player = game:GetService('Players').LocalPlayer
if player == nil or player.PlayerGui == nil then return end
local manager = player.PlayerGui.EuiManager
if manager == nil then return end
local root = manager:GetRootNode()
if root == nil then return end
local node = game:GetService('World'):CreateUnit('EUINodeBase', {
    Parent = root, Size = Vector2.New(160, 80), TouchEnabled = true,
})
if node == nil then return end
node.OnTouchBegan:Once(function(info, player)
    print('OnTouchBegan:', player)
end)

OnTouchMoved ​

签名:OnTouchMoved(euiTouchInfo: EUITouchInfo, player: Player) 触发:local

EUINodeBase 提供的触摸移动事件,当玩家在节点上触摸并移动时触发,回调参数依次为 euiTouchInfo(EUITouchInfo 类型)与 player(Player 类型)。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 TouchEnabled=true 的节点。注册回调本身不代表触摸行为已验证。

回调参数类型说明
euiTouchInfoEUITouchInfo交互参数
playerPlayer玩家

示例代码

启用交互后监听 OnTouchMoved

lua
-- @runtime client
local player = game:GetService('Players').LocalPlayer
if player == nil or player.PlayerGui == nil then return end
local manager = player.PlayerGui.EuiManager
if manager == nil then return end
local root = manager:GetRootNode()
if root == nil then return end
local node = game:GetService('World'):CreateUnit('EUINodeBase', {
    Parent = root, Size = Vector2.New(160, 80), TouchEnabled = true,
})
if node == nil then return end
node.OnTouchMoved:Once(function(info, player)
    print('OnTouchMoved:', player)
end)

OnTouchEnded ​

签名:OnTouchEnded(euiTouchInfo: EUITouchInfo, player: Player) 触发:local

EUINodeBase 提供的触摸结束事件,当玩家在节点上的触摸结束时触发,回调参数依次为 euiTouchInfo(EUITouchInfo 类型)与 player(Player 类型)。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 TouchEnabled=true 的节点。注册回调本身不代表触摸行为已验证。

回调参数类型说明
euiTouchInfoEUITouchInfo交互参数
playerPlayer玩家

示例代码

启用交互后监听 OnTouchEnded

lua
-- @runtime client
local player = game:GetService('Players').LocalPlayer
if player == nil or player.PlayerGui == nil then return end
local manager = player.PlayerGui.EuiManager
if manager == nil then return end
local root = manager:GetRootNode()
if root == nil then return end
local node = game:GetService('World'):CreateUnit('EUINodeBase', {
    Parent = root, Size = Vector2.New(160, 80), TouchEnabled = true,
})
if node == nil then return end
node.OnTouchEnded:Once(function(info, player)
    print('OnTouchEnded:', player)
end)

OnClicked ​

签名:OnClicked(player: Player) 触发:local

EUINodeBase 提供的点击事件,当节点被点击时触发,回调会传入触发点击的 player 参数(Player 类型)。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 TouchEnabled=true 的节点。注册回调本身不代表触摸行为已验证。

回调参数类型说明
playerPlayer玩家

示例代码

启用交互后监听 OnClicked

lua
-- @runtime client
local player = game:GetService('Players').LocalPlayer
if player == nil or player.PlayerGui == nil then return end
local manager = player.PlayerGui.EuiManager
if manager == nil then return end
local root = manager:GetRootNode()
if root == nil then return end
local node = game:GetService('World'):CreateUnit('EUINodeBase', {
    Parent = root, Size = Vector2.New(160, 80), TouchEnabled = true,
})
if node == nil then return end
node.OnClicked:Once(function(player)
    print('OnClicked:', player)
end)

函数 (12) ​

RemoveFromParent ​

签名:RemoveFromParent() -> void

将当前节点从其父级移除的方法。

返回值 void

示例代码

把 EUI 节点从父节点移除

lua
-- @runtime client
local player = game:GetService('Players').LocalPlayer
if player == nil or player.PlayerGui == nil then return end
local manager = player.PlayerGui.EuiManager
if manager == nil then return end
local root = manager:GetRootNode()
if root == nil then return end
local node = game:GetService('World'):CreateUnit('EUINodeBase', { Parent = root })
if node == nil then return end
node:RemoveFromParent()

GetFullPath ​

签名:GetFullPath() -> String (UI 路径字符串('.' 分隔))

获取当前 UI 节点完整路径的方法,返回以 '.' 分隔的路径字符串。

返回值 String (UI 路径字符串('.' 分隔))

示例代码

调用 EUINodeBase:GetFullPath 的示例。

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local euiNodeBase = World:CreateUnit("EUINodeBase", { Parent = rootNode })
local result = euiNodeBase:GetFullPath()  -- 返回 String
if result ~= nil then
    print(result)
    if result ~= "" then
        print("返回了非空字符串")
    end
end

TweenPosition ​

签名:TweenPosition(endPosition: Vector2, easingDirection: EasingDirection, easingStyle: EasingStyle, time: Float, override: Bool, callback: Function) -> Bool (是否成功启动新 Tween)

TweenPosition 是 EUINodeBase 上的补间接口,用于让节点的位置向 endPosition 指定的 Vector2 目标位置过渡。调用时需要同时给出缓动方向 easingDirection、缓动样式 easingStyle、补间时长 time、是否覆盖的 override,以及一个 Function 类型的 callback 参数;函数返回 Bool,表示本次调用是否成功启动了新的 Tween。

参数类型说明
endPositionVector2目标位置(绝对像素)
easingDirectionEasingDirection缓动方向(默认 Out)
easingStyleEasingStyle缓动样式(默认 Quad)
timeFloat时长(秒,默认 1)
overrideBool是否抢占同通道旧 Tween(默认 false)
callbackFunction完成或被抢占时触发的回调(status:TweenStatus)

返回值 Bool (是否成功启动新 Tween)

示例代码

把节点补间到目标位置

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local player = Players.LocalPlayer
if player == nil then return end
local node = World:CreateUnit("EUINodeBase", {
    Parent = player.PlayerGui.EuiManager:GetRootNode(),
    Position = Vector2.New(40, 40),
    Size = Vector2.New(100, 40),
})
node:TweenPosition(Vector2.New(160, 100), Enums.EasingDirection.Out, Enums.EasingStyle.Quad, 0.3, true, function()
    print("位置补间完成")
end)

TweenSize ​

签名:TweenSize(endSize: Vector2, easingDirection: EasingDirection, easingStyle: EasingStyle, time: Float, override: Bool, callback: Function) -> Bool (是否成功启动新 Tween)

TweenSize 是 EUINodeBase 上的尺寸过渡接口,按 endSize 指定的目标尺寸,配合 easingDirection、easingStyle 与 time 描述过渡的缓动方式与时长,为当前 EUI 节点启动一次尺寸变化;override 与 callback 分别作为覆盖开关与 Function 回调参与本次调用。函数返回 Bool,含义是“是否成功启动新 Tween”,调用方可据此判断本次请求是否真正触发了一段新的尺寸过渡。

参数类型说明
endSizeVector2目标尺寸(绝对像素)
easingDirectionEasingDirection缓动方向(默认 Out)
easingStyleEasingStyle缓动样式(默认 Quad)
timeFloat时长(秒,默认 1)
overrideBool是否抢占同通道旧 Tween(默认 false)
callbackFunction完成或被抢占时触发的回调(status:TweenStatus)

返回值 Bool (是否成功启动新 Tween)

示例代码

把节点尺寸补间到目标大小

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local player = Players.LocalPlayer
if player == nil then return end
local node = World:CreateUnit("EUINodeBase", {
    Parent = player.PlayerGui.EuiManager:GetRootNode(),
    Size = Vector2.New(100, 40),
})
node:TweenSize(Vector2.New(240, 80), Enums.EasingDirection.Out, Enums.EasingStyle.Quad, 0.3, true, function()
    print("尺寸补间完成")
end)

TweenSizeAndPosition ​

签名:TweenSizeAndPosition(endSize: Vector2, endPosition: Vector2, easingDirection: EasingDirection, easingStyle: EasingStyle, time: Float, override: Bool, callback: Function) -> Bool (是否成功启动新 Tween)

TweenSizeAndPosition 是 EUINodeBase 提供的补间接口,用于在指定时长内让节点同时从当前尺寸、当前位置过渡到目标尺寸与目标位置。调用时需要依次提供目标尺寸 endSize、目标位置 endPosition、缓动方向 easingDirection、缓动样式 easingStyle、补间时长 time,以及是否覆盖当前补间的 override 和补间结束后的回调函数 callback。函数返回一个 Bool,表示本次调用是否成功启动新的 Tween。

参数类型说明
endSizeVector2目标尺寸(绝对像素)
endPositionVector2目标位置(绝对像素)
easingDirectionEasingDirection缓动方向(默认 Out)
easingStyleEasingStyle缓动样式(默认 Quad)
timeFloat时长(秒,默认 1)
overrideBool是否抢占 Pos/Size 两通道旧 Tween(默认 false)
callbackFunction完成或被抢占时触发的回调(status:TweenStatus)

返回值 Bool (是否成功启动新 Tween)

示例代码

同时补间节点尺寸和位置

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local player = Players.LocalPlayer
if player == nil then return end
local node = World:CreateUnit("EUINodeBase", {
    Parent = player.PlayerGui.EuiManager:GetRootNode(),
    Position = Vector2.New(40, 40),
    Size = Vector2.New(100, 40),
})
node:TweenSizeAndPosition(Vector2.New(240, 80), Vector2.New(160, 100), Enums.EasingDirection.Out, Enums.EasingStyle.Quad, 0.3, true, function()
    print("尺寸和位置补间完成")
end)

TweenOpacity ​

签名:TweenOpacity(endOpacity: Float, easingDirection: EasingDirection, easingStyle: EasingStyle, time: Float, override: Bool, callback: Function) -> Bool (是否成功启动新 Tween)

TweenOpacity 是 EUINodeBase 提供的节点级透明度过渡接口:在给定的时间(time)内,把节点的透明度平滑过渡到 endOpacity,过渡过程使用 easingDirection 与 easingStyle 指定的缓动方向与缓动样式,并在过渡结束时触发 callback。函数返回一个 Bool,用于表示本次透明度过渡是否成功启动。

参数类型说明
endOpacityFloat目标透明度(0~1)
easingDirectionEasingDirection缓动方向(默认 Out)
easingStyleEasingStyle缓动样式(默认 Quad)
timeFloat时长(秒,默认 1)
overrideBool是否抢占 Opacity 通道旧 Tween(默认 false)
callbackFunction完成或被抢占时触发的回调(status:TweenStatus)

返回值 Bool (是否成功启动新 Tween)

示例代码

调用 EUINodeBase:TweenOpacity 的示例。

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local euiNodeBase = World:CreateUnit("EUINodeBase", { Parent = rootNode })
local endOpacity = 0.0  -- Float
local easingDirection = Enums.EasingDirection.In  -- EasingDirection
local easingStyle = Enums.EasingStyle.Linear  -- EasingStyle
local time = 1.0  -- Float
local override = false  -- Bool
local callback = function() end  -- Function
local result = euiNodeBase:TweenOpacity(endOpacity, easingDirection, easingStyle, time, override, callback)  -- 返回 Bool
if result then
    print("调用结果为 true")
else
    print("调用结果为 false")
end

Retain ​

签名:Retain() -> void

EUINodeBase 的无参数方法 Retain,调用时不接收参数也不返回结果。

返回值 void

示例代码

在异步使用期间保留节点并成对释放

lua
-- @runtime client
local player = game:GetService('Players').LocalPlayer
if player == nil or player.PlayerGui == nil then return end
local manager = player.PlayerGui.EuiManager
if manager == nil then return end
local root = manager:GetRootNode()
if root == nil then return end
local node = game:GetService('World'):CreateUnit('EUINodeBase', { Parent = root })
if node == nil then return end
node:Retain()
game:GetService("Task"):Delay(1, function()
    print("异步读取节点路径:", node:GetFullPath())
    node:Release()
end)

Release ​

签名:Release() -> void

EUINodeBase 的无参数方法 Release,调用时不接收参数也不返回结果。

⚙ Release 必须与此前成功执行的 Retain 成对调用;不要在未 Retain 的节点上单独调用。

返回值 void

示例代码

释放此前保留的节点引用

lua
-- @runtime client
local player = game:GetService('Players').LocalPlayer
if player == nil or player.PlayerGui == nil then return end
local manager = player.PlayerGui.EuiManager
if manager == nil then return end
local root = manager:GetRootNode()
if root == nil then return end
local node = game:GetService('World'):CreateUnit('EUINodeBase', { Parent = root })
if node == nil then return end
node:Retain()
print('节点路径:', node:GetFullPath())
node:Release()

GetWorldPosition ​

签名:GetWorldPosition() -> Vector2 (世界坐标)

GetWorldPosition 是 EUINodeBase 的成员函数(标题为“获取世界坐标”),无需参数,返回该节点在世界坐标系下的 Vector2 位置。

返回值 Vector2 (世界坐标)

示例代码

调用 EUINodeBase:GetWorldPosition 的示例。

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local euiNodeBase = World:CreateUnit("EUINodeBase", { Parent = rootNode })
local result = euiNodeBase:GetWorldPosition()  -- 返回 Vector2
if result ~= nil then
    print(result)
    local resultText = tostring(result)
    print(resultText)
end

ConvertToWorldPosition ​

签名:ConvertToWorldPosition(localPos: Vector2) -> Vector2 (世界坐标)

ConvertToLocalPosition 的对应函数,ConvertToWorldPosition 是 EUINodeBase 的成员函数(标题为“局部坐标转世界坐标”),接收一个 Vector2 局部坐标,返回转换后的 Vector2 世界坐标。

参数类型说明
localPosVector2局部坐标

返回值 Vector2 (世界坐标)

示例代码

调用 EUINodeBase:ConvertToWorldPosition 的示例。

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local euiNodeBase = World:CreateUnit("EUINodeBase", { Parent = rootNode })
local localPos = Vector2.New(0, 0)  -- Vector2
local result = euiNodeBase:ConvertToWorldPosition(localPos)  -- 返回 Vector2
if result ~= nil then
    print(result)
    local resultText = tostring(result)
    print(resultText)
end

ConvertToLocalPosition ​

签名:ConvertToLocalPosition(worldPos: Vector2) -> Vector2 (局部坐标)

ConvertToLocalPosition 是 EUINodeBase 的成员函数(标题为“世界坐标转局部坐标”),接收一个 Vector2 世界坐标,返回转换后的 Vector2 局部坐标。

参数类型说明
worldPosVector2世界坐标

返回值 Vector2 (局部坐标)

示例代码

调用 EUINodeBase:ConvertToLocalPosition 的示例。

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local euiNodeBase = World:CreateUnit("EUINodeBase", { Parent = rootNode })
local worldPos = Vector2.New(0, 0)  -- Vector2
local result = euiNodeBase:ConvertToLocalPosition(worldPos)  -- 返回 Vector2
if result ~= nil then
    print(result)
    local resultText = tostring(result)
    print(resultText)
end

HitTest ​

签名:HitTest(pos: Vector2) -> Bool (是否命中)

HitTest 是 EUINodeBase 的成员函数(标题为“碰撞检测”),接收一个 Vector2 坐标并返回 Bool,表示该坐标是否命中此节点。

参数类型说明
posVector2世界坐标

返回值 Bool (是否命中)

示例代码

调用 EUINodeBase:HitTest 的示例。

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local euiNodeBase = World:CreateUnit("EUINodeBase", { Parent = rootNode })
local pos = Vector2.New(0, 0)  -- Vector2
local result = euiNodeBase:HitTest(pos)  -- 返回 Bool
if result then
    print("调用结果为 true")
else
    print("调用结果为 false")
end