Пример #1
0
        private static CEPathFindResult GetPathFindResult(CEPathFindNode _endNode)
        {
            var result = new CEPathFindResult();
            var maxNum = 1;
            var node   = _endNode;

            while (node.parent != null)
            {
                node = node.parent;
                maxNum++;
            }

            result.isHavePath = true;
            result.paths      = new Vector2Int[maxNum];

            node = _endNode;
            while (node != null)
            {
                result.paths[maxNum - 1] = new Vector2Int(node.x, node.y);
                node = node.parent;
                maxNum--;
            }

            return(result);
        }
Пример #2
0
        public void TickSearch(out bool _isFinish, out CEPathFindResult _result)
        {
            //起始节点和结束节点本身就无法走
            if (!mStarNode.isWalkable || !mEndNode.isWalkable)
            {
                _isFinish = true;
                _result   = new CEPathFindResult {
                    isHavePath = false
                };
                RecycleNodes();
                return;
            }


            for (var i = 0; i < EACH_TICK_SEARCH_NODE_NUM; i++)
            {
                if (mCurrentNode.x == mEndNode.x && mCurrentNode.y == mEndNode.y)
                {
                    _isFinish = true;
                    _result   = GetPathFindResult(mCurrentNode);
                    RecycleNodes();
                    return;
                }

                mCloseList.Add(mCurrentNode);

                CheckCurrentSearchAroundTile();

                if (mOpenList.Count == 0)
                {
                    //没有Open节点了,全部搜索过,但未找到路径
                    _isFinish = true;
                    _result   = new CEPathFindResult {
                        isHavePath = false
                    };
                    RecycleNodes();
                    return;
                }

//                mOpenList.Sort(SortListByScore);
//                mCurrentNode = mOpenList[0];
//                mOpenList.RemoveAt(0);
                mCurrentNode = mOpenList.Remove();
            }

            _isFinish = false;
            _result   = null;
            return;
        }