예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (oScene != SceneManager.GetActiveScene().name)
        {
            AudioSource[] msource = FindObjectsOfType <AudioSource>();

            for (int i = 0; i < msource.Length; i++)
            {
                if (msource[i].enabled)
                {
                    source = msource[i];
                }
            }

            oScene = SceneManager.GetActiveScene().name;
        }

        var em = ps.emission;


        //Calculate dB
        int length = (int)source.clip.length;

        buffer = source.GetOutputData(128, 1);

        db = Mathf.Round(AudioPower.ComputeDB(buffer, 0, ref length));

        if (db < dbActive)
        {
            ps.enableEmission = false;
            return;
        }

        em.enabled = true;
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        lastdb = db;

        if (oScene != SceneManager.GetActiveScene().name)
        {
            AudioSource[] msource = FindObjectsOfType <AudioSource>();

            for (int i = 0; i < msource.Length; i++)
            {
                if (msource[i].enabled)
                {
                    source = msource[i];
                }
            }

            oScene = SceneManager.GetActiveScene().name;
        }


        //Calculate dB
        int length = (int)source.clip.length;

        buffer = source.GetOutputData(128, 1);

        db = Mathf.Round(AudioPower.ComputeDB(buffer, 0, ref length));

        if (db - lastdb > spikeAmount && db < -15 || db - lastdb > spikeAmount / 2 && db > -15 && lastdb > -15 || db - lastdb > spikeAmount / 3 && db > -10 && lastdb > -10 || db - lastdb > spikeAmount / 4 && db > -5 && lastdb > -5)
        {
            ps.Play();
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        if (oScene != SceneManager.GetActiveScene().name)
        {
            AudioSource[] msource = FindObjectsOfType <AudioSource>();

            for (int i = 0; i < msource.Length; i++)
            {
                if (msource[i].enabled)
                {
                    source = msource[i];
                }
            }

            oScene = SceneManager.GetActiveScene().name;
        }

        var em = ps.emission;

        //Calculate dB
        int length = (int)source.clip.length;

        buffer = source.GetOutputData(128, 1);

        db = Mathf.Round(AudioPower.ComputeDB(buffer, 0, ref length));

        if (db < dbMin)
        {
            return;
        }

        //Make dB positive
        float adb = new float();

        if (db < 0)
        {
            adb = db * -1;
        }
        else
        {
            adb = db;

            if (adb > dbMax)
            {
                adb = dbMax;
            }
        }

        //Put dB in range of dif
        float pdb = new float();

        if (adb != dbMax)
        {
            pdb = dbMax + adb;
        }
        else
        {
            pdb = dif;
        }

        //Convert dB to a percentage
        pdb /= dif;

        pdb -= 1f;
        pdb *= -1;

        if (pdb > 1f)
        {
            pdb = 1f;
        }

        //Use dB percentage to change emission rate starting at minimum rate
        float fillA = range * pdb;

        em.rateOverTime = rateMin + fillA;
    }