Skip to content

EUIEffect

概览

字段
KindUnit · 单位 Unit
Realmcommon

继承关系

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

继承成员

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

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类型默认值说明
LoopPlayBooltrue控制动效是否循环播放。
EffectIdInt1动效资源的标识符,用于指定 EUIEffect 节点播放的动效。
SizeVector2[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()
end

StopAnimation

签名:StopAnimation() -> void

停止当前正在播放的动效。

返回值 void

示例代码

停止正在播放的 UI 动效

lua
-- @runtime client
local function stopEffect(effect)
    if effect == nil then return end
    effect:StopAnimation()
end