主题
EUIImage
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(5 属性 / 28 函数 / 6 事件)
- EUINodeBase(35 属性 / 13 函数 / 4 事件)
- [EUIImage](4 属性)
- EUINodeBase(35 属性 / 13 函数 / 4 事件)
继承成员
2 个来源 / 40 属性 / 39 函数 / 10 事件
- 来自 EUINodeBase(35 属性 / 13 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、TouchDragEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、Clone、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release、GetWorldPosition、ConvertToWorldPosition、ConvertToLocalPosition、HitTest - 事件:
OnTouchBegan、OnTouchMoved、OnTouchEnded、OnClicked
- 属性:
- 来自 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
- 属性:
EUIImage 是 EUI 界面体系中的图片节点控件,用于在界面层级中展示图片资源。它提供 Image 指定图片地址,并通过 Color 对图片染色,借助 StretchArea 与 StretchAreaPercentEnabled 控制九宫格拉伸区域及其是否按百分比计算。
适用场景
常用于在玩家界面的根节点下创建图标、底图、边框或装饰性图层,例如为按钮或面板铺设背景图并调节染色与拉伸效果。
使用要点
先取到本地玩家 Players.LocalPlayer,再用 localPlayer.PlayerGui.EuiManager:GetRootNode() 获得界面根节点;接着调用 World:CreateUnit("EUIImage", { Parent = rootNode }) 创建实例,并在创建配置或创建完成后设置 Image、Color、StretchArea 等属性。StretchAreaPercentEnabled 是可读写属性,默认值为 true;写入它可切换 StretchArea 的百分比解释方式。
注意事项
EUI 控件通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()(不能自行直接构造,也不能通过 GetService 获取 EUIManager)。EUIImage.Image 的公开类型是 String,应在 CreateUnit config 中使用调用方提供的有效 Asset 协议字符串。
代码示例
创建 EUIImage 并使用 Asset 协议字符串
lua
-- @runtime client
local function createImage(imageUri)
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()
return World:CreateUnit("EUIImage", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
Image = imageUri,
Color = Color.New(255, 255, 255, 255),
})
end属性 (4)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
StretchArea | Vector4 | [0, 0, 0, 0] | 图片的拉伸区域,使用 Vector4 表示九宫格边距。 |
Color | Color | [255, 255, 255, 255] | 图片的整体着色,使用 Color 类型表示颜色和透明度。 |
Image | String | official://image/10000 | 图片资源标识,公开类型为 String;在 CreateUnit config 中使用 official://image/... 或项目支持的 custom://... Asset 协议字符串。 |
StretchAreaPercentEnabled | Bool | true | 控制 StretchArea 的边距值是否按百分比计算。 |
