private HighlightPiece _createHighLight(Vector2 pos) { GameObject prefab = ResourceCache.getPrefab(BasePiece.BASE_PREFAB); GameObject obj = Instantiate(prefab, gameObject.transform, true); HighlightPiece hightlightPiece = obj.AddComponent <HighlightPiece>(); hightlightPiece.Setup(pos); hightlightPiece.sprite = BasePiece.H_CELL_HIGHLIGHTED; return(hightlightPiece); }
private void _removeHighlightMoves() { for (int i = 0; i < _piecesHighlighted.Count; i++) { Destroy(_piecesHighlighted[i].gameObject); } if (_currentPosPieceHighligh) { Destroy(_currentPosPieceHighligh.gameObject); } _piecesHighlighted = new List <HighlightPiece> (); _currentPosPieceHighligh = null; }
private void _createHighLightAt(Vector2 pos, Vector2 posFrom, bool isCurrentPos = false) { HighlightPiece component = _createHighLight(pos); component.pos = pos; component.zIndex = ZIndex.PIECES_HIGHLIGHT; component.AnimateScale(0, 1.0f); if (!isCurrentPos) { component.sprite = BasePiece.H_CELL_HIGHLIGHTED; _piecesHighlighted.Add(component); } else { component.sprite = BasePiece.H_CELL_CURRENT; _currentPosPieceHighligh = component; } }
// lighing next cell that we can put in a piece public void RecalculateDraggingAction(Vector3 pos) { // find highlighet piece by pos bool foundNextCell = false; for (int i = 0; i < _piecesHighlighted.Count; i++) { Vector2 nextBoardPos = new Vector2(Mathf.Round(pos.x / GameEngine.CELL_SIZE), Mathf.Round(pos.y / GameEngine.CELL_SIZE)); HighlightPiece pieceComponent = _piecesHighlighted[i]; if (pieceComponent.pos.x == nextBoardPos.x && pieceComponent.pos.y == nextBoardPos.y) { foundNextCell = true; Cell prevCell = GameEngine.GameController.GetNextAction().CellFrom; Cell nextCell = GetCellAt(nextBoardPos); if (nextCell.Piece && (nextCell.Piece.Relation == PieceRelation.ENEMY || nextCell.HasFight)) { if (nextCell.HasFight) { if (nextCell.Piece.Relation == PieceRelation.ENEMY && nextCell.AttackerPiece.Relation == PieceRelation.SELF) { pieceComponent.sprite = BasePiece.H_CELL_ENEMY; GameEngine.GameController.UpdateNextActionCell(nextCell, BoardAction.ATTACK_HELP); } else if (nextCell.Piece.Relation == PieceRelation.SELF && nextCell.AttackerPiece.Relation == PieceRelation.ENEMY) { pieceComponent.sprite = BasePiece.H_CELL_ENEMY; GameEngine.GameController.UpdateNextActionCell(nextCell, BoardAction.DEFEND_HELP); } } else if (nextCell.Piece.Relation == PieceRelation.ENEMY) { pieceComponent.sprite = BasePiece.H_CELL_ENEMY; GameEngine.GameController.UpdateNextActionCell(nextCell, BoardAction.ATTACK); } } else { pieceComponent.sprite = BasePiece.H_CELL_MOVE_TO; InteractionType interactionType = PieceInteraction.GetType(prevCell, nextCell); if (interactionType == InteractionType.NONE) { GameEngine.GameController.UpdateNextActionCell(nextCell, BoardAction.MOVE); } else if (interactionType == InteractionType.END_LEVEL || interactionType == InteractionType.END_LEVEL_FROM_HORSE) { GameEngine.GameController.UpdateNextActionCell(nextCell, BoardAction.END_LEVEL); } else { GameEngine.GameController.UpdateNextActionCell(nextCell, BoardAction.INTERACTION); } } } else { pieceComponent.sprite = BasePiece.H_CELL_HIGHLIGHTED; } } if (!foundNextCell) { GameEngine.GameController.UpdateNextActionCell(null, BoardAction.MOVE); } }