Skip to content

Commit

Permalink
Fix the Animation Color for converted Shiruken particle system
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Jan 21, 2017
1 parent c0d015b commit d0b5e09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ModelMultiShurikenPersistFX.cs
Expand Up @@ -620,10 +620,16 @@ public override void OnInitialize()

//particleSystemRenderer.alignment = ParticleSystemRenderSpace.View;

pkpe.doesAnimateColor = childKSPParticleEmitter.doesAnimateColor;

if (childKSPParticleEmitter.doesAnimateColor)
{
ParticleSystem.ColorOverLifetimeModule col = particleSystem.colorOverLifetime;
col.enabled = true;

// 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
col.enabled = false;

GradientColorKey[] colorKeys = new GradientColorKey[5];
GradientAlphaKey[] alphaKeys = new GradientAlphaKey[5];
Expand All @@ -634,8 +640,8 @@ public override void OnInitialize()

for (int t = 0; t < colors.Length; t++)
{
colorKeys[t] = new GradientColorKey(colors[t], t * step);
alphaKeys[t] = new GradientAlphaKey(colors[t].a, t * step);
colorKeys[t] = new GradientColorKey(colors[t], 1 - t * step);
alphaKeys[t] = new GradientAlphaKey(colors[t].a, 1 - t * step);
}

Gradient gradient = new Gradient();
Expand Down Expand Up @@ -971,7 +977,7 @@ public override void OnSave(ConfigNode node)

private static void Print(String s)
{
print("[SmokeScreen ModelMultiParticlePersistFX] " + s);
print("[SmokeScreen ModelMultiShurikenPersistFX] " + s);
}

// TODO : move the whole UI stuff to a dedicated class - this is getting way too big
Expand Down
7 changes: 7 additions & 0 deletions PersistentKSPShurikenEmitter.cs
Expand Up @@ -74,6 +74,7 @@ public class PersistentKSPShurikenEmitter
public Vector3 force;
public Vector3 rndForce;
public Color color;
public bool doesAnimateColor;

//private float emitterVelocityScale;
private Vector3 rndVelocity;
Expand Down Expand Up @@ -543,6 +544,12 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity)
? (Vector3)pPos
: peTransform.InverseTransformPoint(pPos);
}

if (doesAnimateColor)
{
float lifePercentage = (particle.lifetime / particle.startLifetime);
particle.startColor = pe.colorOverLifetime.color.Evaluate(lifePercentage);
}
}
particles[j] = particle;
}
Expand Down

0 comments on commit d0b5e09

Please sign in to comment.