Example #1
0
 public void OnVesselDestroy(Vessel vessel)
 {
     if (VesselDict.ContainsKey(vessel.id))
     {
         ReentryEffect effects = VesselDict[vessel.id];
         if (effects != null)
         {
             effects.Die();
         }
         VesselDict.Remove(vessel.id);
     }
 }
Example #2
0
        private void FixedUpdate()
        {
            float         effectStrength = (AeroFX.FxScalar * AeroFX.state - EffectThreshold) * (1 / EffectThreshold);
            List <Vessel> vessels        = FlightGlobals.Vessels;

            for (int i = vessels.Count - 1; i >= 0; --i)
            {
                Vessel        vessel  = vessels[i];
                ReentryEffect effects = null;
                if (VesselDict.ContainsKey(vessel.id))
                {
                    effects = VesselDict[vessel.id];
                }
                else
                {
                    if (vessel.loaded)
                    {
                        effects = CreateEffect();
                        VesselDict.Add(vessel.id, effects);
                    }
                    else
                    {
                        continue;
                    }
                }

                if (!vessel.loaded)
                {
                    if (effects != null)
                    {
                        effects.Die();
                    }
                    effects = null;
                    continue;
                }

                if (effects == null || effects.Trail == null || effects.Sparks == null)
                {
                    continue;
                }

                ParticleSystem.EmissionModule trailEmission  = effects.Trail.emission;
                ParticleSystem.EmissionModule sparksEmission = effects.Sparks.emission;
                if (AeroFX != null)
                {
                    //effects.Trail.transform.localScale = new Vector3(TrailScale, TrailScale, TrailScale);
#if DEBUG
                    afx1 = AeroFX;

                    effects.Trail.transform.localScale = new Vector3(scaleX, scaleY, scaleZ);

                    var main = effects.Trail.main;
                    main.scalingMode = _scalingMode;
#endif

                    // FxScalar: Strength of the effects.
                    // state: 0 = condensation, 1 = reentry.
                    if (effectStrength > 0)
                    {
                        // Ensure the particles don't lag a frame behind.
                        effects.Trail.transform.position  = vessel.CoM + vessel.rb_velocity * Time.fixedDeltaTime;
                        trailEmission.enabled             = true;
                        effects.Sparks.transform.position = vessel.CoM + vessel.rb_velocity * Time.fixedDeltaTime;
                        sparksEmission.enabled            = true;

                        velocity = AeroFX.velocity * (float)AeroFX.airSpeed;

                        var trailMain = effects.Trail.main;
                        trailMain.startSpeed            = velocity.magnitude;
                        effects.Trail.transform.forward = -velocity.normalized;
                        trailMain.maxParticles          = (int)(MaxParticles * effectStrength);
                        trailEmission.rateOverTime      = (int)(MaxEmissionRate * effectStrength);

                        // startSpeed controls the emission cone angle. Greater than ~1 is too wide.
                        //reentryTrailSparks.startSpeed = velocity.magnitude;
                        var sparksMain = effects.Sparks.main;
                        effects.Sparks.transform.forward = -velocity.normalized;
                        sparksMain.maxParticles          = (int)(MaxParticles * effectStrength);
                        sparksEmission.rateOverTime      = (int)(MaxEmissionRate * effectStrength);
                    }
                    else
                    {
                        trailEmission.enabled  = false;
                        sparksEmission.enabled = false;
                    }
                }
                else
                {
                    trailEmission.enabled  = false;
                    sparksEmission.enabled = false;
                }
            }
        }