コード例 #1
0
    void Update()
    {
        if (Source == AudioVisualisationSource.Microphone)
        {
            SpectrumData = Input.GetSpectrum();
        }
        else if (Source == AudioVisualisationSource.Molecule)
        {
            if (SpectrumData.Length == 0)
            {
                LoadMoleculeSpectrum();
            }
        }
        var length = SpectrumData.Length;

        // The line renderer can only do 1024 points, so if length > 1024 increase the step size
        Vector3[] lineCoordinates = new Vector3[length];

        for (var i = 0; i < length; i++)
        {
            lineCoordinates [i] = new Vector3(Width * ((1f * i / length) - 0.5f), SpectrumData[i] * Scale, 0);
        }
        LineRenderer.SetPositions(lineCoordinates);
    }