Ejemplo n.º 1
0
        /// <summary>
        /// Creates a classic black and white checkers board
        /// </summary>
        void CreateBoard()
        {
            Texture2D whiteCell = Resources.Load <Texture2D> ("Textures/cellWhite");
            Texture2D blackCell = Resources.Load <Texture2D> ("Textures/cellBlack");

            grid.gridTopology = GRID_TOPOLOGY.Box;
            grid.rowCount     = 8;
            grid.columnCount  = 8;

            bool even = false;

            for (int row = 0; row < grid.rowCount; row++)
            {
                even = !even;
                for (int col = 0; col < grid.columnCount; col++)
                {
                    even = !even;
                    Cell cell      = grid.CellGetAtPosition(col, row);
                    int  cellIndex = grid.CellGetIndex(cell);
                    if (even)
                    {
                        grid.CellToggle(cellIndex, true, whiteCell);
                    }
                    else
                    {
                        grid.CellToggle(cellIndex, true, blackCell);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // Highlight cells sequentially on each frame
        IEnumerator HighlightCell()
        {
            currentCol++;
            // run across the grid row by row
            if (currentCol >= grid.columnCount)
            {
                currentCol = 0;
                currentRow++;
                if (currentRow >= grid.rowCount)
                {
                    currentRow = 0;
                }
            }
            // get cell at current grid position and color it with fade out option
            Cell cell = grid.CellGetAtPosition(currentCol, currentRow);

            if (cell != null)
            {
                int   cellIndex = grid.CellGetIndex(cell);
                float duration  = Random.value * 2.5f + 0.5f;
                Color color     = new Color(Random.value, Random.value, Random.value);
                grid.CellFadeOut(cellIndex, color, duration);
            }
            // trigger next iteration after this frame
            yield return(new WaitForEndOfFrame());

            StartCoroutine(HighlightCell());
        }
Ejemplo n.º 3
0
        void TriggerRandomCell(Color color)
        {
            // We get a random vector from -0.5..0.5 on both X and Y (z is ignored)
            Vector2 localPosition = Random.onUnitSphere * 0.5f;
            Cell    cell          = grid.CellGetAtPosition(localPosition);

            if (cell != null)
            {
                int   cellIndex = grid.CellGetIndex(cell);
                float duration  = Random.value * 2.5f + 0.5f;
                grid.CellFadeOut(cellIndex, color, duration);
            }
        }