public CEPathFindResult GetPathFindResult(CEPathFindNode _endNode) { var result = new CEPathFindResult(); int maxNum = 1; var node = _endNode; while (node.parent != null) { node = node.parent; maxNum++; } result.isHavePath = true; result.paths = new CEIntVector2[maxNum]; node = _endNode; while (node != null) { result.paths [maxNum - 1] = new CEIntVector2(node.x, node.y); node = node.parent; maxNum--; } return(result); }
// Update is called once per frame private void Update() { if (mAllAgentProxyList.Count <= 0) { return; } mAllAgentProxyList.ForEach(proxy => { bool isFinish; CEPathFindResult result; proxy.agent.TickSearch(out isFinish, out result); proxy.searchTime++; if (!isFinish && proxy.searchTime >= MAX_SEARCH_TIME) { isFinish = true; result = new CEPathFindResult { isHavePath = false }; Debug.LogError("Reach CEPathFind max loop"); mShareAgent.DebugOutput(); } if (!isFinish) { return; } proxy.callback(result); proxy.isFinish = true; }); mAllAgentProxyList.RemoveAll(proxy => proxy.isFinish); }
/// <summary> /// 一次性返回搜索结果,用于小图搜索 /// </summary> public static CEPathFindResult FindPath(int _starTileX, int _starTileY, int _endTileX, int _endTileY, CEPathFindMapAgent _findEngine) { if (mShareAgent == null) { mShareAgent = new CEPathFindAgent(); } mShareAgent.Reset(_findEngine, _starTileX, _starTileY, _endTileX, _endTileY); CEPathFindResult result = null; var isFinish = false; var searchTime = 0; while (!isFinish) { mShareAgent.TickSearch(out isFinish, out result); searchTime++; if (searchTime >= MAX_SEARCH_TIME && !isFinish) { isFinish = true; result = new CEPathFindResult { isHavePath = false }; Debug.LogError("Reach CEPathFind max loop"); mShareAgent.DebugOutput(); } } return(result); }
public static CEPathFindResult FindPath(int _starTileX, int _starTileY, int _endTileX, int _endTileY, CEPathFindBasic _findEngine) { if (mShareAgent == null) { mShareAgent = new CEPathFindAgent(); } mShareAgent.Reset(_findEngine, _starTileX, _starTileY, _endTileX, _endTileY); CEPathFindResult result = null; bool isFinish = false; while (!isFinish) { mShareAgent.TickSearch(out isFinish, out result); } return(result); }
public void TickSearch(out bool _isFinish, out CEPathFindResult _reuslt) { //起始节点和结束节点本身就无法走 if (!mStarNode.isWalkable || !mEndNode.isWalkable) { _isFinish = true; _reuslt = new CEPathFindResult(); _reuslt.isHavePath = false; RecyleNodes(); return; } for (var i = 0; i < EACH_TICK_SEARCH_NODE_NUM; i++) { if (mCurrentNode.x == mEndNode.x && mCurrentNode.y == mEndNode.y) { _isFinish = true; _reuslt = GetPathFindResult(mCurrentNode); RecyleNodes(); return; } mCloseList.Add(mCurrentNode); CheckCurrentSearchAroundTile(); if (mOpenList.Count == 0) { //没有Open节点了,全部搜索过,但未找到路径 _isFinish = true; _reuslt = new CEPathFindResult(); _reuslt.isHavePath = false; RecyleNodes(); return; } mOpenList.Sort(SortListByScore); mCurrentNode = mOpenList [0]; mOpenList.RemoveAt(0); } _isFinish = false; _reuslt = null; return; }
// Update is called once per frame void Update() { if (mAllAgentProxyList.Count > 0) { mAllAgentProxyList.ForEach(proxy => { bool isFinish; CEPathFindResult result = null; proxy.agent.TickSearch(out isFinish, out result); if (isFinish) { proxy.callback(result); proxy.isFinish = true; } }); mAllAgentProxyList.RemoveAll(proxy => proxy.isFinish == true); } }