Esempio n. 1
0
    /// <summary>
    ///
    /// </summary>
    void InstanceSpectrum()
    {
        //Calculate the size of each UI bar
        float sf = ((RootSpectrumUI.sizeDelta.x - (Space * m_Samples)) / m_Samples);
        //start position
        float sp = -sf;

        for (int i = 0; i < m_Samples; i++)
        {
            //next position
            sp += sf + Space;
            GameObject s = Instantiate(SpectrumPrefab) as GameObject;
            s.name = string.Format("Spectrum[{0}]", i + 1);
            s.transform.SetParent(SpectrumPanel, false);

            bl_SpectrumUI r = s.GetComponent <bl_SpectrumUI>();
            r.SpectrumColor = SpectrumColor;
            m_Recs.Add(r);

            Vector2 v = r.anchoredPosition;
            v.x = sp;
            r.RootRect.anchoredPosition = v;

            Vector2 size = r.sizeDelta;
            size.x = sf;
            r.RootRect.sizeDelta = size;
        }
    }
Esempio n. 2
0
    /// <summary>
    ///
    /// </summary>
    void Update()
    {
        //Get spectrum data samples from audio listener
        float[] data = new float[m_Samples];
        AudioListener.GetSpectrumData(data, m_Channel, FTT);

        if (Time.time >= NextRate)
        {
            //apply to the bars ui
            for (int i = 0; i < m_Recs.Count; i++)
            {
                bl_SpectrumUI spectrum = m_Recs[i];
                Vector2       v        = spectrum.sizeDelta;
                Vector2       vs       = spectrum.anchoredPosition;

                v.y  = ((data[i] * (RootSpectrumUI.sizeDelta.y * 0.5f)) * Multiplier);
                vs   = spectrum.anchoredPosition;
                vs.y = 0 + ((data[i] * RootSpectrumUI.sizeDelta.y * 0.5f));

                vs.y     = 0;
                v.y      = Mathf.Clamp(v.y, 0, MaxOutPout * Multiplier);
                NextRate = Time.time + Rate;

                spectrum.anchoredPosition = Vector2.Lerp(spectrum.anchoredPosition, vs, Time.deltaTime * UpLerp);
                spectrum.sizeDelta        = Vector2.Lerp(spectrum.sizeDelta, v, Time.deltaTime * UpLerp);
            }
            NextRate = Time.time + Rate;
        }
        else
        {
            //apply to the bars ui
            for (int i = 0; i < m_Recs.Count; i++)
            {
                bl_SpectrumUI spectrum = m_Recs[i];
                Vector2       v        = spectrum.sizeDelta;
                Vector2       vs       = spectrum.anchoredPosition;

                v.y  = Mathf.Lerp(v.y, 0, Time.deltaTime * DownLerp);
                vs.y = Mathf.Lerp(vs.y, 0, Time.deltaTime * DownLerp);
                spectrum.anchoredPosition = vs;
                spectrum.sizeDelta        = v;
            }
        }
    }