Bootstrap

Unity设置粒子系统的播放进度

ParticleSystem.Simulate

Fast-forwards the Particle System by simulating particles over the given period of time, then pauses it.

local ParticleUtil ={}

---设置物体上的粒子系统播放进度
function ParticleUtil:play_at_time(gameobject,time)
    ---@type UnityEngine.ParticleSystem[]
    local particles =gameobject:GetAllComponents(CS.Types.ParticleSystem)
    for _, particle in ipairs(particles) do
        --第一个参数 粒子要从第几秒开始播
        --第二个参数 是否播放子物体上的粒子系统
        --第三个参数 是否重新开始播放
        --第四个参数 是否在fixedTime中更新
        --模拟到指定时间
        particle:Simulate(time,false,true)
        --调用PLay继续播放
        particle:Play(false)
    end
end

return ParticleUtil

参考文档:

https://docs.unity3d.com/ScriptReference/ParticleSystem.Simulate.html

;