Skip to content

EUIEffect ​

概览 ​

字段值
KindUnit · 单位 Unit
Realmcommon

继承关系 ​

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

继承成员 ​

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

EUIEffect 是用于在界面上播放动效的单位类型,动效资源由 EffectId 指定,显示尺寸由 Size 控制,LoopPlay 决定是否循环播放。它提供 PlayAnimation 与 StopAnimation 两个方法用于启动和停止动效,适合承担界面装饰、状态反馈等视觉表现。

适用场景 ​

当需要在玩家界面上播放一段动效时,可以创建 EUIEffect 并挂载到 EuiManager 的根节点下,配置好 EffectId 与 Size 后调用 PlayAnimation 播放,在需要结束时调用 StopAnimation 停止。

使用要点 ​

先通过 game:GetService("World"):CreateUnit("EUIEffect", {...}) 创建实例,并在配置中把 Parent 指向 game:GetService("Players").LocalPlayer.PlayerGui.EuiManager:GetRootNode() 之类的界面节点,同时给出 Position、Size 与 EffectId。实例创建完成后调用 PlayAnimation 开始播放动效,并由 LoopPlay 决定是否为循环播放,需要结束时调用 StopAnimation。

注意事项 ​

通过 World:CreateUnit 创建 EUIEffect 并挂载到界面节点;EffectId、Size、LoopPlay 分别控制动效资源、尺寸与循环播放,使用公开的 PlayAnimation 和 StopAnimation 控制启停。

代码示例 ​

创建 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类型默认值说明
LoopPlayBooltrueEUIEffect 实例的循环播放开关,用布尔值控制动效是否重复播放。
EffectIdInt1EUIEffect 实例的动效 ID,用整数标识该实例所使用的动效资源。
SizeVector2[164, 164]EUIEffect 的 Size 属性,类型为 Vector2,用于表示该 UI 特效的尺寸。它属于 EUIEffect 实例的公开属性,在特效创建配置中作为一项可写入的字段存在,创建完成后也可通过实例读取该属性的当前取值。

关联类型 ​

函数 (2) ​

PlayAnimation ​

签名:PlayAnimation() -> void

播放 EUIEffect 实例所绑定动效的动画,使该 UI 动效进入播放状态。

返回值 void

示例代码

播放当前 EffectId 指定的 UI 动效

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

StopAnimation ​

签名:StopAnimation() -> void

停止 EUIEffect 实例当前正在播放的动画。

返回值 void

示例代码

停止正在播放的 UI 动效

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