| | |
| | | /// </summary> |
| | | public List<Agent> listAgent { get { return this.agentInsList; } } |
| | | |
| | | /// <summary> |
| | | /// 获取距目标结点最近的Agent. |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Agent getMinDisAgent(bool _noPoison = false) |
| | | { |
| | | if (agentInsList.Count == 0) return null; |
| | | // /// <summary> |
| | | // /// 获取距目标结点最近的Agent. |
| | | // /// </summary> |
| | | // /// <returns></returns> |
| | | // public Agent getMinDisAgent(bool _noPoison = false) |
| | | // { |
| | | // if (agentInsList.Count == 0) return null; |
| | | |
| | | // 排序,然后返回对应的数据 |
| | | // 直接使用闭包函数来进行排序: |
| | | agentInsList.Sort((left, right) => |
| | | { |
| | | if (left.distanceToDest > right.distanceToDest) |
| | | { |
| | | return 1; |
| | | } |
| | | else if (left.distanceToDest == right.distanceToDest) |
| | | { |
| | | return 0; |
| | | } |
| | | else |
| | | { |
| | | return -1; |
| | | } |
| | | }); |
| | | // // 排序,然后返回对应的数据 |
| | | // // 直接使用闭包函数来进行排序: |
| | | // agentInsList.Sort((left, right) => |
| | | // { |
| | | // if (left.distanceToDest > right.distanceToDest) |
| | | // { |
| | | // return 1; |
| | | // } |
| | | // else if (left.distanceToDest == right.distanceToDest) |
| | | // { |
| | | // return 0; |
| | | // } |
| | | // else |
| | | // { |
| | | // return -1; |
| | | // } |
| | | // }); |
| | | |
| | | if (_noPoison) |
| | | // if (_noPoison) |
| | | // { |
| | | // for (int ti = 0; ti < agentInsList.Count; ti++) |
| | | // { |
| | | // if (!agentInsList[ti].bInPoison) |
| | | // return agentInsList[ti]; |
| | | // } |
| | | |
| | | // return null; |
| | | // } |
| | | // else |
| | | // return agentInsList[0]; |
| | | // } |
| | | |
| | | public Agent GetMinDistanceAgent() |
| | | { |
| | | for (int ti = 0; ti < agentInsList.Count; ti++) |
| | | Agent ret = null; |
| | | float minDistance = -1f; |
| | | |
| | | WaveLineAgentInsMgr[] waveLineAgentIns = AgentInsManager.instance.GetWaveLineList(); |
| | | WaveLineAgentInsMgr waveLineAgentInsMgr = waveLineAgentIns[waveLineID]; |
| | | List<Agent> agents = waveLineAgentInsMgr.listAgent; |
| | | Vector3 endPos = EndlessLevelManager.instance.GetHomeBasePosition(waveLineID + 1); |
| | | |
| | | for (int i = 0; i < agents.Count; ++i) |
| | | { |
| | | if (!agentInsList[ti].bInPoison) |
| | | return agentInsList[ti]; |
| | | float distance = Mathf.Abs(agents[i].transform.position.z - endPos.z); |
| | | |
| | | if (minDistance < 0 || distance < minDistance) |
| | | { |
| | | minDistance = distance; |
| | | ret = agents[i]; |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | else |
| | | return agentInsList[0]; |
| | | return ret; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | Agent ag; |
| | | if (oppo) |
| | | ag = oppoAgentWaveLineArray[lineid].getMinDisAgent(noPoison); |
| | | // ag = oppoAgentWaveLineArray[lineid].getMinDisAgent(noPoison); |
| | | ag = oppoAgentWaveLineArray[lineid].GetMinDistanceAgent(); |
| | | else |
| | | ag = agentWaveLineArray[lineid].getMinDisAgent(noPoison); |
| | | // ag = agentWaveLineArray[lineid].getMinDisAgent(noPoison); |
| | | ag = agentWaveLineArray[lineid].GetMinDistanceAgent(); |
| | | |
| | | // 这一行防止无限的循环下去。 |
| | | if (forceGet) return ag; |