主题
EUILoadingBar
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(35 属性 / 12 函数 / 4 事件)
- [EUILoadingBar](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
- 属性:
EUILoadingBar 是挂载在玩家 EUI 树上的进度条节点,通过 Percent、Image、Direction 与 Color 控制进度数值和显示样式。
适用场景
在进入地图后加载资源、等待场景就绪或执行分阶段初始化时,创建一个加载进度条挂到当前玩家界面根节点上,随完成度持续更新 Percent;当需要从满到空反向显示时,把 Direction 设为 Enums.EUIProgressDirection.Reverse。
使用要点
先通过 game:GetService("Players") 取得 Players,用 Players.LocalPlayer 拿到本地玩家,再调用 localPlayer.PlayerGui.EuiManager:GetRootNode() 取得界面根节点;随后执行 game:GetService("World"):CreateUnit("EUILoadingBar", { Parent = rootNode }) 创建实例。实例到手后按进度写入 Percent,并按需赋值 Image、Direction(Enums.EUIProgressDirection.Normal 或 Enums.EUIProgressDirection.Reverse)以及 Color。
注意事项
EUILoadingBar 通过 World:CreateUnit 创建,并把 Parent 设置为当前玩家 PlayerGui.EuiManager:GetRootNode()。Percent 的 Meta 类型是 Float、默认值为 0.5,Meta 未声明取值区间;示例数值仅展示赋值方式。Direction 使用 Enums.EUIProgressDirection.Normal/Reverse;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 = Enums.EUIProgressDirection.Reverse,
})
end
local loadingBar = createLoadingBar('official://image/30011')
if loadingBar == nil then return end
print('加载条已创建:', loadingBar.Name)属性 (4)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
Percent | Float | 0.5 | EUILoadingBar 的 Percent 属性,类型为浮点数,用于表示进度条当前的进度比例。 |
Image | String | official://image/30011 | EUILoadingBar 的 Image 属性,类型为字符串,用于指定进度条所使用的图片。 |
Direction | EUIProgressDirection | Enums.EUIProgressDirection.Normal | EUILoadingBar(加载条)的 Direction 属性,用于控制加载条进度的推进方向,取值类型为枚举 EUIProgressDirection,该枚举包含 Normal 与 Reverse 两个取值。 |
Color | Color | [255, 255, 255, 255] | EUILoadingBar(加载条)的 Color 属性,用于指定加载条的显示颜色,取值类型为 Color,该类型包含 r、g、b、a 四个分量,其中 a 表示透明度。该属性在 Meta 中声明的默认取值为 (255, 255, 255, 255)。 |
