public static bool TargetInRange(Vector3 targetPos, EffectiveRangeType rangeType, Vector3 position, float direction = -1f, float param1 = 0f, float param2 = 0f) { if (direction == -1f) { return(UnitFeature.TargetInRange(targetPos, rangeType, position, Vector3.zero, param1, param2)); } return(UnitFeature.TargetInRange(targetPos, rangeType, position, new Vector3(0f, 0f, direction), param1, param2)); }
public static List <Units> findTargets(Units self, Vector3 pos, SkillTargetCamp targetType, global::TargetTag targetTag, EffectiveRangeType rangeType, float param1 = 0f, float param2 = 0f, int max_num = -1) { List <Units> list = new List <Units>(); List <int> targets = null; switch (targetType) { case SkillTargetCamp.Self: list.Add(self); break; case SkillTargetCamp.Enemy: targets = TeamManager.GetOtherTeam(self.team, Relation.Hostility, true); break; case SkillTargetCamp.Partener: targets = TeamManager.GetOtherTeam(self.team, Relation.Friendly, true); break; case SkillTargetCamp.AttackYouTarget: { Units attackedYouTarget = self.GetAttackedYouTarget(); if (attackedYouTarget != null) { list.Add(attackedYouTarget); } targets = TeamManager.GetOtherTeam(self.team, Relation.Hostility, true); break; } case SkillTargetCamp.SkillHitTarget: { Units skillHitedTarget = self.GetSkillHitedTarget(); if (skillHitedTarget != null) { list.Add(skillHitedTarget); } return(list); } case SkillTargetCamp.AttackTarget: { Units attackTarget = self.GetAttackTarget(); if (attackTarget != null) { list.Add(attackTarget); } targets = TeamManager.GetOtherTeam(self.team, Relation.Hostility, true); break; } case SkillTargetCamp.SkillHitYouTarget: { Units skillHitedYouTarget = self.GetSkillHitedYouTarget(); if (skillHitedYouTarget != null) { list.Add(skillHitedYouTarget); } return(list); } case SkillTargetCamp.SelectTarget: if (self.currentSkillOrAttack != null) { return(self.currentSkillOrAttack.attackTargets); } return(list); } if (list.Count <= 0) { switch (rangeType) { case EffectiveRangeType.JuXing: case EffectiveRangeType.YuanXing: case EffectiveRangeType.ShanXing: case EffectiveRangeType.Single: { float radius = (param1 <= param2) ? param2 : param1; int layerMask = 1 << LayerMask.NameToLayer("Vehicle"); Collider[] array = Physics.OverlapSphere(pos, radius, layerMask); for (int i = 0; i < array.Length; i++) { if (array[i] != null) { Collider collider = array[i]; GameObject gameObject = collider.transform.parent.gameObject; Units component = gameObject.GetComponent <Units>(); if (max_num == -1 || list.Count < max_num) { if (TagManager.CheckTag(component, targetTag)) { if (UnitFeature.TargetInRange(collider.transform.position, rangeType, pos, self.transform.eulerAngles, param1, param2)) { if (TeamManager.CheckTeam(self.gameObject, gameObject, targetType, null)) { if (!(component == null) && component.isLive && component.CanSkillSelected) { if (!list.Contains(component)) { list.Add(component); } } } } } } } } break; } case EffectiveRangeType.AllMap: { Dictionary <int, Units> allMapUnits = MapManager.Instance.GetAllMapUnits(); Dictionary <int, Units> .Enumerator enumerator = allMapUnits.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <int, Units> current = enumerator.Current; Units value = current.Value; if (!(value == null) && value.isLive && value.CanSkillSelected) { if (max_num == -1 || list.Count < max_num) { if (TagManager.CheckTag(value, targetTag)) { if (TeamManager.CheckTeamType(value.teamType, targets)) { if (!list.Contains(value)) { list.Add(value); } } } } } } break; } case EffectiveRangeType.Link: { float num = (param1 <= param2) ? param2 : param1; int layerMask2 = 1 << LayerMask.NameToLayer("Vehicle"); if (max_num > 0) { if (!(self == null)) { Units attackTarget2 = self.GetAttackTarget(); if (!(attackTarget2 == null)) { list.Add(attackTarget2); pos = attackTarget2.transform.position; while (list.Count < max_num) { bool flag = false; Units units = null; float num2 = -1f; Collider[] array2 = Physics.OverlapSphere(pos, num, layerMask2); for (int j = 0; j < array2.Length; j++) { if (array2[j] != null) { Collider collider2 = array2[j]; GameObject gameObject2 = collider2.transform.parent.gameObject; Units component2 = gameObject2.GetComponent <Units>(); if (max_num != -1 && list.Count >= max_num) { break; } if (TagManager.CheckTag(component2, targetTag)) { if (TeamManager.CheckTeam(self.gameObject, gameObject2, targetType, null)) { if (!(component2 == null) && component2.isLive && component2.CanSkillSelected) { if (!list.Contains(component2)) { if ((units == null || num2 > (pos - component2.transform.position).sqrMagnitude) && (pos - component2.transform.position).sqrMagnitude < num * num) { units = component2; num2 = (pos - component2.transform.position).sqrMagnitude; } if (units != null) { flag = true; } } } } } } } if (!flag) { break; } list.Add(units); pos = units.transform.position; } } } } break; } } } return(list); }