主题
EUIImage
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUIImage](4 属性)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
继承成员
2 个来源 / 38 属性 / 33 函数 / 10 事件
- 来自 EUINodeBase(34 属性 / 8 函数 / 4 事件)
- 属性:
Visible、Position、Anchor、FlippedX、FlippedY、Size、Rotation、Opacity、TouchBeginAudio、TouchEndAudio、TouchClickAudio、TouchbeginEvent、ClickEvent、TouchendEvent、LongtouchEvent、ShowEvent、HideEvent、TouchEnabled、SwallowTouchEnabled、TopAdaptMode、TopAdaption、BottomAdaptMode、BottomAdaption、LeftAdaptMode、LeftAdaption、RightAdaptMode、RightAdaption、AnchorXAdaptMode、AnchorXAdaption、AnchorYAdaptMode、AnchorYAdaption、LocalZOrder、LayoutOrder、Scale - 函数:
RemoveFromParent、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release - 事件:
OnTouchBegan、OnTouchMoved、OnTouchEnded、OnClicked
- 属性:
- 来自 Unit(4 属性 / 25 函数 / 6 事件)
- 属性:
AssetId、Name、Desc、Parent - 函数:
ClearAllChildren、GetChildren、GetDescendants、IsAncestorOf、IsDescendantOf、FindFirstAncestor、FindFirstAncestorWhichIsA、FindFirstAncestorOfClass、FindFirstChild、FindFirstChildWhichIsA、FindFirstChildOfClass、HasChildren、GetChildCount、GetChildAtIndex、SetAttribute、GetAttribute、GetAllProps、Clone、IsA、Destroy、GetPropertyChangedSignal、GetAttributeChangedSignal、FindFromPath、GetFullPath、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUIImage 是用于在界面中显示图片的 UI 控件,支持设置图片资源、颜色和拉伸区域。通过调整拉伸区域可以控制图片的九宫格缩放效果,适合制作按钮、图标、背景等界面元素。
适用场景
常用于制作界面按钮的背景图、物品图标或装饰性图片,通过设置 Image 属性加载官方或自定义图片资源,并结合拉伸区域实现自适应缩放。
使用要点
通过 World:CreateUnit 创建 EUIImage 实例,将 Parent 设置为当前玩家的 EUIRootNode,然后设置 Image 属性为有效的图片资源路径,并可调整 Color 和 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 类型定义(x、y、z、w 分别对应左、上、右、下边距),用于指定图片拉伸时保持边角不变形的区域。 |
Color | Color | [255, 255, 255, 255] | 图片的颜色叠加值,使用 Color 类型(包含 r、g、b、a 四个通道),用于对原始图片进行着色或透明度调整。 |
Image | String | official://image/10000 | 图片资源标识,公开类型为 String;在 CreateUnit config 中使用 official://image/... 或项目支持的 custom://... Asset 协议字符串。 |
StretchAreaPercentEnabled | Bool | true | 是否按百分比计算拉伸区域边距,布尔类型。为 true 时 StretchArea 的值为百分比(0-1),为 false 时为像素值。 |
