예제 #1
0
        void BuildPath(int clickedCellIndex)
        {
            DestroyLOSMarkers();

            if (isSelectingStart)
            {
                // Selects start cell
                cellStartIndex = clickedCellIndex;
                grid.CellToggle(cellStartIndex, true, Color.yellow);
            }
            else
            {
                // Clicked on the end cell, then show the path
                // First clear color of start cell
                grid.CellToggle(cellStartIndex, false, Color.white);
                // Get Path
                List <int> path = grid.FindPath(cellStartIndex, clickedCellIndex, cellGroupMask: CELLS_ALL_NAVIGATABLE);
                // Color the path
                if (path != null)
                {
                    for (int k = 0; k < path.Count; k++)
                    {
                        grid.CellFadeOut(path [k], Color.green, 1f);
                    }
                }
            }
            isSelectingStart = !isSelectingStart;
        }
예제 #2
0
        void BuildPath(int clickedCellIndex)
        {
            // If clicked cell can't be crossed, return
            if (!grid.cells[clickedCellIndex].canCross)
            {
                return;
            }

            // Get Path
            int        cellIndex = grid.CellGetIndex(tokenRow, tokenColumn);
            List <int> path      = grid.FindPath(cellIndex, clickedCellIndex, movePoints);

            if (path != null)
            {
                movePoints -= path.Count;
                // Color the path
                for (int k = 0; k < path.Count; k++)
                {
                    grid.CellFlash(path [k], Color.green, 1f);
                }
                // Start animating/moving the ship
                StartCoroutine(MoveShipAlongPath(path));
                // Annotate new ship row and column
                tokenRow    = grid.CellGetRow(clickedCellIndex);
                tokenColumn = grid.CellGetColumn(clickedCellIndex);
            }
            else
            {
                // Indicate that cell is not reachable
                grid.CellFlash(clickedCellIndex, Color.red, 1f);
            }
        }
예제 #3
0
        /// <summary>
        /// Moves the piece to the center position of the cell specified by cell index.
        /// </summary>
        /// <param name="cellIndex">Cell index.</param>
        void MovePiece(int destinationCellIndex)
        {
            // Gets current cell under piece
            Cell currentCell      = grid.CellGetAtPosition(piece.transform.position, true);
            int  currentCellIndex = grid.CellGetIndex(currentCell);

            // Obtain a path from current cell to destination
            List <int> positions = grid.FindPath(currentCellIndex, destinationCellIndex);

            // Move along those positions
            grid.MoveTo(piece, positions, 0.5f, 0f);
        }