主题
EUIImage
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
- [EUIImage](4 属性)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
继承成员
2 个来源 / 39 属性 / 36 函数 / 10 事件
- 来自 EUINodeBase(35 属性 / 12 函数 / 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、GetFullPath、TweenPosition、TweenSize、TweenSizeAndPosition、TweenOpacity、Retain、Release、GetWorldPosition、ConvertToWorldPosition、ConvertToLocalPosition、HitTest - 事件:
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、GetDebugId - 事件:
ChildAdded、ChildRemoved、DescendantAdded、DescendantRemoving、AncestryChanged、Destroying
- 属性:
EUIImage 是运行在玩家界面上的图片控件,用于把一张图片资源绘制到 EUI 层级中。它通过 Image 指定图片、Color 设置整体染色,并用 StretchArea 与 StretchAreaPercentEnabled 定义拉伸区域,使图片在尺寸变化时按指定区域伸缩。
适用场景
适合在运行时动态构建玩家界面元素,例如为活动面板添加背景图、为功能入口配置底图,或在需要自适应尺寸的图片上启用拉伸区域。创建时把控件挂到当前玩家的 EUI 根节点下,即可直接显示在玩家界面上。
使用要点
先取到本地玩家 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 的边距值是否按百分比计算。 |
