private void BuildGridMesh()
        {
            int vertNodesIndex = 0;
            int triNodesIndex  = 0;

            int vertConnectionsIndex = 0;
            int triConnectionsIndex  = 0;

            // get the references to the mesh stuff
            Vector3[] nodesVerts = nodesMeshInfo.Vertices;
            Color[]   nodesCols  = nodesMeshInfo.Colors;
            int[]     nodesTris  = nodesMeshInfo.Triangles;
            Mesh      nodesMesh  = nodesMeshInfo.Mesh;

            Vector3[] connectionsVerts = connectionsMeshInfo.Vertices;
            Color[]   connectionsCols  = connectionsMeshInfo.Colors;
            int[]     connectionsTris  = connectionsMeshInfo.Triangles;
            Mesh      connectionsMesh  = connectionsMeshInfo.Mesh;

            // calculate half the width of the line that represents the neighbor connections
            float lineWidthRadius = connectionsWidthFactor * nodeRadius;

            for (int i = 0; i < numRows; i++)
            {
                for (int j = 0; j < numCols; j++)
                {
                    GridNode n = Nodes[i, j];

                    // first we set up the quads corresponding to the node visual representation
                    Vector3 v1 = n.Pos + (Vector3.left + Vector3.back) * NodeDebugRadius;
                    Vector3 v2 = n.Pos + (Vector3.right + Vector3.back) * NodeDebugRadius;
                    Vector3 v3 = n.Pos + (Vector3.left + Vector3.forward) * NodeDebugRadius;
                    Vector3 v4 = n.Pos + (Vector3.right + Vector3.forward) * NodeDebugRadius;

                    Color col = n.Walkable ? walkableNodeColor : unwalkableNodeColor;

                    nodesVerts[vertNodesIndex]     = v1;
                    nodesVerts[vertNodesIndex + 1] = v2;
                    nodesVerts[vertNodesIndex + 2] = v3;
                    nodesVerts[vertNodesIndex + 3] = v4;

                    nodesCols[vertNodesIndex]     = col;
                    nodesCols[vertNodesIndex + 1] = col;
                    nodesCols[vertNodesIndex + 2] = col;
                    nodesCols[vertNodesIndex + 3] = col;

                    nodesTris[triNodesIndex++] = vertNodesIndex;
                    nodesTris[triNodesIndex++] = vertNodesIndex + 2;
                    nodesTris[triNodesIndex++] = vertNodesIndex + 1;

                    nodesTris[triNodesIndex++] = vertNodesIndex + 2;
                    nodesTris[triNodesIndex++] = vertNodesIndex + 3;
                    nodesTris[triNodesIndex++] = vertNodesIndex + 1;

                    vertNodesIndex += 4;

                    // now we set up the connections to the neighbors
                    for (int k = 0; k < n.Neighbors.Length; k++)
                    {
                        GridNode neighbor = n.Neighbors[k];

                        if (neighbor == null)
                        {
                            continue;
                        }

                        Vector3 offsetToNeighbor = neighbor.Pos - n.Pos;

                        Vector3 left = Vector3.Cross(offsetToNeighbor, -cam.transform.forward).normalized *lineWidthRadius;

                        v1 = n.Pos + left + NodeDebugConnectionsUp;
                        v2 = n.Pos - left + NodeDebugConnectionsUp;
                        v3 = n.Pos + left + offsetToNeighbor + NodeDebugConnectionsUp;
                        v4 = n.Pos - left + offsetToNeighbor + NodeDebugConnectionsUp;

                        connectionsVerts[vertConnectionsIndex]     = v1;
                        connectionsVerts[vertConnectionsIndex + 1] = v2;
                        connectionsVerts[vertConnectionsIndex + 2] = v3;
                        connectionsVerts[vertConnectionsIndex + 3] = v4;

                        connectionsCols[vertConnectionsIndex]     = connectionsColor;
                        connectionsCols[vertConnectionsIndex + 1] = connectionsColor;
                        connectionsCols[vertConnectionsIndex + 2] = connectionsColor;
                        connectionsCols[vertConnectionsIndex + 3] = connectionsColor;

                        connectionsTris[triConnectionsIndex++] = vertConnectionsIndex;
                        connectionsTris[triConnectionsIndex++] = vertConnectionsIndex + 2;
                        connectionsTris[triConnectionsIndex++] = vertConnectionsIndex + 1;

                        connectionsTris[triConnectionsIndex++] = vertConnectionsIndex + 2;
                        connectionsTris[triConnectionsIndex++] = vertConnectionsIndex + 3;
                        connectionsTris[triConnectionsIndex++] = vertConnectionsIndex + 1;

                        vertConnectionsIndex += 4;
                    }
                }
            }

            nodesMeshInfo.SetMesh();
            nodesMeshInfo.Recalculate();

            connectionsMeshInfo.SetMesh();
            connectionsMeshInfo.Recalculate();
        }