From 71e4aea762a1ab8ae5e998857708bd561a2318ce Mon Sep 17 00:00:00 2001 From: Sarbian Date: Tue, 7 Feb 2017 21:29:58 +0100 Subject: [PATCH] v2.7.2 Fix the performance issue of the color anim May require more investigation since the evaluate method may work with more setup/test --- ModelMultiShurikenPersistFX.cs | 23 +++++----------------- PersistentKSPShurikenEmitter.cs | 35 +++++++++++++++++++++++++++++++-- Properties/AssemblyInfo.cs | 4 ++-- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/ModelMultiShurikenPersistFX.cs b/ModelMultiShurikenPersistFX.cs index 8f8e319..a190699 100644 --- a/ModelMultiShurikenPersistFX.cs +++ b/ModelMultiShurikenPersistFX.cs @@ -627,27 +627,14 @@ public override void OnInitialize() ParticleSystem.ColorOverLifetimeModule col = particleSystem.colorOverLifetime; // This one is annoying. The old particle system animate the color over the whole % life of the particle (0 - 1) - // The new one animate it over time. So converted system may not reac the full value - // The animation is set up here but disabled and the color is manually set in the update of PersistentKSPShurikenEmitter with this gradient + // The new one animate it over time. So converted system may not reach the full value + // The color is manually set in the update of PersistentKSPShurikenEmitter col.enabled = false; - GradientColorKey[] colorKeys = new GradientColorKey[5]; - GradientAlphaKey[] alphaKeys = new GradientAlphaKey[5]; - Color[] colors = childKSPParticleEmitter.colorAnimation; - - float step = 1f / (colors.Length - 1); - - for (int t = 0; t < colors.Length; t++) - { - colorKeys[t] = new GradientColorKey(colors[t], 1 - t * step); - alphaKeys[t] = new GradientAlphaKey(colors[t].a, 1 - t * step); - } - - Gradient gradient = new Gradient(); - gradient.SetKeys(colorKeys, alphaKeys); - - col.color = new ParticleSystem.MinMaxGradient(gradient); + + pkpe.colors = new Color[colors.Length]; + Array.Copy(colors, pkpe.colors, colors.Length); } //try diff --git a/PersistentKSPShurikenEmitter.cs b/PersistentKSPShurikenEmitter.cs index b6a718d..ec00ffb 100644 --- a/PersistentKSPShurikenEmitter.cs +++ b/PersistentKSPShurikenEmitter.cs @@ -75,6 +75,7 @@ public class PersistentKSPShurikenEmitter public Vector3 rndForce; public Color color; public bool doesAnimateColor; + public Color[] colors; //private float emitterVelocityScale; private Vector3 rndVelocity; @@ -547,8 +548,38 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity) if (doesAnimateColor) { - float lifePercentage = (particle.lifetime / particle.startLifetime); - particle.startColor = pe.colorOverLifetime.color.Evaluate(lifePercentage); + float lifePercentage = 1 - (particle.lifetime / particle.startLifetime); + + float lerp; + Color a; + Color b; + if (lifePercentage < 0.25f) + { + a = colors[0]; + b = colors[1]; + lerp = lifePercentage * 4f; + } + else if (lifePercentage < 0.50f) + { + a = colors[1]; + b = colors[2]; + lerp = (lifePercentage - 0.25f) * 4f; + } + else if (lifePercentage < 0.75f) + { + a = colors[2]; + b = colors[3]; + lerp = (lifePercentage - 0.50f) * 4f; + } + else + { + a = colors[3]; + b = colors[4]; + lerp = (lifePercentage - 0.75f) * 4f; + } + + Color c = Color.Lerp(a, b, lerp); + particle.startColor = c; } } particles[j] = particle; diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index a05668f..7853e7e 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -34,5 +34,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.1.0")] -[assembly: AssemblyFileVersion("2.7.1.0")] +[assembly: AssemblyVersion("2.7.2.0")] +[assembly: AssemblyFileVersion("2.7.2.0")]