|
@@ -190,41 +190,150 @@ public class SearchTrigger : MonoBehaviour
|
|
|
return list;
|
|
return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Character GetMinDisTarget(List<TargetType> targetTypes, bool canHitFly)
|
|
|
|
|
|
|
+ public Character GetMinDisTarget(List<TargetType> targetTypes, bool canHitFly,SearchMode searchMode)
|
|
|
{
|
|
{
|
|
|
if (!enabled || !gameObject.activeInHierarchy)
|
|
if (!enabled || !gameObject.activeInHierarchy)
|
|
|
{
|
|
{
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
List<Character> list = GetAllTargets(targetTypes, canHitFly);
|
|
List<Character> list = GetAllTargets(targetTypes, canHitFly);
|
|
|
-
|
|
|
|
|
- Character minDisChar = null;
|
|
|
|
|
- float minDistance = -1;
|
|
|
|
|
- for (int i = 0; i < list.Count; i++)
|
|
|
|
|
|
|
+ switch (searchMode)
|
|
|
{
|
|
{
|
|
|
- Character character = list[i];
|
|
|
|
|
- //判断对象是否在远程单位的射击夹角范围内
|
|
|
|
|
- AttackController.AttackMethod am = owner.attackController.curAttackMethod;
|
|
|
|
|
- if (am.attackType == AttackController.AttackType.Shoot)
|
|
|
|
|
- {
|
|
|
|
|
- float up = am.maxUpAngle;
|
|
|
|
|
- float down = am.maxDownAngle;
|
|
|
|
|
- Vector3 dir = character.beSearchTrigger.transform.position - transform.position;
|
|
|
|
|
- float angle = Vector3.Angle(dir, Vector3.left * owner.bodyTrans.localScale.x);
|
|
|
|
|
- if ((dir.y > 0 && angle > up) || (dir.y < 0 && angle > down))
|
|
|
|
|
|
|
+ case SearchMode.MinDistance:
|
|
|
|
|
+ Character minDisChar = null;
|
|
|
|
|
+ float minDistance = -1;
|
|
|
|
|
+ for (int i = 0; i < list.Count; i++)
|
|
|
{
|
|
{
|
|
|
- continue;
|
|
|
|
|
|
|
+ Character character = list[i];
|
|
|
|
|
+ //判断对象是否在远程单位的射击夹角范围内
|
|
|
|
|
+ AttackController.AttackMethod am = owner.attackController.curAttackMethod;
|
|
|
|
|
+ if (am.attackType == AttackController.AttackType.Shoot)
|
|
|
|
|
+ {
|
|
|
|
|
+ float up = am.maxUpAngle;
|
|
|
|
|
+ float down = am.maxDownAngle;
|
|
|
|
|
+ Vector3 dir = character.beSearchTrigger.transform.position - transform.position;
|
|
|
|
|
+ float angle = Vector3.Angle(dir, Vector3.left * owner.bodyTrans.localScale.x);
|
|
|
|
|
+ if ((dir.y > 0 && angle > up) || (dir.y < 0 && angle > down))
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //判断是否在攻击范围内
|
|
|
|
|
+ float distance = Mathf.Abs(character.transform.position.x - owner.transform.position.x);
|
|
|
|
|
+ if (minDisChar == null || minDistance == -1 || minDistance > distance)
|
|
|
|
|
+ {
|
|
|
|
|
+ minDisChar = character;
|
|
|
|
|
+ minDistance = distance;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- //判断是否在攻击范围内
|
|
|
|
|
- float distance = Mathf.Abs(character.transform.position.x - owner.transform.position.x);
|
|
|
|
|
- if (minDisChar == null || minDistance == -1 || minDistance > distance)
|
|
|
|
|
- {
|
|
|
|
|
- minDisChar = character;
|
|
|
|
|
- minDistance = distance;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return minDisChar;
|
|
|
|
|
+ case SearchMode.MaxDistance:
|
|
|
|
|
+ Character maxDisChar = null;
|
|
|
|
|
+ float maxDistance = -1;
|
|
|
|
|
+ for (int i = 0; i < list.Count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Character character = list[i];
|
|
|
|
|
+ //判断对象是否在远程单位的射击夹角范围内
|
|
|
|
|
+ AttackController.AttackMethod am = owner.attackController.curAttackMethod;
|
|
|
|
|
+ if (am.attackType == AttackController.AttackType.Shoot)
|
|
|
|
|
+ {
|
|
|
|
|
+ float up = am.maxUpAngle;
|
|
|
|
|
+ float down = am.maxDownAngle;
|
|
|
|
|
+ Vector3 dir = character.beSearchTrigger.transform.position - transform.position;
|
|
|
|
|
+ float angle = Vector3.Angle(dir, Vector3.left * owner.bodyTrans.localScale.x);
|
|
|
|
|
+ if ((dir.y > 0 && angle > up) || (dir.y < 0 && angle > down))
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //判断是否在攻击范围内
|
|
|
|
|
+ float distance = Mathf.Abs(character.transform.position.x - owner.transform.position.x);
|
|
|
|
|
+ if (maxDisChar == null || maxDistance == -1 || maxDistance < distance)
|
|
|
|
|
+ {
|
|
|
|
|
+ maxDisChar = character;
|
|
|
|
|
+ maxDistance = distance;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ Debug.Log(maxDisChar);
|
|
|
|
|
+ return maxDisChar;
|
|
|
|
|
+ case SearchMode.MinHp:
|
|
|
|
|
+ Character minHPChar = null;
|
|
|
|
|
+ for (int i = 0; i < list.Count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Character character = list[i];
|
|
|
|
|
+ //判断对象是否在远程单位的射击夹角范围内
|
|
|
|
|
+ AttackController.AttackMethod am = owner.attackController.curAttackMethod;
|
|
|
|
|
+ if (am.attackType == AttackController.AttackType.Shoot)
|
|
|
|
|
+ {
|
|
|
|
|
+ float up = am.maxUpAngle;
|
|
|
|
|
+ float down = am.maxDownAngle;
|
|
|
|
|
+ Vector3 dir = character.beSearchTrigger.transform.position - transform.position;
|
|
|
|
|
+ float angle = Vector3.Angle(dir, Vector3.left * owner.bodyTrans.localScale.x);
|
|
|
|
|
+ if ((dir.y > 0 && angle > up) || (dir.y < 0 && angle > down))
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (minHPChar == null || minHPChar.hp < character.hp)
|
|
|
|
|
+ {
|
|
|
|
|
+ minHPChar = character;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return minHPChar;
|
|
|
|
|
+ case SearchMode.MaxHp:
|
|
|
|
|
+ Character maxHPChar = null;
|
|
|
|
|
+ for (int i = 0; i < list.Count; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ Character character = list[i];
|
|
|
|
|
+ //判断对象是否在远程单位的射击夹角范围内
|
|
|
|
|
+ AttackController.AttackMethod am = owner.attackController.curAttackMethod;
|
|
|
|
|
+ if (am.attackType == AttackController.AttackType.Shoot)
|
|
|
|
|
+ {
|
|
|
|
|
+ float up = am.maxUpAngle;
|
|
|
|
|
+ float down = am.maxDownAngle;
|
|
|
|
|
+ Vector3 dir = character.beSearchTrigger.transform.position - transform.position;
|
|
|
|
|
+ float angle = Vector3.Angle(dir, Vector3.left * owner.bodyTrans.localScale.x);
|
|
|
|
|
+ if ((dir.y > 0 && angle > up) || (dir.y < 0 && angle > down))
|
|
|
|
|
+ {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (maxHPChar == null || maxHPChar.hp > character.hp)
|
|
|
|
|
+ {
|
|
|
|
|
+ maxHPChar = character;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return maxHPChar;
|
|
|
|
|
+ case SearchMode.ByType:
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
- return minDisChar;
|
|
|
|
|
|
|
+ //Character minDisChar = null;
|
|
|
|
|
+ //float minDistance = -1;
|
|
|
|
|
+ //for (int i = 0; i < list.Count; i++)
|
|
|
|
|
+ //{
|
|
|
|
|
+ // Character character = list[i];
|
|
|
|
|
+ // //判断对象是否在远程单位的射击夹角范围内
|
|
|
|
|
+ // AttackController.AttackMethod am = owner.attackController.curAttackMethod;
|
|
|
|
|
+ // if (am.attackType == AttackController.AttackType.Shoot)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // float up = am.maxUpAngle;
|
|
|
|
|
+ // float down = am.maxDownAngle;
|
|
|
|
|
+ // Vector3 dir = character.beSearchTrigger.transform.position - transform.position;
|
|
|
|
|
+ // float angle = Vector3.Angle(dir, Vector3.left * owner.bodyTrans.localScale.x);
|
|
|
|
|
+ // if ((dir.y > 0 && angle > up) || (dir.y < 0 && angle > down))
|
|
|
|
|
+ // {
|
|
|
|
|
+ // continue;
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ // //判断是否在攻击范围内
|
|
|
|
|
+ // float distance = Mathf.Abs(character.transform.position.x - owner.transform.position.x);
|
|
|
|
|
+ // if (minDisChar == null || minDistance == -1 || minDistance > distance)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // minDisChar = character;
|
|
|
|
|
+ // minDistance = distance;
|
|
|
|
|
+ // }
|
|
|
|
|
+ //}
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Character GetMinHPCharacter(List<TargetType> targetTypes, bool canHitFly)
|
|
public Character GetMinHPCharacter(List<TargetType> targetTypes, bool canHitFly)
|
|
@@ -243,3 +352,12 @@ public class SearchTrigger : MonoBehaviour
|
|
|
return minHPChar;
|
|
return minHPChar;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+public enum SearchMode
|
|
|
|
|
+{
|
|
|
|
|
+ MinDistance,
|
|
|
|
|
+ MaxDistance,
|
|
|
|
|
+ MinHp,
|
|
|
|
|
+ MaxHp,
|
|
|
|
|
+ ByType
|
|
|
|
|
+}
|