主题
EUIEffect
概览
| 字段 | 值 |
|---|---|
| Kind | Unit · 单位 Unit |
| Realm | common |
继承关系
- Unit(4 属性 / 25 函数 / 6 事件)
- EUINodeBase(34 属性 / 8 函数 / 4 事件)
- [EUIEffect](3 属性 / 2 函数)
- 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
- 属性:
EUIEffect 是用于在 UI 中播放动效的节点,支持设置动效资源、控制播放与停止,并可配置循环播放和尺寸。
适用场景
常用于在界面中展示动态特效,例如按钮点击反馈、加载动画或装饰性动效。
使用要点
通过 World:CreateUnit("EUIEffect", { Parent = parentNode, Position = Vector2.New(0, 0), Size = Vector2.New(100, 40) }) 创建实例,设置 EffectId 指定动效资源,调用 PlayAnimation 开始播放,需要停止时调用 StopAnimation。
注意事项
实例必须通过 World:CreateUnit 创建并指定父节点,不能直接使用 New 构造。动效资源 ID 需为有效值,否则可能无法正常显示。
代码示例
创建 UI 动效并播放
lua
-- @runtime client
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
if localPlayer == nil then return end
local rootNode = localPlayer.PlayerGui.EuiManager:GetRootNode()
local World = game:GetService("World")
local function createAndPlayEffect(effectId)
if type(effectId) ~= "number" then return nil end
local effect = World:CreateUnit("EUIEffect", {
Parent = rootNode,
Position = Vector2.New(0, 0),
Size = Vector2.New(100, 40),
EffectId = effectId,
LoopPlay = true,
})
effect:PlayAnimation()
game:GetService("Task"):Delay(5, function()
effect:StopAnimation()
effect:Destroy()
end)
return effect
end
-- 调用方把项目配置中的真实动效 ID 传给 createAndPlayEffect属性 (3)
| Name | 类型 | 默认值 | 说明 |
|---|---|---|---|
LoopPlay | Bool | true | 控制动效是否循环播放。 |
EffectId | Int | 1 | 动效资源的标识符,用于指定 EUIEffect 节点播放的动效。 |
Size | Vector2 | [164, 164] | 特效节点的尺寸,以像素为单位。 |
关联类型
函数 (2)
PlayAnimation
签名:PlayAnimation() -> void
开始播放当前 EffectId 指定的动效。
返回值 void
示例代码
播放当前 EffectId 指定的 UI 动效
lua
-- @runtime client
local function playEffect(effect)
if effect == nil then return end
effect:PlayAnimation()
endStopAnimation
签名:StopAnimation() -> void
停止当前正在播放的动效。
返回值 void
示例代码
停止正在播放的 UI 动效
lua
-- @runtime client
local function stopEffect(effect)
if effect == nil then return end
effect:StopAnimation()
end