From f900853952635a6e82e24fe62548d171823afda0 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 1 Sep 2021 17:47:20 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E7=B2=92=E5=AD=90=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=9C=A8=E7=BC=96=E8=BE=91=E5=99=A8=E4=B8=8B=E7=9A=84=E6=92=AD?= =?UTF-8?q?=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ActionTool/Editor/ActionData.cs | 77 ++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 7 deletions(-) (limited to 'Assets/ActionTool/Editor/ActionData.cs') diff --git a/Assets/ActionTool/Editor/ActionData.cs b/Assets/ActionTool/Editor/ActionData.cs index 2c75ad92..5e519c3e 100644 --- a/Assets/ActionTool/Editor/ActionData.cs +++ b/Assets/ActionTool/Editor/ActionData.cs @@ -23,6 +23,7 @@ namespace ActionTool private TimelineEventProxy m_TimelineEventProxy; private static List m_Projectiles = new List(); + private static List m_ParticleSystems = new List(); #region metadata private float m_TotalFrame; //timeline采样的总帧数 @@ -90,6 +91,7 @@ namespace ActionTool m_TimelineEventProxy = new TimelineEventProxy(animator.gameObject.transform); m_TimelineEventProxy.isInEditMode = true; m_TimelineEventProxy.registerProjectile = RegisterProjectile; + m_TimelineEventProxy.registerParticleSystem = RegisterParticleSystem; } public void SetCurrentAnimTime(float time) @@ -158,9 +160,11 @@ namespace ActionTool public void UpdateFrame() { + float dt = (float)(EditorApplication.timeSinceStartup - m_PrevLocalTime); + if (ActionManager.IsPlay) { - float deltaFrame = (float)(EditorApplication.timeSinceStartup - m_PrevLocalTime) * (ActionManager.FPS * ActionManager.Speed); + float deltaFrame = dt * ActionManager.FPS * ActionManager.Speed; if (applyCurve) { @@ -184,12 +188,9 @@ namespace ActionTool m_CurAnimFrame %= m_TotalFrame; } - for (int i = 0; i < m_Projectiles.Count; ++i) - { - if (m_Projectiles[i] == null) - continue; - m_Projectiles[i].Update((float)(EditorApplication.timeSinceStartup - m_PrevLocalTime)); - } + UpdateParticles(dt); + + UpdateProjectiles(dt); ActionManager.gizmos.SetCurAnimFrame(m_CurAnimFrame); @@ -304,6 +305,68 @@ namespace ActionTool m_Projectiles.Add(projectile); } + public static void RegisterParticleSystem(FxClear vfx) + { + m_ParticleSystems.Add(vfx); + } + + void UpdateProjectiles(float dt) + { + List removed = ListPool.Get(); + // 更新projectile + for (int i = 0; i < m_Projectiles.Count; ++i) + { + if (m_Projectiles[i] == null) + continue; + m_Projectiles[i].Update(dt); + if (m_Projectiles[i] != null) + { + TransformEx.DoRecursively(m_Projectiles[i].transform, (t) => { + ParticleSystem ps = t.GetComponent(); + if (ps != null) + { + ps.Simulate(m_Projectiles[i].time); + } + }, true); + } + else + { + removed.Add(m_Projectiles[i]); + } + } + ListPool.Release(removed); + } + + void UpdateParticles(float dt) + { + List removed = ListPool.Get(); + // 更新粒子系统 + for (int i = 0; i < m_ParticleSystems.Count; ++i) + { + if (m_ParticleSystems[i] == null) + continue; + if (m_ParticleSystems[i] != null) + { + m_ParticleSystems[i].UpdateFunc(dt); + if (m_ParticleSystems[i] != null) + { + TransformEx.DoRecursively(m_ParticleSystems[i].transform, (t) => { + ParticleSystem ps = t.GetComponent(); + if (ps != null) + { + ps.Simulate(m_ParticleSystems[i].time); + } + }, true); + } + else + { + removed.Add(m_ParticleSystems[i]); + } + } + } + ListPool.Release(removed); + } + } } -- cgit v1.1-26-g67d0