コード例 #1
0
        private void SetPathList(NavNode start, NavNode end)
        {
            Running = false;

            _pathStatus = PathStatus.success;
            var search = end;

            path.Clear();
            while (search != start)
            {
                if (_cameFrom.ContainsKey(search))
                {
                    path.Add(search);
                    search = _cameFrom[search];
                }
                else
                {
                    _pathStatus = PathStatus.failure;
                    return;
                }
            }

            path.Add(start);
            path.Reverse();
            if (_pathStatus == PathStatus.success)
            {
                OnPathfindingComplete?.Invoke(this);
            }
        }
コード例 #2
0
        private void SetPathList(NavNode start, NavNode end)
        {
            PathStatus = PathStatus.success;
            var search = end;

            path.Clear();
            path.Add(end);
            int pathLength = 0;

            while (search != start && pathLength < 100)
            {
                pathLength++;
                if (cameFrom.ContainsKey(search))
                {
                    search = cameFrom[search];
                    path.Add(search);
                }
                else
                {
                    PathStatus = PathStatus.failure;
                    return;
                }
            }

            // path.Add(start);
            path.Reverse();
            if (PathStatus == PathStatus.success)
            {
                OnPathfindingComplete?.Invoke(this);
            }
            Running = false;
        }