public void Setup(int _tracks, int _unitResolution, float _width, float _height, Vector2 _range, Vector2 _io)
 {
     _gridParams = new gridParams(_tracks, _unitResolution, _width, _height, _range, _io);
     setGridHandles();
     updateHeight();
     updateGrid(_range, _width);
     _scrollInterface.Activate();
 }
Ejemplo n.º 2
0
    public void updateGrid(gridParams _gridParams)
    {
        mesh.Clear();
        mesh.subMeshCount = 5;

        List <Vector3> points = new List <Vector3>();
        List <int>     rowsA  = new List <int>();
        List <int>     rowsB  = new List <int>();

        List <int> lines  = new List <int>();
        List <int> linesB = new List <int>();
        List <int> linesC = new List <int>();

        Vector2 bounds = new Vector2(_gridParams.getGridWidth(), _gridParams.getGridHeight());

        updateUI(bounds);

        points.Add(new Vector3(0, 0));
        points.Add(new Vector3(bounds.x, 0));

        int counter = 0;

        for (int i = 0; i < _gridParams.tracks; i++)
        {
            float h = _gridParams.UnittoY(i);
            points.Add(new Vector3(0, h));
            points.Add(new Vector3(bounds.x, h));
            counter++;
        }

        points.Add(new Vector3(0, bounds.y));
        points.Add(new Vector3(bounds.x, bounds.y));
        counter++;

        for (int i = 0; i < counter; i++)
        {
            int s = i * 2;
            if (rowTone(i))
            {
                rowsA.AddRange(new int[] {
                    s, s + 1, s + 3, s + 2
                });
            }
            else
            {
                rowsB.AddRange(new int[] {
                    s, s + 1, s + 3, s + 2
                });
            }

            if ((i - 1) % 12 == 5 || (i - 1) % 12 == 0)
            {
                lines.Add(s);
                lines.Add(s + 1);
            }
        }

        int tempCounter = points.Count;

        counter = 0;

        for (int i = Mathf.FloorToInt(_gridParams.range.x * _gridParams.snapFraction); i < Mathf.CeilToInt(_gridParams.range.y * _gridParams.snapFraction); i++)
        {
            float x = -_gridParams.UnittoX(i / _gridParams.snapFraction);
            if (x != 0 && x != 1)
            {
                points.Add(new Vector3(x, 0));
                points.Add(new Vector3(x, bounds.y));

                int s = tempCounter + counter * 2;

                if (i % (4 * _gridParams.snapFraction) == 0)
                {
                    linesC.Add(s);
                    linesC.Add(s + 1);
                }
                else if (i % _gridParams.snapFraction == 0)
                {
                    linesB.Add(s);
                    linesB.Add(s + 1);
                }
                else
                {
                    lines.Add(s);
                    lines.Add(s + 1);
                }
                counter++;
            }
        }

        mesh.vertices = points.ToArray();

        mesh.SetIndices(rowsA.ToArray(), MeshTopology.Quads, 0);
        mesh.SetIndices(rowsB.ToArray(), MeshTopology.Quads, 1);
        mesh.SetIndices(lines.ToArray(), MeshTopology.Lines, 2);
        mesh.SetIndices(linesB.ToArray(), MeshTopology.Lines, 3);
        mesh.SetIndices(linesC.ToArray(), MeshTopology.Lines, 4);
    }