public void AddTileGrid()
        {
            if (!Application.isPlaying)
            {
                throw new Exception("Must be on play mode");
            }

            ClearAllGrids();

            // Create a grid of GridSize by GridSize, using the cellPrefab.
            tileGrid = SimpleGrid.RectXY(gameObject, gridSize, gridSize, cellPrefab, cellDimensions);

            // Get (or add) a grid's event trigger controller to attach events to change the color of the cell when clicking it.
            var eventTrigger = tileGrid.AddComponent <GridEventTrigger>();

            eventTrigger.UICamera = Camera.main;
            eventTrigger.OnLeftMouseButtonDown.AddListener(point =>
            {
                tileGrid.Grid[point].GetRequiredComponent <SpriteRenderer>().color = colors.Count > 0 ? colors[0] : Color.white;
            }
                                                           );
            eventTrigger.OnRightMouseButtonDown.AddListener(point =>
            {
                tileGrid.Grid[point].GetRequiredComponent <SpriteRenderer>().color = colors.Count > 0 ? colors[1] : Color.black;
            }
                                                            );

            // Colorize the grid.
            foreach (var point in tileGrid.Grid.Points)
            {
                tileGrid.Grid[point].GetComponent <SpriteRenderer>().color = colors[point.GetColor(colorFunction) % colors.Count];
            }
        }
        private void AddMeshGrid()
        {
            if (!Application.isPlaying)
            {
                throw new Exception("Must be on play mode");
            }

            ClearAllGrids();

            var meshFilter = gameObject.GetComponent <MeshFilter>();

            // Create a mesh grid of GridSize by GridSize, using the meshData.
            mesh     = new Mesh();
            meshGrid = SimpleGrid.RectXY <bool>(mesh, gridSize, gridSize, meshData, cellDimensions);

            // Colorize the vertex fed to the mesh.
            var vertexColors  = new List <Color>();
            var vertexPerCell = 4;

            foreach (var point in meshGrid.Points)
            {
                var colorIndex = point.GetColor(colorFunction.x0, colorFunction.x1, colorFunction.y1);

                for (var i = 0; i < vertexPerCell; i++)
                {
                    vertexColors.Add(colors[colorIndex]);
                }
            }

            mesh.colors = vertexColors.ToArray();

            // Set the new mesh
            meshFilter.sharedMesh = mesh;
        }