Skip to content

Commit

Permalink
Fix the singleEmitTimer and add workaround for the stock effect init …
Browse files Browse the repository at this point in the history
…problem
  • Loading branch information
sarbian committed May 26, 2015
1 parent 9014200 commit 0b813a7
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions ModelMultiParticlePersistFX.cs
Expand Up @@ -177,16 +177,16 @@ public ModelMultiParticlePersistFX()
// Catch in time
public void OnVesselDie()
{
Print("OnVesselDie");
//Print("OnVesselDie");
OnDestroy();
}

private void OnDestroy()
{
Print("OnDestroy");
//Print("OnDestroy");
if (persistentEmitters != null)
{
Print("OnDestroy Detach");
//Print("OnDestroy Detach");
for (int i = 0; i < persistentEmitters.Count; i++)
{
persistentEmitters[i].Detach(0);
Expand All @@ -204,7 +204,7 @@ public override void OnEvent()
}
singleTimerEnd = singleEmitTimer + Time.fixedTime;
timeModuloDelta = singleTimerEnd % timeModulo;

// Old version Emitted 1 second of particle in one go
// New version set power to 1 for singleEmitTimer seconds
//UpdateEmitters(1);
Expand All @@ -216,13 +216,12 @@ public override void OnEvent()

public override void OnEvent(float power)
{
//Print("OnEvent " + power);
if (persistentEmitters == null)
{
return;
}

if ((overRideInputs || power > 0 || Time.deltaTime <= singleTimerEnd) && activated)
if ((overRideInputs || power > 0) && activated)
{
UpdateEmitters(power);
for (int i = 0; i < persistentEmitters.Count; i++)
Expand All @@ -249,6 +248,18 @@ public void FixedUpdate()
return;
}

if (singleTimerEnd > 0)
{
if (Time.fixedTime <= singleTimerEnd)
{
OnEvent(1);
}
else
{
OnEvent(0);
singleTimerEnd = 0;
}
}
SmokeScreenConfig.UpdateParticlesCount();

//RaycastHit vHit = new RaycastHit();
Expand Down Expand Up @@ -290,7 +301,6 @@ private void UpdateInputs(float power)
else
{
time = singleTimerEnd - Time.fixedTime;
power = 1;
}

if (hostPart != null)
Expand Down Expand Up @@ -427,6 +437,7 @@ public void Update()
{
return;
}

for (int i = 0; i < persistentEmitters.Count; i++)
{
// using Camera.main will mess up anything multi cam but using current require adding a OnWillRenderObject() to the ksp particle emitter GameObject (? not tested)
Expand Down Expand Up @@ -545,6 +556,10 @@ public override void OnInitialize()
Destroy(templateKspParticleEmitter);

list.Add(this);

// 1.0 don't seems to properly do this for engines.
OnEvent(0);

}

private static void DisableCollider(GameObject go)
Expand Down

0 comments on commit 0b813a7

Please sign in to comment.