主题
EUILoadingBar
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUILoadingBar](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
- 属性:
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 | 类型 | 默认值 | 说明 |
|---|---|---|---|
Percent | Float | 0.5 | 默认值 |
Image | String | official://image/30011 | 加载条使用的图片资源 URI。 |
Direction | Int | 0 (Normal) | 加载条的填充方向,整数值表示不同的方向模式。 |
Color | Color | [255, 255, 255, 255] | 加载条填充区域的颜色,使用 Color 类型表示 RGBA 值。 |
