Example #1
0
    public void Update()
    {
        //Print("Update");
        if (persistentEmitters == null)
        {
            return;
        }

        for (int i = 0; i < persistentEmitters.Count; i++)
        {
            if (persistentEmitters[i].go == null)
            {
                continue;
            }

            // using Camera.main will mess up anything multi cam but using current require adding a OnWillRenderObject() to the ksp particle emitter GameObject (? not tested)
            float currentAngle = Vector3.Angle(
                -Camera.main.transform.forward,
                persistentEmitters[i].go.transform.forward);
            float currentDist = (Camera.main.transform.position - persistentEmitters[i].go.transform.position).magnitude;

            persistentEmitters[i].pe.maxParticleSize = persistentEmitters[i].maxSizeBase * angle.Value(currentAngle)
                                                       * distance.Value(currentDist);
            persistentEmitters[i].pe.pr.maxParticleSize = persistentEmitters[i].pe.maxParticleSize;
        }
    }
Example #2
0
        void Update()
        {
            if (_fixedUpdateCount < 2)
            {
                return;
            }

            try {
                if (audioSource.clip == null)
                {
                    return;
                }

                if (_gamePaused)
                {
                    if (audioSource.isPlaying)
                    {
                        audioSource.Stop();
                    }
                    return;
                }

                if (audioSource.loop && !audioSource.isPlaying)
                {
                    audioSource.time = UnityEngine.Random.Range(0, audioSource.clip.length);
                    audioSource.Play();
                }
                else if (_playSoundSingle)
                {
                    audioSource.Play();
                    _playSoundSingle = false;
                }
                else if (oneShot)
                {
                    if (_oneshotTimeOut != 0)
                    {
                        _oneshotTimeOut--;
                        return;
                    }

                    float thrustDelta = (thrustPow - lastThrust) * 60;
                    if (thrustDelta > oneShotSensitivity)
                    {
                        audioSource.Play();
                        _oneshotTimeOut = oneShotTimeout;
                    }
                }

                if (thumpAmount > 0)
                {
                    float thrustDelta = (thrustPow - lastThrust) * 60;
                    if (thrustDelta > thumpSensitivity)
                    {
                        _thumper = thumpAmount;
                    }

                    float thumpProgress = _thumper / thumpAmount;
                    //_thumper = Mathf.MoveTowards(_thumper, 0, (thumpRate * thumpProgress) * Time.deltaTime);
                    _thumper = Mathf.MoveTowards(_thumper, 0, thumpRate * Time.deltaTime);
                }

                audioSource.pitch = pitch.Value(thrustPow) + _thumper;
                AudioFX.SetSourceVolume(audioSource, Mathf.Clamp(volume.Value(thrustPow), 0, 3), channel);

                lastThrust = thrustPow;
            } catch {
                return;
            }
        }