diff options
author | chai <chaifix@163.com> | 2021-09-01 17:47:20 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-09-01 17:47:20 +0800 |
commit | f900853952635a6e82e24fe62548d171823afda0 (patch) | |
tree | 0d2c0bce3f7411c8ab61c13a5ade65bddbac6375 /Assets/ActionTool/Editor/ActionData.cs | |
parent | a93ea925263c23d5c08b5fca546eef81d6d4fec3 (diff) |
*修改粒子系统在编辑器下的播放
Diffstat (limited to 'Assets/ActionTool/Editor/ActionData.cs')
-rw-r--r-- | Assets/ActionTool/Editor/ActionData.cs | 77 |
1 files changed, 70 insertions, 7 deletions
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<Projectile> m_Projectiles = new List<Projectile>();
+ private static List<FxClear> m_ParticleSystems = new List<FxClear>();
#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<Projectile> removed = ListPool<Projectile>.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<ParticleSystem>();
+ if (ps != null)
+ {
+ ps.Simulate(m_Projectiles[i].time);
+ }
+ }, true);
+ }
+ else
+ {
+ removed.Add(m_Projectiles[i]);
+ }
+ }
+ ListPool<Projectile>.Release(removed);
+ }
+
+ void UpdateParticles(float dt)
+ {
+ List<FxClear> removed = ListPool<FxClear>.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<ParticleSystem>();
+ if (ps != null)
+ {
+ ps.Simulate(m_ParticleSystems[i].time);
+ }
+ }, true);
+ }
+ else
+ {
+ removed.Add(m_ParticleSystems[i]);
+ }
+ }
+ }
+ ListPool<FxClear>.Release(removed);
+ }
+
}
}
|