Example #1
0
    public void RenderChunk()
    {
        List <Vector3> verts    = new List <Vector3>();
        List <int>     hexInds  = new List <int>();
        List <int>     starInds = new List <int>();
        List <Vector2> uvs      = new List <Vector2>();
        bool           star     = false;

        for (int q = 0; q < chunkSize; q++)
        {
            for (int r = 0; r < chunkSize; r++)
            {
                RenderHelper.AddBorderedHex(verts, hexInds, uvs, hexSize, 0.05f, new OffsetHex(q + chunkSize * chunkPos.x, r + chunkSize * chunkPos.y));
                Vector2Int chunkOffset = new Vector2Int(chunkPos.x * WorldHandler.Main.chunkSize, chunkPos.y * WorldHandler.Main.chunkSize);
                Hex        hex         = WorldHandler.Main.HexHandler.GetHex(chunkOffset.x + q, chunkOffset.y + r);
                if (hex.HasStar)
                {
                    star = true;
                    RenderHelper.AddFilledCircle(verts, starInds, uvs, 10, WorldHandler.Main.starSize / 2, hex.star.worldPos, -0.01f);
                }
            }
        }

        mesh.Clear();
        mesh.SetVertices(verts);
        mesh.SetTriangles(hexInds.ToArray(), 0);
        if (star)
        {
            mesh.subMeshCount = 2;
            mesh.SetTriangles(starInds.ToArray(), 1);
        }
        if (!star)
        {
            meshRenderer.materials[1] = null;
        }
        mesh.SetUVs(0, uvs);
    }