public BaseUnitBehaviour GetTarget(BaseUnitBehaviour unit, BaseUnitBehaviour currentTarget, ArrayRO <BaseUnitBehaviour> possibleUnits) { UnitPlace currentTargetPlace = currentTarget != null ? currentTarget.Place : new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle }; UnitPlace nextTargetPlace = GetNextTargetPlace(unit.Place, currentTargetPlace); while (!nextTargetPlace.Equals(currentTargetPlace)) { if (nextTargetPlace.Range != EUnitRange.None || nextTargetPlace.Position != EUnitPosition.None) { BaseUnitBehaviour nextUnit = GetPlaceBaseUnitBehaviour(possibleUnits, nextTargetPlace); if (nextUnit != null && !nextUnit.UnitData.IsDead) { return(nextUnit); } } nextTargetPlace = GetNextTargetPlace(unit.Place, nextTargetPlace); } if (currentTarget != null) { return(currentTarget); } else { BaseUnitBehaviour nextUnit = GetPlaceBaseUnitBehaviour(possibleUnits, currentTargetPlace); return(nextUnit != null && !nextUnit.UnitData.IsDead ? nextUnit : null); } }
public BaseUnitBehaviour GetNextAttackUnit(BaseUnitBehaviour attackUnit) { bool currentIsAllyAttack = attackUnit != null && attackUnit.IsAlly; UnitPlace currentAttackPlace = attackUnit != null ? attackUnit.Place : new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle }; bool nextIsAllyAttack = !currentIsAllyAttack; UnitPlace nextAttackPlace = nextIsAllyAttack && attackUnit != null ? GetNextAttackPlace(currentAttackPlace) : currentAttackPlace; while (!(nextIsAllyAttack == currentIsAllyAttack && nextAttackPlace.Equals(currentAttackPlace))) { if (nextAttackPlace.Range != EUnitRange.None || nextAttackPlace.Position != EUnitPosition.None) { BaseUnitBehaviour nextUnit = GetPlaceBaseUnitBehaviour(nextIsAllyAttack ? FightManager.SceneInstance.AllyUnits : FightManager.SceneInstance.EnemyUnits, nextAttackPlace); if (nextUnit != null && !nextUnit.UnitData.IsDead) { return(nextUnit); } } nextIsAllyAttack = attackUnit != null ? !nextIsAllyAttack : nextIsAllyAttack; nextAttackPlace = nextIsAllyAttack ? GetNextAttackPlace(nextAttackPlace) : nextAttackPlace; if (attackUnit == null && nextIsAllyAttack.Equals(currentAttackPlace)) { nextIsAllyAttack = false; } } return(null); }