Example #1
0
 public void DeselectPiece()
 {
     foreach (var piece in ActiveChessPieces)
     {
         piece.ChessSprite.raycastTarget = true;
     }
     selectedPiece = null;
 }
Example #2
0
 public void SelectPiece(BasePieceGO basePiece)
 {
     selectedPiece = basePiece;
     foreach (var piece in ActiveChessPieces)
     {
         piece.ChessSprite.raycastTarget = false;
     }
     selectedPiece.ChessSprite.raycastTarget = true;
 }
Example #3
0
    private void OnCellClicked(object _data)
    {
        BasePieceGO selectedChessPiece = ChessPieceManager.GetSelectedPiece();

        if (selectedChessPiece == null)
        {
            return;
        }

        ChessCell chessCell = _data as ChessCell;

        selectedChessPiece.TryMove(chessCell.x, chessCell.y, GameId);
    }
Example #4
0
    /// <summary>
    /// Uses Server Board data to create Chess Pieces on the Client board
    /// </summary>
    /// <param name="serverBoard"></param>
    /// <param name="clientBoard"></param>
    public void Initialize(BoardData serverBoard, ChessBoard clientBoard)
    {
        for (int i = 0; i < 8; i++)
        {
            for (int j = 0; j < 8; j++)
            {
                if (serverBoard.AllCells[i, j].ChessPiece != null)
                {
                    CellData  serverCell = serverBoard.AllCells[i, j];
                    ChessCell chessCell  = clientBoard.AllCells[i, j];

                    BasePieceGO basePieceGO = Instantiate(chessPiecesSO.ChessPieces[serverCell.ChessPiece.Type], chessCell.transform).GetComponent <BasePieceGO>();
                    basePieceGO.Initialize(serverCell.ChessPiece, this);

                    chessCell.ChessPiece = basePieceGO;
                    ActiveChessPieces.Add(basePieceGO);
                }
            }
        }
        Debug.Log("ChessPieces Initialized");
    }
    public void OnPointerClick(PointerEventData _eventData)
    {
        if (!GameManager.IsMyTurn)
        {
            return;
        }

        BasePieceGO basePieceGO = ChessPieceManagerRef.GetSelectedPiece();

        if (basePieceGO != null && basePieceGO.ChessPieceData.ChessPieceId == ChessPieceData.ChessPieceId)
        {
            ChessPieceManagerRef.DeselectPiece();
            return;
        }

        if (ChessPieceData.PlayerId == GameManager.UserInfo.Id)
        {
            Debug.Log($"OnPointerClicked event from {GetType()}");
            ChessPieceManagerRef.SelectPiece(this);
        }
    }
Example #6
0
 public void Cleanup()
 {
     ActiveChessPieces = new List <BasePieceGO>();
     selectedPiece     = null;
 }
Example #7
0
 public void RemoveChessPiece(BasePieceGO basePieceGO)
 {
     ActiveChessPieces.Remove(basePieceGO);
     Destroy(basePieceGO.gameObject);
 }
Example #8
0
    public void MovePiece(int _id, ChessCell _targetCell, ChessCell _originalCell)
    {
        BasePieceGO basePieceGO = GetChessPieceById(_id);

        basePieceGO.Move(_targetCell, _originalCell);
    }