Skip to content

EUINodeBase ​

概览 ​

字段值
KindUnit · 单位 Unit
Realmcommon

继承关系 ​

继承成员 ​

1 个来源 / 5 属性 / 26 函数 / 6 事件

界面节点基类,集中提供所有界面节点的公共外观与交互能力:可见性、坐标、锚点、尺寸、旋转、透明度、缩放、层级与布局序号,以及四边与锚点的自适应模式和触摸音效、事件名绑定。它同时封装了补间动画方法(TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity)、坐标换算(GetWorldPosition、ConvertToWorldPosition、ConvertToLocalPosition)和命中检测 HitTest,并对外派发本地触摸与点击事件。

适用场景 ​

在搭建界面时用它统一控制节点摆放与交互,例如创建一个图片节点挂到根节点下,设定位置与尺寸后通过 TweenOpacity 做淡入,并借助 OnClicked 响应玩家点击。

使用要点 ​

在客户端取得 Players.LocalPlayer 与 PlayerGui.EuiManager 的根节点,再用 World:CreateUnit 创建具体 EUI 子类(如 EUIImage、EUILayout),基类能力由子类继承;不要直接创建抽象基类。通过 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("EUIImage", {
    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 类型的触摸信息对象与 Player 类型的玩家对象。EUITouchInfo 提供 BeganPosition、MovedPosition、EndedPosition、TouchID 等属性,可用于读取本次触摸的起始位置与触点编号。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 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('EUIImage', {
    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 类型的触摸信息对象与 Player 类型的玩家对象。可通过 EUITouchInfo 的 MovedPosition 属性获取移动过程中的位置信息。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 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('EUIImage', {
    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 类型的触摸信息对象与 Player 类型的玩家对象。EUITouchInfo 提供 BeganPosition、MovedPosition、EndedPosition、TouchID 等属性,可用于读取本次触摸的结束位置。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 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('EUIImage', {
    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 类型的玩家对象,用于标识触发点击的玩家。

⚙ 需要客户端触摸输入;先准备有非零尺寸且 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('EUIImage', {
    Parent = root, Size = Vector2.New(160, 80), TouchEnabled = true,
})
if node == nil then return end
node.OnClicked:Once(function(player)
    print('OnClicked:', player)
end)

函数 (13) ​

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('EUIImage', { Parent = root })
if node == nil then return end
node:RemoveFromParent()

Clone ​

签名:Clone(deep?: Bool, parent?: EUINodeBase) -> EUINodeBase | nil (克隆出的节点)

克隆当前 EUINodeBase 节点,返回克隆出的节点实例。该函数接收两个可选参数:deep 用于指定是否深度克隆,parent 用于指定克隆结果的父节点。返回值为 EUINodeBase 类型,可能为空。

参数类型说明
deep?Booltrue 递归克隆全部子节点,false 只克隆当前节点;默认为 true
parent?EUINodeBase克隆出的节点挂载到的父节点;为空时使用当前节点的父节点

返回值 EUINodeBase | nil (克隆出的节点)

示例代码

深克隆 EUI 节点并挂载到指定父节点

lua
-- @runtime client
local Players = game:GetService("Players")
local World = game:GetService("World")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
-- 取得 EUI 根节点作为原节点与克隆节点的父节点
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local sourceNode = World:CreateUnit("EUIImage", { Parent = rootNode })
sourceNode.Position = Vector2.New(100, 100)
sourceNode.Size = Vector2.New(120, 60)
local clonedNode = sourceNode:Clone(true, rootNode)
if clonedNode ~= nil then
	-- 克隆节点是独立实例,可单独调整位置并读取路径确认来源
	clonedNode.Position = Vector2.New(100, 200)
	print("克隆节点路径:" .. clonedNode:GetFullPath())
end

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("EUIImage", { 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)

在指定时长内将 EUINodeBase 派生界面节点的 Position 过渡到目标位置 endPosition(Vector2)。需要传入缓动方向、缓动样式、时长、覆盖开关与结束回调,返回 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("EUIImage", {
    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)

在指定时长内将 EUINodeBase 派生界面节点的 Size 过渡到目标尺寸 endSize(Vector2)。调用需提供缓动方向、缓动样式、时长、覆盖开关与结束回调,返回 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("EUIImage", {
    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)

在同一个 Tween 中同时把 EUINodeBase 派生界面节点的 Size 过渡到 endSize、Position 过渡到 endPosition,两者使用相同的缓动方向、缓动样式与时长。函数返回 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("EUIImage", {
    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)

在指定时长内将 EUINodeBase 派生界面节点的 Opacity 属性过渡到目标值 endOpacity。调用时需同时给出缓动方向、缓动样式、时长、是否覆盖以及结束回调,函数返回 Bool 表示是否成功启动新的 Tween。

参数类型说明
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("EUIImage", { 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('EUIImage', { 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('EUIImage', { 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("EUIImage", { 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("EUIImage", { 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("EUIImage", { 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("EUIImage", { Parent = rootNode })
local pos = Vector2.New(0, 0)  -- Vector2
local result = euiNodeBase:HitTest(pos)  -- 返回 Bool
if result then
    print("调用结果为 true")
else
    print("调用结果为 false")
end