From ee2cbc86ed58ae03a092b67690d3869ebe78fd20 Mon Sep 17 00:00:00 2001 From: chenxin <chenxin6991@163.com> Date: Sat, 28 Nov 2020 18:04:52 +0800 Subject: [PATCH] 解决木精灵在打泡泡和木小怪时索敌问题,只打泡泡不打小怪 --- Assets/Scripts/TowerDefense/Level/AgentInsManager.cs | 92 +++++++++++++++++++++++++++++---------------- 1 files changed, 59 insertions(+), 33 deletions(-) diff --git a/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs b/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs index ce99dd9..221492e 100644 --- a/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs +++ b/Assets/Scripts/TowerDefense/Level/AgentInsManager.cs @@ -78,44 +78,68 @@ /// </summary> public List<Agent> listAgent { get { return this.agentInsList; } } - /// <summary> - /// 获取距目标结点最近的Agent. - /// </summary> - /// <returns></returns> - public Agent getMinDisAgent(bool _noPoison = false) + // /// <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; + // } + // }); + + // 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() { - if (agentInsList.Count == 0) return null; + Agent ret = null; + float minDistance = -1f; - // 排序,然后返回对应的数据 - // 直接使用闭包函数来进行排序: - agentInsList.Sort((left, right) => + 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 (left.distanceToDest > right.distanceToDest) - { - return 1; - } - else if (left.distanceToDest == right.distanceToDest) - { - return 0; - } - else - { - return -1; - } - }); + float distance = Mathf.Abs(agents[i].transform.position.z - endPos.z); - if (_noPoison) - { - for (int ti = 0; ti < agentInsList.Count; ti++) + if (minDistance < 0 || distance < minDistance) { - if (!agentInsList[ti].bInPoison) - return agentInsList[ti]; + minDistance = distance; + ret = agents[i]; } - - return null; } - else - return agentInsList[0]; + + return ret; } } @@ -314,9 +338,11 @@ 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; -- Gitblit v1.9.1