private void InsertNewUnitOnBoard(PlaceholderBoardUnit placeHolder, Vector2 position) { CardScript cardScript = InstantiateCardPrefab(position.x, position.y, false /* isEnemyPlayer */, placeHolder.IsFrontRow); // Replace unit in boardUnits int index = this.boardUnits.IndexOf(placeHolder); this.boardUnits[index] = cardScript; placeHolder.ShouldReplaceWithRealUnit = false; }
private void RerenderRow(bool isEnemyPlayer, bool isFrontRow) { // Move rest of ships to account for removed space List <IBoardUnit> unitsList = this.GetBoardUnitsForRow(isEnemyPlayer, isFrontRow); List <Vector2> unitPositions = this.GetUnitPositionsForRow(isEnemyPlayer, isFrontRow, unitsList.Count); for (int i = 0; i < unitsList.Count; i++) { IBoardUnit unit = unitsList[i]; if (!unit.IsTempSpaceholder) { ((CardScript)unit).MoveHorizontally(unitPositions[i]); } else { PlaceholderBoardUnit placeHolder = (PlaceholderBoardUnit)unit; if (placeHolder.ShouldReplaceWithRealUnit) { InsertNewUnitOnBoard(placeHolder, unitPositions[i]); } } } }
public void OnDropCard(PlayerHandFullCard fullCard, Vector2 dropPosition) { this.boardUnits.Remove(this.tempDropOverCard); int dropRow = this.GetRowPositionFromDropPosition(dropPosition); if (dropRow == 0) { // Return card to hand if not dropped on board fullCard.HideFullCardShowMiniCard(); } else { // Replace placeholder with real unit when rendering PlaceholderBoardUnit placeHolderUnit = this.AddDropOverPlaceHolderAtPosition(dropPosition, dropRow == 1); placeHolderUnit.ShouldReplaceWithRealUnit = true; // Remove card from hand fullCard.RemovePlayerHandCard(); } // Move units accordingly this.RerenderPlayerRows(); }