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); }
UIUnitSlot GetUIUnitSlot(UnitPlace place) { for (int i = 0; i < UnitSlotsRO.Length; i++) { UIUnitSlot slot = UnitSlotsRO[i]; if (slot != null && slot.Place.Range == place.Range && slot.Place.Position == place.Position) { return(slot); } } return(null); }
UIUnitSlot GetUIUnitSlot(UnitPlace place) { for (int i = 0; i < UnitSlotsRO.Length; i++) { UIUnitSlot slot = UnitSlotsRO[i]; if (slot != null && slot.Place.Range == place.Range && slot.Place.Position == place.Position) return slot; } return null; }
string GetPlaceName(UnitPlace place) { return place.Range + " " + place.Position; }
UnitPlace GetNextTargetPlace(UnitPlace attackPlace, UnitPlace currentPlace) { switch (attackPlace.Position) { case EUnitPosition.Middle: if (attackPlace.Range == EUnitRange.Ranged || attackPlace.Range == EUnitRange.Melee) { if (currentPlace.Range == EUnitRange.Melee) return new UnitPlace() { Range = EUnitRange.Ranged, Position = currentPlace.Position }; else if (currentPlace.Range == EUnitRange.Ranged) { if (currentPlace.Position == EUnitPosition.Middle) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top }; else if (currentPlace.Position == EUnitPosition.Top) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom }; else if (currentPlace.Position == EUnitPosition.Bottom) return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle }; } else return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle }; } else { if (currentPlace.Position == EUnitPosition.Middle) { if (currentPlace.Range == EUnitRange.Ranged || currentPlace.Range == EUnitRange.Melee) return new UnitPlace() { Range = currentPlace.Range, Position = EUnitPosition.Top }; else return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle }; } else if (currentPlace.Position == EUnitPosition.Top) return new UnitPlace() { Range = currentPlace.Range, Position = EUnitPosition.Bottom }; else if (currentPlace.Position == EUnitPosition.Bottom) { if (currentPlace.Range == EUnitRange.Melee) return new UnitPlace() { Range = EUnitRange.Ranged, Position = EUnitPosition.Middle }; else if (currentPlace.Range == EUnitRange.Ranged) return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle }; } } break; case EUnitPosition.Top: if (currentPlace.Range == EUnitRange.Melee) return new UnitPlace() { Range = EUnitRange.Ranged, Position = currentPlace.Position }; else if (currentPlace.Range == EUnitRange.Ranged) { if (currentPlace.Position == EUnitPosition.Top) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle }; else if (currentPlace.Position == EUnitPosition.Middle) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom }; else if (currentPlace.Position == EUnitPosition.Bottom) return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle }; } else return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top }; break; case EUnitPosition.Bottom: if (currentPlace.Range == EUnitRange.Melee) return new UnitPlace() { Range = EUnitRange.Ranged, Position = currentPlace.Position }; else if (currentPlace.Range == EUnitRange.Ranged) { if (currentPlace.Position == EUnitPosition.Bottom) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle }; else if (currentPlace.Position == EUnitPosition.Middle) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top }; else if (currentPlace.Position == EUnitPosition.Top) return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle }; } else return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom }; break; } return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.None }; }
BaseUnitBehaviour GetPlaceBaseUnitBehaviour(ArrayRO<BaseUnitBehaviour> units, UnitPlace place) { for (int i = 0; i < units.Length; i++) { BaseUnitBehaviour possibleUnit = units[i]; if (possibleUnit.Place.Range == place.Range && possibleUnit.Place.Position == place.Position) return possibleUnit; } return null; }
UnitPlace GetNextAttackPlace(UnitPlace attackPlace) { switch (attackPlace.Range) { case EUnitRange.Melee: return new UnitPlace() { Range = EUnitRange.Ranged, Position = attackPlace.Position }; case EUnitRange.Ranged: if (attackPlace.Position == EUnitPosition.Middle) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top }; else if (attackPlace.Position == EUnitPosition.Top) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom }; else if (attackPlace.Position == EUnitPosition.Bottom) return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle }; break; case EUnitRange.None: if (attackPlace.Position == EUnitPosition.Middle) return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle }; break; } return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.None }; }
public UnitSlot(UnitPlace place, EUnitKey unit) { _place = place; _unit = unit; }
UnitPlace GetNextTargetPlace(UnitPlace attackPlace, UnitPlace currentPlace) { switch (attackPlace.Position) { case EUnitPosition.Middle: if (attackPlace.Range == EUnitRange.Ranged || attackPlace.Range == EUnitRange.Melee) { if (currentPlace.Range == EUnitRange.Melee) { return new UnitPlace() { Range = EUnitRange.Ranged, Position = currentPlace.Position } } ; else if (currentPlace.Range == EUnitRange.Ranged) { if (currentPlace.Position == EUnitPosition.Middle) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top } } ; else if (currentPlace.Position == EUnitPosition.Top) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom } } ; else if (currentPlace.Position == EUnitPosition.Bottom) { return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle } } ; } else { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle } }; } else { if (currentPlace.Position == EUnitPosition.Middle) { if (currentPlace.Range == EUnitRange.Ranged || currentPlace.Range == EUnitRange.Melee) { return new UnitPlace() { Range = currentPlace.Range, Position = EUnitPosition.Top } } ; else { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle } }; } else if (currentPlace.Position == EUnitPosition.Top) { return new UnitPlace() { Range = currentPlace.Range, Position = EUnitPosition.Bottom } } ; else if (currentPlace.Position == EUnitPosition.Bottom) { if (currentPlace.Range == EUnitRange.Melee) { return new UnitPlace() { Range = EUnitRange.Ranged, Position = EUnitPosition.Middle } } ; else if (currentPlace.Range == EUnitRange.Ranged) { return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle } } ; } } break; case EUnitPosition.Top: if (currentPlace.Range == EUnitRange.Melee) { return new UnitPlace() { Range = EUnitRange.Ranged, Position = currentPlace.Position } } ; else if (currentPlace.Range == EUnitRange.Ranged) { if (currentPlace.Position == EUnitPosition.Top) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle } } ; else if (currentPlace.Position == EUnitPosition.Middle) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom } } ; else if (currentPlace.Position == EUnitPosition.Bottom) { return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle } } ; } else { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top } }; break; case EUnitPosition.Bottom: if (currentPlace.Range == EUnitRange.Melee) { return new UnitPlace() { Range = EUnitRange.Ranged, Position = currentPlace.Position } } ; else if (currentPlace.Range == EUnitRange.Ranged) { if (currentPlace.Position == EUnitPosition.Bottom) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle } } ; else if (currentPlace.Position == EUnitPosition.Middle) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top } } ; else if (currentPlace.Position == EUnitPosition.Top) { return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle } } ; } else { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom } }; break; } return(new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.None }); } #endregion string GetUnitName(BaseUnitBehaviour unit) { return(unit != null ? unit.name : string.Empty); } string GetPlaceName(UnitPlace place) { return(place.Range + " " + place.Position); } }
UnitPlace GetNextAttackPlace(UnitPlace attackPlace) { switch (attackPlace.Range) { case EUnitRange.Melee: return(new UnitPlace() { Range = EUnitRange.Ranged, Position = attackPlace.Position }); case EUnitRange.Ranged: if (attackPlace.Position == EUnitPosition.Middle) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Top } } ; else if (attackPlace.Position == EUnitPosition.Top) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Bottom } } ; else if (attackPlace.Position == EUnitPosition.Bottom) { return new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.Middle } } ; break; case EUnitRange.None: if (attackPlace.Position == EUnitPosition.Middle) { return new UnitPlace() { Range = EUnitRange.Melee, Position = EUnitPosition.Middle } } ; break; } return(new UnitPlace() { Range = EUnitRange.None, Position = EUnitPosition.None }); } BaseUnitBehaviour GetPlaceBaseUnitBehaviour(ArrayRO <BaseUnitBehaviour> units, UnitPlace place) { for (int i = 0; i < units.Length; i++) { BaseUnitBehaviour possibleUnit = units[i]; if (possibleUnit.Place.Range == place.Range && possibleUnit.Place.Position == place.Position) { return(possibleUnit); } } return(null); }
private void Awake() { myUnitPlace = transform.GetComponentInParent <UnitPlace>(); myColor = GetComponent <Image>().color; }