Unity 歌曲频谱实现

http://docs.unity3d.com/ScriptReference/AudioSource.GetSpectrumData.html
https://github.com/keijiro/unity-audio-spectrum
http://www.41post.com/4776/programming/unity-making-a-simple-audio-visualization

Unity 歌曲频谱实现_第1张图片
Paste_Image.png
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class SpectrumViewer : MonoBehaviour
{
    private float[] spectrum = new float[64];

    private float deltaTime;

    public float time = 0.1f;

    void Start()
    {

    }

    void Update()
    {
        deltaTime += Time.deltaTime;
        if (deltaTime < time)
            return;

        deltaTime = 0;

        AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular);

        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).GetComponent().fillAmount = Mathf.Ceil(spectrum[i] * 10) / 10.0f;
        }
    }
}

你可能感兴趣的:(Unity 歌曲频谱实现)