EmitterOnUpdate() public method

public EmitterOnUpdate ( Vector3 emitterWorldVelocity ) : void
emitterWorldVelocity Vector3
return void
Ejemplo n.º 1
0
    private void LateUpdate()
    {
        for (int i = 0; i < persistentEmittersShuriken.Count; i++)
        {
            PersistentKSPShurikenEmitter em = persistentEmittersShuriken[i];
            if (em.endTime > 0 && em.endTime < Time.fixedTime)
            {
                em.EmissionStop();
            }

            // If the gameObject is null clean up the emitter
            if (em.go == null || em.pe == null)
            {
                Remove(em);
                Destroy(em.go);
                i--;
            }
            // if not and the transform parent is null ( Emitter detached from part so the particle are not removed instantly )
            // then the emitter won't be updated by the effect Update Call. So update it here
            else if (em.emitOnUpdate && em.go.transform.parent == null)
            {
                em.EmitterOnUpdate(Vector3.zero);

                if (em.pe.particleCount == 0)
                {
                    Remove(em);
                    Destroy(em.go);
                    i--;
                }
            }
        }
    }
    // 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());
            }
        }
    }