Skip to content

EUIImage ​

概览 ​

字段值
KindUnit · 单位 Unit
Realmcommon

继承关系 ​

  • Unit(4 属性 / 25 函数 / 6 事件)
    • EUINodeBase(35 属性 / 12 函数 / 4 事件)
      • [EUIImage](4 属性)

继承成员 ​

2 个来源 / 39 属性 / 36 函数 / 10 事件

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类型默认值说明
StretchAreaVector4[0, 0, 0, 0]图片的拉伸区域,使用 Vector4 表示九宫格边距。
ColorColor[255, 255, 255, 255]图片的整体着色,使用 Color 类型表示颜色和透明度。
ImageStringofficial://image/10000图片资源标识,公开类型为 String;在 CreateUnit config 中使用 official://image/... 或项目支持的 custom://... Asset 协议字符串。
StretchAreaPercentEnabledBooltrue控制 StretchArea 的边距值是否按百分比计算。

关联类型 ​