Пример #1
0
        //寻路主要逻辑,通过调用该方法来获取路径信息,由一串Point2代表
        public List <APoint> FindPath(APoint beginPos, APoint endPos)
        {
            List <APoint> result = new List <APoint>();

            this.endPos = endPos;
            APoint currentPos = beginPos;

            openSet.Add(currentPos);

            while (!currentPos.Equals(this.endPos))
            {
                UpdatePath(currentPos);
                if (openSet.Count == 0)
                {
                    return(null);
                }

                currentPos = openTree.First().Value.First();
            }

            APoint path = currentPos;

            while (!path.Equals(beginPos))
            {
                result.Add(path);
                path        = allNodes[path].parent.position;
                currentPath = result;
            }

            result.Add(beginPos);
            return(result);
        }