主题
EUINodeBase
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(5 属性 / 28 函数 / 6 事件)
- [EUINodeBase](35 属性 / 13 函数 / 4 事件)
- EUIButton(13 属性)
- EUIClippingNode(4 属性)
- EUIEffect(3 属性 / 2 函数)
- EUIGridLayout(10 属性 / 1 函数)
- EUIImage(4 属性)
- EUIInputField(16 属性 / 1 事件)
- EUIJoystick(2 属性 / 1 事件)
- EUILayout(1 属性)
- EUIListLayout(8 属性 / 1 函数)
- EUIListView(8 属性 / 3 函数)
- EUILoadingBar(4 属性)
- EUIProgressTimer(4 属性)
- EUIRichTextLabel(31 属性)
- EUIRootNode
- EUISceneNode(5 属性 / 1 函数)
- EUISimpleRichTextLabel(21 属性)
- EUISlider(18 属性 / 4 事件)
- EUITableLayout(6 属性 / 1 函数)
- EUITextLabel(15 属性)
- [EUINodeBase](35 属性 / 13 函数 / 4 事件)
继承成员
1 个来源 / 5 属性 / 26 函数 / 6 事件
- 来自 Unit(5 属性 / 28 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent、Tags - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetDebugId、HasTag、AddTag、RemoveTag - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
界面节点基类,集中提供所有界面节点的公共外观与交互能力:可见性、坐标、锚点、尺寸、旋转、透明度、缩放、层级与布局序号,以及四边与锚点的自适应模式和触摸音效、事件名绑定。它同时封装了补间动画方法(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 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Visible | Bool | true | EUINodeBase 的是否可见属性,类型为 Bool,用于控制节点是否显示。 |
Position | Vector2 | [0, 0] | Position 是 EUINodeBase 上的 Vector2 类型属性,用于表示节点在父节点坐标系中的位置,默认值为 (0, 0)。 |
Anchor | Vector2 | [0.5, 0.5] | Anchor 是 EUINodeBase 上的 Vector2 类型属性,用于表示节点自身的锚点,即节点在定位时作为对齐基准的那个点,默认值为 (0.5, 0.5)。 |
FlippedX | Bool | false | EUINodeBase 的横向反转开关,类型为 Bool,用于标记节点是否沿横向翻转。 |
FlippedY | Bool | false | EUINodeBase 的纵向反转开关,类型为 Bool,用于标记节点是否沿纵向翻转。 |
Size | Vector2 | [0, 0] | 节点的显示尺寸。 |
Rotation | Float | 0.0 | EUINodeBase 的旋转属性,类型为 Float,以数值表示节点的旋转量。 |
Opacity | Float | 1.0 | EUINodeBase 的透明度属性,类型为 Float,以数值表示节点的透明程度。 |
TouchBeginAudio | String | "" | EUINodeBase 的按下音效属性,类型为 String,用于保存按下操作对应的音效标识。 |
TouchEndAudio | String | "" | EUINodeBase 的抬起音效属性,类型为 String,用于保存抬起操作对应的音效标识。 |
TouchClickAudio | String | "" | EUINodeBase 的点击音效属性,类型为 String,用于保存点击操作对应的音效标识。 |
TouchbeginEvent | String | "" | EUINodeBase 的触摸开始事件属性,类型为 String,用于保存与触摸开始关联的事件标识。 |
ClickEvent | String | "" | EUINodeBase 的点击事件属性,类型为 String,用于保存与点击关联的事件标识。 |
TouchendEvent | String | "" | EUINodeBase 的触摸结束事件属性,类型为 String,用于保存与触摸结束关联的事件标识。 |
LongtouchEvent | String | "" | EUINodeBase 的长按事件属性,类型为 String,用于保存与长按行为关联的事件标识。 |
ShowEvent | String | "" | EUINodeBase 的显示事件属性,类型为 String,用于保存与显示行为关联的事件标识。 |
HideEvent | String | "" | EUINodeBase 的隐藏事件属性,类型为 String,用于保存与隐藏行为关联的事件标识。 |
TouchEnabled | Bool | false | EUINodeBase 的是否可触摸属性,类型为 Bool,用于标记节点是否接收触摸操作。 |
TouchDragEnabled | Bool | false | TouchDragEnabled 是 EUINodeBase 上的 Bool 类型属性,用于表示该节点是否允许拖动,默认值为 false。 |
SwallowTouchEnabled | Bool | true | EUINodeBase 的是否吞噬触摸属性,类型为 Bool,用于标记节点是否吞掉触摸输入。 |
TopAdaptMode | EUIAdaptMode | Enums.EUIAdaptMode.None | EUINodeBase 的顶部自适应模式属性,类型为 EUIAdaptMode,用于指定顶边的自适应方式。 |
TopAdaption | Float | 0.0 | EUINodeBase 的顶部自适应量属性,类型为 Float,用于配合 TopAdaptMode 描述顶边的适配数值。 |
BottomAdaptMode | EUIAdaptMode | Enums.EUIAdaptMode.None | EUINodeBase 的底部自适应模式属性,类型为 EUIAdaptMode,用于指定底边的自适应方式。 |
BottomAdaption | Float | 0.0 | EUINodeBase 的底部自适应量属性,类型为 Float,用于配合 BottomAdaptMode 描述底边的适配数值。 |
LeftAdaptMode | EUIAdaptMode | Enums.EUIAdaptMode.None | EUINodeBase 的左边自适应模式属性,类型为 EUIAdaptMode,用于指定左边的自适应方式。 |
LeftAdaption | Float | 0.0 | EUINodeBase 的左边自适应量属性,类型为 Float,用于配合 LeftAdaptMode 描述左边的适配数值。 |
RightAdaptMode | EUIAdaptMode | Enums.EUIAdaptMode.None | EUINodeBase 的右边自适应模式属性,类型为 EUIAdaptMode,用于指定右边的自适应方式。 |
RightAdaption | Float | 0.0 | EUINodeBase 的右边自适应量属性,类型为 Float,用于配合 RightAdaptMode 描述右边的适配数值。 |
AnchorXAdaptMode | EUIAnchorAdaptMode | Enums.EUIAnchorAdaptMode.None | EUINodeBase 的锚点 X 自适应模式属性,类型为 EUIAnchorAdaptMode,用于指定锚点在横向上的自适应方式。 |
AnchorXAdaption | Float | - | EUINodeBase 的锚点 X 自适应量属性,类型为 Float,用于配合 AnchorXAdaptMode 描述横向锚点的适配数值。 |
AnchorYAdaptMode | EUIAnchorAdaptMode | Enums.EUIAnchorAdaptMode.None | EUINodeBase 的锚点 Y 自适应模式属性,类型为 EUIAnchorAdaptMode,用于指定锚点在纵向上的自适应方式。 |
AnchorYAdaption | Float | - | EUINodeBase 的锚点 Y 自适应量属性,类型为 Float,用于配合 AnchorYAdaptMode 描述纵向锚点的适配数值。 |
LocalZOrder | Int | 0 | EUINodeBase 的层级序号属性,类型为 Int,用于描述节点在同一父级中的层级顺序。 |
LayoutOrder | Int | 0 | EUINodeBase 的布局序号属性,类型为 Int,用于给节点在自动布局中提供排序依据。 |
Scale | Vector2 | [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 的节点。注册回调本身不代表触摸行为已验证。
| 回调参数 | 类型 | 说明 |
|---|---|---|
euiTouchInfo | EUITouchInfo | 交互参数 |
player | Player | 玩家 |
示例代码
启用交互后监听 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 的节点。注册回调本身不代表触摸行为已验证。
| 回调参数 | 类型 | 说明 |
|---|---|---|
euiTouchInfo | EUITouchInfo | 交互参数 |
player | Player | 玩家 |
示例代码
启用交互后监听 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 的节点。注册回调本身不代表触摸行为已验证。
| 回调参数 | 类型 | 说明 |
|---|---|---|
euiTouchInfo | EUITouchInfo | 交互参数 |
player | Player | 玩家 |
示例代码
启用交互后监听 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 的节点。注册回调本身不代表触摸行为已验证。
| 回调参数 | 类型 | 说明 |
|---|---|---|
player | Player | 玩家 |
示例代码
启用交互后监听 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? | Bool | true 递归克隆全部子节点,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())
endGetFullPath
签名: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
endTweenPosition
签名:TweenPosition(endPosition: Vector2, easingDirection: EasingDirection, easingStyle: EasingStyle, time: Float, override: Bool, callback: Function) -> Bool (是否成功启动新 Tween)
在指定时长内将 EUINodeBase 派生界面节点的 Position 过渡到目标位置 endPosition(Vector2)。需要传入缓动方向、缓动样式、时长、覆盖开关与结束回调,返回 Bool 表示是否成功启动新的 Tween。
| 参数 | 类型 | 说明 |
|---|---|---|
endPosition | Vector2 | 目标位置(绝对像素) |
easingDirection | EasingDirection | 缓动方向(默认 Out) |
easingStyle | EasingStyle | 缓动样式(默认 Quad) |
time | Float | 时长(秒,默认 1) |
override | Bool | 是否抢占同通道旧 Tween(默认 false) |
callback | Function | 完成或被抢占时触发的回调(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。
| 参数 | 类型 | 说明 |
|---|---|---|
endSize | Vector2 | 目标尺寸(绝对像素) |
easingDirection | EasingDirection | 缓动方向(默认 Out) |
easingStyle | EasingStyle | 缓动样式(默认 Quad) |
time | Float | 时长(秒,默认 1) |
override | Bool | 是否抢占同通道旧 Tween(默认 false) |
callback | Function | 完成或被抢占时触发的回调(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。
| 参数 | 类型 | 说明 |
|---|---|---|
endSize | Vector2 | 目标尺寸(绝对像素) |
endPosition | Vector2 | 目标位置(绝对像素) |
easingDirection | EasingDirection | 缓动方向(默认 Out) |
easingStyle | EasingStyle | 缓动样式(默认 Quad) |
time | Float | 时长(秒,默认 1) |
override | Bool | 是否抢占 Pos/Size 两通道旧 Tween(默认 false) |
callback | Function | 完成或被抢占时触发的回调(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。
| 参数 | 类型 | 说明 |
|---|---|---|
endOpacity | Float | 目标透明度(0~1) |
easingDirection | EasingDirection | 缓动方向(默认 Out) |
easingStyle | EasingStyle | 缓动样式(默认 Quad) |
time | Float | 时长(秒,默认 1) |
override | Bool | 是否抢占 Opacity 通道旧 Tween(默认 false) |
callback | Function | 完成或被抢占时触发的回调(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")
endRetain
签名: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)
endConvertToWorldPosition
签名:ConvertToWorldPosition(localPos: Vector2) -> Vector2 (世界坐标)
ConvertToLocalPosition 的对应函数,ConvertToWorldPosition 是 EUINodeBase 的成员函数(标题为“局部坐标转世界坐标”),接收一个 Vector2 局部坐标,返回转换后的 Vector2 世界坐标。
| 参数 | 类型 | 说明 |
|---|---|---|
localPos | Vector2 | 局部坐标 |
返回值 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)
endConvertToLocalPosition
签名:ConvertToLocalPosition(worldPos: Vector2) -> Vector2 (局部坐标)
ConvertToLocalPosition 是 EUINodeBase 的成员函数(标题为“世界坐标转局部坐标”),接收一个 Vector2 世界坐标,返回转换后的 Vector2 局部坐标。
| 参数 | 类型 | 说明 |
|---|---|---|
worldPos | Vector2 | 世界坐标 |
返回值 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)
endHitTest
签名:HitTest(pos: Vector2) -> Bool (是否命中)
HitTest 是 EUINodeBase 的成员函数(标题为“碰撞检测”),接收一个 Vector2 坐标并返回 Bool,表示该坐标是否命中此节点。
| 参数 | 类型 | 说明 |
|---|---|---|
pos | Vector2 | 世界坐标 |
返回值 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