コード例 #1
0
        private void OnMouseDown()
        {
            selectedPiece     = this;
            timeSelectedPiece = Time.time;
            ClearAllPieceSprites(true);
            sr.color = selectedColor;

            CleanHighlightedFloorTiles();

            List <Vector2Int> movementOptions = ChessMovements.GetMovementOptions(level, pieceType, new Vector2Int(isoTransform.coords.x, isoTransform.coords.y));

            foreach (Vector2Int option in movementOptions)
            {
                highlightedFloorTiles.Add(option);
            }
        }
コード例 #2
0
        private void UpdateHighlightedTiles()
        {
            foreach (Vector2Int tilePos in highlightedFloorTiles)
            {
                level.GetFloorGameObject(tilePos).GetComponent <SpriteRenderer>().color = Color.Lerp(Color.green, Color.white, 0.3f);
            }

            Vector2Int mouseCoords = level.transformer.ScreenToTile(Input.mousePosition);

            if (highlightedFloorTiles.Contains(mouseCoords))
            {
                level.GetFloorGameObject(mouseCoords).GetComponent <SpriteRenderer>().color = Color.Lerp(Color.green, Color.blue, 0.3f);

                if (Input.GetMouseButtonDown(0) && Time.time != timeSelectedPiece)
                {
                    Vector2Int previousPosition = (Vector2Int)isoTransform.coords;
                    level.data.SetItem(mouseCoords.x, mouseCoords.y, (int)pieceType, 0);
                    level.data.SetItem(previousPosition.x, previousPosition.y, (int)ChessIndex.EMPTY, 0);
                    CleanHighlightedFloorTiles();
                    selectedPiece = null;
                }
            }
        }