public void DeselectPiece() { foreach (var piece in ActiveChessPieces) { piece.ChessSprite.raycastTarget = true; } selectedPiece = null; }
public void SelectPiece(BasePieceGO basePiece) { selectedPiece = basePiece; foreach (var piece in ActiveChessPieces) { piece.ChessSprite.raycastTarget = false; } selectedPiece.ChessSprite.raycastTarget = true; }
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); }
/// <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); } }
public void Cleanup() { ActiveChessPieces = new List <BasePieceGO>(); selectedPiece = null; }
public void RemoveChessPiece(BasePieceGO basePieceGO) { ActiveChessPieces.Remove(basePieceGO); Destroy(basePieceGO.gameObject); }
public void MovePiece(int _id, ChessCell _targetCell, ChessCell _originalCell) { BasePieceGO basePieceGO = GetChessPieceById(_id); basePieceGO.Move(_targetCell, _originalCell); }