Skip to content

EUILoadingBar

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

  • Unit(4 属性 / 25 函数 / 6 事件)
    • EUINodeBase(34 属性 / 8 函数 / 4 事件)
      • [EUILoadingBar](4 属性)

继承成员

2 个来源 / 38 属性 / 33 函数 / 10 事件

EUILoadingBar 是用于显示进度或加载状态的 UI 控件,通过设置 Percent 属性控制进度条的填充比例。它支持自定义进度条图片和颜色,并可指定填充方向。

适用场景

常用于显示任务完成进度、资源加载进度或玩家经验值进度,例如在界面中展示下载进度或技能冷却进度。

使用要点

通过 World:CreateUnit 创建实例,将 Parent 设置为当前玩家的 PlayerGui.EuiManager:GetRootNode(),然后设置 Position、Size 等布局属性。通过修改 Percent 属性(0-100 的浮点数)更新进度,并可设置 Image 和 Color 自定义外观。

注意事项

EUILoadingBar 通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()(不能通过 GetService 获取 EUIManager)。Color 类型必须用 0-255 RGBA 四参数构造(如 Color.New(255, 0, 0, 255)),不能用 0-1 归一化值。Percent 是 0-100 范围的 Float 百分比(如 50.0 表示 50%),不是 0-1 比例。Direction 是 Int 方向标识,不是 Enums.EasingDirection;Image 的公开类型是 String。

代码示例

创建加载条并设置进度

lua
-- @runtime client
local function createLoadingBar(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("EUILoadingBar", {
        Parent = rootNode,
        Position = Vector2.New(0, 0),
        Size = Vector2.New(100, 40),
        Image = imageUri,
        Percent = 60.0,
        Color = Color.New(80, 180, 255, 255),
        Direction = 1,
    })
end

属性 (4)

Name类型默认值说明
PercentFloat0.5默认值
ImageStringofficial://image/30011加载条使用的图片资源 URI。
DirectionInt0 (Normal)加载条的填充方向,整数值表示不同的方向模式。
ColorColor[255, 255, 255, 255]加载条填充区域的颜色,使用 Color 类型表示 RGBA 值。

关联类型