コード例 #1
0
ファイル: Visualizer.cs プロジェクト: cysAAAA/Unity3D-Ski
    void Update()
    {
        var spectrum = GetComponent <AudioSpectrum>();

        if (barCount == spectrum.Levels.Length && !Input.GetMouseButtonDown(0))
        {
            return;
        }

        // Change the bar type on mouse click.
        if (Input.GetMouseButtonDown(0))
        {
            if (barType == SpectrumBar.BarType.MeanLevel)
            {
                barType = SpectrumBar.BarType.Realtime;
            }
            else
            {
                barType++;
            }
        }

        // Destroy the old bars.
        foreach (var child in transform)
        {
            Destroy((child as Transform).gameObject);
        }

        // Change the number of bars.
        barCount = spectrum.Levels.Length;
        var barWidth = 6.0f / barCount;
        var barScale = new Vector3(barWidth * 0.9f, 1, 0.75f);

        // Create new bars.

        /*
         * for (var i = 0; i < barCount; i++)
         * {
         *  var x = 6.0f * i / barCount - 3.0f + barWidth / 2;
         *
         *  //var bar = Instantiate(barPrefab, Vector3.right * x, transform.rotation) as GameObject;
         *
         *  bar.GetComponent<SpectrumBar>().index = i;
         *  bar.GetComponent<SpectrumBar>().barType = barType;
         *
         *  bar.transform.parent = transform;
         *  bar.transform.localScale = barScale;
         *
         * }
         */
    }
コード例 #2
0
ファイル: SpectrumVisualizer.cs プロジェクト: haruo666/VJ149
    void Update()
    {
        var spectrum = GetComponent<AudioSpectrum>();

        if (Input.GetKeyDown (KeyCode.Space)) {
            //Debug.Log("Updating camera position.");
            changeCamPosition();
        }

        if (barCount == spectrum.Levels.Length && !Input.GetMouseButtonDown(0)) {
            return;
        }

        // Change the bar type on mouse click.
        if (Input.GetMouseButtonDown(0)) {
            if (barType == SpectrumBar.BarType.MeanLevel) {
                barType = SpectrumBar.BarType.Realtime;
            } else {
                barType++;
            }
        }

        // Destroy the old bars.
        foreach (var child in transform) {
            Destroy ((child as Transform).gameObject);
        }

        // Change the number of bars.
        barCount = spectrum.Levels.Length;
        var barWidth = 6.0f / barCount;
        var barScale = new Vector3 (barWidth * 0.9f, 1, 0.75f);

        GameObject[] bars = GameObject.FindGameObjectsWithTag ("SpectrumBar");

        // Create new bars.
        //for (var i = 0; i < barCount; i++) {
        foreach (var bar in bars) {
            //var x = 6.0f * i / barCount - 3.0f + barWidth / 2;

            //var bar = Instantiate (barPrefab, Vector3.right * x, transform.rotation) as GameObject;

            var index = bar.GetComponent<SpectrumBar> ().index;

            bar.GetComponent<SpectrumBar> ().barType = barType;

            bar.transform.parent = transform;
            bar.transform.localScale = barScale;
        }
    }