public void SelectUnit(int index, TroopLocation location, bool isNullUnit) { if (selectedUnit.location == TroopLocation.NULL && !isNullUnit) { selectedUnit.index = index; selectedUnit.location = location; } else if (location != TroopLocation.NULL && selectedUnit.location != TroopLocation.NULL) { TroopLocation temp = selectedUnit.location; selectedUnit.location = TroopLocation.NULL; GameManager.instance.TransferUnits(temp, selectedUnit.index, location, index); } else { selectedUnit.location = location; selectedUnit.index = index; } if (OnSelectedUnitChange != null) { OnSelectedUnitChange(); } }
public void TransferUnits(TroopLocation from, int fromIndex, TroopLocation to, int toIndex, int amount = -1) { Unit tempUnit; switch (from) { case TroopLocation.BARRACKS: if (amount == -1) { amount = CurrentGame.barracksUnits.units[fromIndex].amount; } switch (to) { case TroopLocation.BARRACKS: if (fromIndex == toIndex) { return; } tempUnit = currentGame.barracksUnits.AddUnits(CurrentGame.barracksUnits.units[fromIndex], amount, toIndex); currentGame.barracksUnits.AddUnits(CurrentGame.barracksUnits.units[fromIndex], -amount, fromIndex); if (tempUnit != null) { currentGame.barracksUnits.AddUnits(tempUnit, tempUnit.amount, fromIndex); } return; case TroopLocation.PLAYER: tempUnit = currentGame.playerTroop.AddUnits(CurrentGame.barracksUnits.units[fromIndex], amount, toIndex); currentGame.barracksUnits.AddUnits(CurrentGame.barracksUnits.units[fromIndex], -amount, fromIndex); if (tempUnit != null) { currentGame.barracksUnits.AddUnits(tempUnit, tempUnit.amount, fromIndex); } return; default: return; } case TroopLocation.RECRUITABLE: if (amount == -1) { amount = CurrentGame.recruitableUnits.units[fromIndex].amount; } switch (to) { case TroopLocation.BARRACKS: currentGame.barracksUnits.AddUnits(CurrentGame.recruitableUnits.units[fromIndex], amount, toIndex); currentGame.recruitableUnits.AddUnits(CurrentGame.recruitableUnits.units[fromIndex], -amount, fromIndex); return; default: return; } case TroopLocation.PLAYER: if (amount == -1) { amount = CurrentGame.playerTroop.units[fromIndex].amount; } switch (to) { case TroopLocation.BARRACKS: tempUnit = currentGame.barracksUnits.AddUnits(CurrentGame.playerTroop.units[fromIndex], amount, toIndex); currentGame.playerTroop.AddUnits(CurrentGame.playerTroop.units[fromIndex], -amount, fromIndex); if (tempUnit != null) { currentGame.playerTroop.AddUnits(tempUnit, tempUnit.amount, fromIndex); } return; case TroopLocation.PLAYER: tempUnit = currentGame.playerTroop.AddUnits(CurrentGame.playerTroop.units[fromIndex], amount, toIndex); currentGame.playerTroop.AddUnits(CurrentGame.playerTroop.units[fromIndex], -amount, fromIndex); if (tempUnit != null) { currentGame.playerTroop.AddUnits(tempUnit, tempUnit.amount, fromIndex); } return; default: return; } default: return; } }