// First, I tried to emit particles on regular Update, but stuff was weird, and the plume still appeared out of sync with frame draws
    // According to https://docs.unity3d.com/Manual/ExecutionOrder.html
    // LateUpdate is the last thing that happens before frame draw. That makes it as synced to frame draws, as possible
    // LateUpdate is called after physics calculations too, so the newly emitted plume particles are right where they should be.
    public void LateUpdate()
    {
        if (persistentEmitters == null || hostPart == null || hostPart.Rigidbody == null)
        {
            return;
        }

        // I think it's important to call this even though it doesn't count active particles
        // because it calculates how many particles should be removed on next emit pass.
        SmokeScreenConfig.UpdateParticlesCount();

        for (int i = 0; i < persistentEmitters.Count; i++)
        {
            PersistentKSPShurikenEmitter emitter = persistentEmitters[i];
            if (EmitOnUpdate)
            {
                emitter.EmitterOnUpdate(hostPart.Rigidbody.velocity + Krakensbane.GetFrameVelocity());
            }
        }
    }
    public void FixedUpdate()
    {
        //Print("FixedUpdate");
        if (persistentEmitters == null || hostPart == null || hostPart.Rigidbody == null)
        {
            return;
        }

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

        //RaycastHit vHit = new RaycastHit();
        //Ray vRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        //if(Physics.Raycast(vRay, out vHit))
        //{
        //    RaycastHit vHit2 = new RaycastHit();
        //    if (Physics.Raycast(vHit.point + vHit.normal * 10, -vHit.normal, out vHit2))
        //        Debug.Log(vHit2.collider.name);
        //}

        for (int i = 0; i < persistentEmitters.Count; i++)
        {
            PersistentKSPShurikenEmitter emitter = persistentEmitters[i];
            // This is FixedUpdate, so don't emit here if particles should emit in LateUpdate
            if (!EmitOnUpdate)
            {
                emitter.EmitterOnUpdate(hostPart.Rigidbody.velocity + Krakensbane.GetFrameVelocity());
            }
        }
    }
Example #3
0
    public void FixedUpdate()
    {
        //Print("FixedUpdate");
        if (persistentEmitters == null || hostPart == null || hostPart.rb == null)
        {
            return;
        }

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

        //RaycastHit vHit = new RaycastHit();
        //Ray vRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        //if(Physics.Raycast(vRay, out vHit))
        //{
        //    RaycastHit vHit2 = new RaycastHit();
        //    if (Physics.Raycast(vHit.point + vHit.normal * 10, -vHit.normal, out vHit2))
        //        Debug.Log(vHit2.collider.name);
        //}

        PersistentKSPParticleEmitter[] persistentKspParticleEmitters = persistentEmitters.ToArray();
        for (int i = 0; i < persistentKspParticleEmitters.Length; i++)
        {
            PersistentKSPParticleEmitter persistentKspParticleEmitter = persistentKspParticleEmitters[i];

            persistentKspParticleEmitter.EmitterOnUpdate(hostPart.rb.velocity + Krakensbane.GetFrameVelocity());
        }
    }