主题
EUINode
EUINode 对象 API 参考。EUINode 由 EUIService 方法返回(FindFirstChild、GetDescendants、CreateEUINode 等)。
概览
编辑器 UI 系统的节点对象,代表界面树中的一个控件单元,负责承载控件属性并提供层级访问能力。通过 GetProperty 与 SetProperty 可读写节点属性,借助 GetParent、GetChildren 与 GetDescendants 遍历节点树,FindFirstChild 可按名称定位子节点,Destroy 能将节点从树中移除。
不可实例化,由接口返回
函数
GetUnitType
签名:GetUnitType() -> String
获取当前节点的控件类型,返回值为类型名称字符串。
返回值 String — 控件类型
调用 GetUnitType
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local result = euiNode:GetUnitType() -- 返回 String
if result ~= nil then
print(result)
if result ~= "" then
print("返回了非空字符串")
end
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endGetName
签名:GetName() -> String
获取当前节点的名称,返回值类型为字符串。
返回值 String — 节点名称
调用 GetName
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local result = euiNode:GetName() -- 返回 String
if result ~= nil then
print(result)
if result ~= "" then
print("返回了非空字符串")
end
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endGetProperty
签名:GetProperty(name: String, default: Any?) -> Any
按属性名读取节点的内置属性值。可通过 default 参数指定属性不存在时返回的默认值。
| 参数 | 类型 | 说明 |
|---|---|---|
name | String | 属性名 |
default | Any | 默认值 |
返回值 Any — 属性值;属性不存在时返回默认值
调用 GetProperty
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local name = "default" -- String
local default = nil -- Any
local result = euiNode:GetProperty(name, default) -- 返回 Any
if result ~= nil then
print("调用成功,结果: " .. tostring(result))
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endSetProperty
签名:SetProperty(name: String, value: Any) -> Bool
按属性名设置节点的内置属性值,返回设置操作是否成功。
| 参数 | 类型 | 说明 |
|---|---|---|
name | String | 属性名 |
value | Any | 属性值 |
返回值 Bool — 是否设置成功
调用 SetProperty
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local name = "default" -- String
local value = nil -- Any
local result = euiNode:SetProperty(name, value) -- 返回 Bool
if result then
print("调用结果为 true")
else
print("调用结果为 false")
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endGetParent
签名:GetParent() -> EUINode
获取当前节点的父节点;节点没有父节点时返回 nil。
返回值 EUINode — 父节点;无父节点时返回 nil
调用 GetParent
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local result = euiNode:GetParent() -- 返回 EUINode
if result ~= nil then
print("调用成功,结果: " .. tostring(result))
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endSetParent
签名:SetParent(parent: EUINode?) -> Bool
设置节点的父节点,调整节点在界面层级中的归属关系,并返回设置是否成功。
| 参数 | 类型 | 说明 |
|---|---|---|
parent | EUINode | 父节点 |
返回值 Bool — 是否设置成功
调用 SetParent
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local parent = euiNode:GetParent()
local result = euiNode:SetParent(parent) -- 返回 Bool
if result then
print("调用结果为 true")
else
print("调用结果为 false")
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endGetChildren
签名:GetChildren() -> Array
获取当前节点的全部直接子节点,结果以数组形式返回。
返回值 Array — 直接子节点数组
调用 GetChildren
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local result = euiNode:GetChildren() -- 返回 Array
if result ~= nil then
for index, item in ipairs(result) do
print(index, item)
end
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endGetDescendants
签名:GetDescendants() -> Array
递归获取当前节点的所有后代节点,结果以数组形式返回。
返回值 Array — 所有后代节点数组
调用 GetDescendants
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local result = euiNode:GetDescendants() -- 返回 Array
if result ~= nil then
for index, item in ipairs(result) do
print(index, item)
end
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endFindFirstChild
签名:FindFirstChild(name: String) -> EUINode
在节点的直接子节点中查找第一个名称匹配的子节点;未找到时返回 nil。
| 参数 | 类型 | 说明 |
|---|---|---|
name | String | 名称 |
返回值 EUINode — 找到的子节点;未找到时返回 nil
调用 FindFirstChild
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local name = "default" -- String
local result = euiNode:FindFirstChild(name) -- 返回 EUINode
if result ~= nil then
print("调用成功,结果: " .. tostring(result))
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
euiNode:Destroy()
endDestroy
签名:Destroy() -> Bool
删除当前节点,并返回是否成功销毁。
返回值 Bool — 是否销毁成功
调用 Destroy
lua
-- @runtime client
local function demo(euiNode)
if euiNode ~= nil then
local result = euiNode:Destroy() -- 返回 Bool
if result then
print("调用结果为 true")
else
print("调用结果为 false")
end
end
end
local euiService = editor:GetService("EUIService")
local position = Vector2.New({x = 0, y = 0})
local size = Vector2.New({x = 120, y = 40})
local euiNode = euiService:CreateEUINode("EUIButton", nil, position, size, "DocumentationExampleNode")
if euiNode ~= nil then
demo(euiNode)
end