当前位置: 首页>>代码示例>>C#>>正文


C# Path.Push方法代码示例

本文整理汇总了C#中Path.Push方法的典型用法代码示例。如果您正苦于以下问题:C# Path.Push方法的具体用法?C# Path.Push怎么用?C# Path.Push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Path的用法示例。


在下文中一共展示了Path.Push方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ManualPath

        /// <summary>
        /// Initializes a new instance of the <see cref="ManualPath"/> class.
        /// </summary>
        /// <param name="replanCallback">The replan callback.</param>
        /// <param name="path">The path.</param>
        public ManualPath(Replan replanCallback, IIndexable<Vector3> path)
        {
            Ensure.ArgumentNotNull(path, "path");

            this.onReplan = replanCallback;

            var stack = new Path(path.count);
            for (int i = path.count - 1; i >= 0; i--)
            {
                stack.Push(path[i].AsPositioned());
            }

            this.path = stack;
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:19,代码来源:ManualPath.cs

示例2: CreateWithPath

        /// <summary>
        /// Factory method to create a result with a path
        /// </summary>
        /// <param name="pathPoints">The path points.</param>
        /// <param name="endWaypoint">The end way point.</param>
        /// <param name="originalRequest">The original request.</param>
        /// <returns>The result</returns>
        public static DirectPathResult CreateWithPath(Vector3[] pathPoints, Vector3 endWaypoint, IPathRequest originalRequest)
        {
            var res = new DirectPathResult();

            var path = new Path(pathPoints.Length);

            for (int i = pathPoints.Length - 1; i >= 0; i--)
            {
                path.Push(new Position(pathPoints[i]));
            }

            res.path = path;
            res.pendingWaypoints = new[] { endWaypoint };
            res.originalRequest = originalRequest;
            res.status = PathingStatus.Complete;

            return res;
        }
开发者ID:forwolk,项目名称:UnityApex,代码行数:25,代码来源:DirectPathResult.cs

示例3: getPath

        public static Path getPath(Cell start, List<Cell> targets)
        {
            Stopwatch sw = Stopwatch.StartNew();
            Path empty = new Path();

            List<Cell> openList = new List<Cell>();
            List<Cell> closedList = new List<Cell>();

            Boolean foundTarget = false;
            Cell currentNode = start;

            Dictionary<Cell, Cell> parentCells = new Dictionary<Cell, Cell>();
            parentCells.Add(start, null);
            openList.Add(start);

            while (!foundTarget)
            {
                if (sw.ElapsedMilliseconds > 80)
                {
                    Console.WriteLine("Taking too long for: " + start.Index);
                    Console.WriteLine("Openlist: " + openList.Count);
                    Console.WriteLine("Closedlist: " + closedList.Count);
                    return empty;
                }

                // If the openlist has no cells return an empty path
                if (openList.Count == 0)
                    return empty;

                // sort the open list
                openList.RemoveAll(delegate(Cell c) { return c == null; });
                openList.Sort(delegate(Cell c1, Cell c2) { return c1.F.CompareTo(c2.F); });

                // grab the first cell w/ lowest f score
                currentNode = openList[0];

                if (targets.Contains(currentNode))
                {
                    // We found the target node
                    Path path = new Path();

                    foundTarget = true;
                    Cell pathNode = currentNode;
                    while(parentCells[pathNode] != null)
                    {
                        path.Push(pathNode);
                        pathNode = parentCells[pathNode];
                    }
                    return path;
                }

                openList.Remove(currentNode);
                closedList.Add(currentNode);

                lock (currentNode.Neighbors)
                {
                    foreach (KeyValuePair<Cell, Boolean> neighbor in currentNode.Neighbors)
                    {
                        if (neighbor.Value && neighbor.Key.Passable)
                        {
                            if (!closedList.Contains(neighbor.Key) && !openList.Contains(neighbor.Key))
                            {
                                parentCells.Add(neighbor.Key, currentNode);
                                neighbor.Key.G = parentCells[neighbor.Key].G + getDistance(currentNode, neighbor.Key);
                                neighbor.Key.H = getClosestTarget(targets, neighbor.Key.Center);
                                neighbor.Key.F = neighbor.Key.G + neighbor.Key.H;
                                openList.Add(neighbor.Key);
                            }
                        }
                    }
                }
            }

            return empty;
        }
开发者ID:behindcurtain3,项目名称:schismTDserver,代码行数:75,代码来源:AStar.cs

示例4: CompletePathSegment

        private bool CompletePathSegment(PathingStatus status)
        {
            if (status != PathingStatus.Complete)
            {
                return false;
            }

            _currentResult.pathCost += _goal.g;

            //Fix the actual destination so it does not overlap obstructions
            FixupGoal(_segmentRequest);

            if (_segmentRequest.type == RequestType.IntelOnly)
            {
                return true;
            }

            var maxPathLength = Mathf.CeilToInt(_goal.g / (_goal.parent.cellSize * _costProvider.baseMoveCost));

            Path pathSegment;
            if (_segmentRequest.pathFinderOptions.usePathSmoothing)
            {
                pathSegment = _smoother.Smooth(_goal, maxPathLength, _segmentRequest, _cellCostStrategy);
            }
            else
            {
                pathSegment = new Path(maxPathLength);

                //Push the actual end position as the goal
                pathSegment.Push(new Position(_segmentRequest.to));

                IPathNode current = _goal.predecessor;
                while (current != null)
                {
                    pathSegment.Push(current);
                    current = current.predecessor;
                }

                //Instead of testing for it in the while loop, just pop off the start node and replace it with the actual start position
                if (pathSegment.count > 1)
                {
                    pathSegment.Pop();
                }

                pathSegment.Push(new Position(_segmentRequest.from));
            }

            _segments.Add(pathSegment);

            return true;
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:51,代码来源:PathingEngineBase.cs

示例5: StartPathSegment

        private PathingStatus StartPathSegment()
        {
            var fromGrid = GridManager.instance.GetGrid(_segmentRequest.from);
            var toGrid = GridManager.instance.GetGrid(_segmentRequest.to);
            if (toGrid == null)
            {
                //Just treat the to grid as the from grid in this case so the destination can be closest point on from grid
                if (toGrid == null)
                {
                    toGrid = fromGrid;
                }
            }

            //If no grids were resolved for this request it means the request involves two points outside the grid(s) that do not cross any grid(s), so we can move directly between them
            if (fromGrid == null && toGrid == null)
            {
                var pathSegment = new Path(2);
                pathSegment.Push(new Position(_segmentRequest.to));
                pathSegment.Push(new Position(_segmentRequest.from));
                _segments.Add(pathSegment);
                return PathingStatus.Complete;
            }
            else if (fromGrid == null)
            {
                return PathingStatus.StartOutsideGrid;
            }

            //Get a reference to the start and end cells
            var start = fromGrid.GetCell(_segmentRequest.from, false) as IPathNode;
            _goal = toGrid.GetCell(_segmentRequest.to, false) as IPathNode;

            //Ensure that the end cell is valid
            if (_goal == null)
            {
                if (_segmentRequest.pathFinderOptions.navigateToNearestIfBlocked)
                {
                    _goal = toGrid.GetCell(_segmentRequest.to, true) as IPathNode;
                    _segmentRequest.to = _goal.position;
                }
                else
                {
                    return PathingStatus.EndOutsideGrid;
                }
            }

            if (!_goal.isWalkable(_segmentRequest.requesterProperties.attributes) && !_segmentRequest.pathFinderOptions.navigateToNearestIfBlocked)
            {
                return PathingStatus.DestinationBlocked;
            }

            //Ensure that the start cell is valid
            IPathNode actualStart = null;
            if (!start.isWalkable(_segmentRequest.requesterProperties.attributes))
            {
                actualStart = start;
                start = fromGrid.GetNearestWalkableCell(start.position, _goal.position, true, _segmentRequest.pathFinderOptions.maxEscapeCellDistanceIfOriginBlocked, _segmentRequest.requesterProperties);
                if (start == null)
                {
                    return PathingStatus.NoRouteExists;
                }
            }

            OnStart(start, actualStart);

            return PathingStatus.Running;
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:66,代码来源:PathingEngineBase.cs

示例6: HandlePortal

        /// <summary>
        /// Handles portalling.
        /// </summary>
        /// <param name="unitData">This unit's UnitFacade.</param>
        /// <param name="group">This unit's current/old group.</param>
        /// <param name="vectorField">The vector field.</param>
        /// <param name="pathPortalIndex">Index of the portal in the current path.</param>
        /// <param name="grid">The grid.</param>
        private void HandlePortal(IUnitFacade unitData, DefaultSteeringTransientUnitGroup group, IVectorField vectorField, int pathPortalIndex, IGrid grid)
        {
            var portal = _currentPath[pathPortalIndex] as IPortalNode;
            if (portal == null)
            {
                // if the path node that was reported as a portal turns out not to be - return
                return;
            }

            if (object.ReferenceEquals(unitData, group.modelUnit))
            {
                // don't ever let model unit jump portal
                return;
            }

            int groupCount = group.count;
            var to = _currentPath[pathPortalIndex + 1];

            // we consider a portal a "far portal" when the distance between it and its partner is more than the diagonal cell size
            // 'far portal' means that it is NOT considered a grid stitching connector portal
            // Requires that grid stitching portals are always placed adjacent to each other
            float portalNewGroupThreshold = (grid.cellSize * Consts.SquareRootTwo) + 0.1f;
            bool isFarPortal = (portal.position - portal.partner.position).sqrMagnitude > (portalNewGroupThreshold * portalNewGroupThreshold);

            if (isFarPortal)
            {
                // if it is a far portal, we need to make or use the next group
                if (group.nextGroup == null)
                {
                    // new group does not exist yet, so create it and tell the old group about it
                    var groupStrat = GroupingManager.GetGroupingStrategy<IUnitFacade>();
                    if (groupStrat == null)
                    {
                        Debug.Log("No Grouping Strategy has been registered for IUnitFacade");
                        return;
                    }

                    var newGroup = groupStrat.CreateGroup(groupCount) as DefaultSteeringTransientUnitGroup;
                    if (newGroup == null)
                    {
                        return;
                    }

                    group.nextGroup = newGroup;
                    _nextGroup = newGroup;
                }
                else
                {
                    // new group exists, so just use it
                    _nextGroup = group.nextGroup;
                }

                // make sure to remove the unit from the old group
                group.Remove(unitData);
            }

            _isPortalling = true;
            // actually execute the portal
            portal.Execute(
                unitData.transform,
                to,
                () =>
                {
                    _isPortalling = false;

                    if (isFarPortal)
                    {
                        // if it is a far portal, we are supposed to join up with the new group
                        _nextGroup.Add(unitData);
                        unitData.transientGroup = _nextGroup;

                        if (_nextGroup.count == 1)
                        {
                            // let the first unit in the new group be responsible for setting the new group up
                            if (vectorField.destination != null)
                            {
                                // the new group's path starts on the other side of the portal...
                                int pathCount = _currentPath.count;
                                var newPath = new Path(pathCount - (pathPortalIndex + 2));
                                for (int i = pathCount - 1; i >= pathPortalIndex + 2; i--)
                                {
                                    newPath.Push(_currentPath[i]);
                                }

                                // the first member that joins the new group tells the new group to move along the path of the old group
                                Vector3 destination = vectorField.destination.position;
                                if ((to.position - destination).sqrMagnitude > 1f)
                                {
                                    // check though that the destination is not the same as the starting position
                                    _nextGroup.MoveAlong(newPath);
                                }

//.........这里部分代码省略.........
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:101,代码来源:SteerForVectorFieldComponent.cs

示例7: Smooth


//.........这里部分代码省略.........
            //Next prune superfluous path nodes
            var reversePath = new List<IPositioned>(maxPathLength);

            var current = goal;
            var next = current.predecessor;

            int bends = -1;
            var prevDir = Vector3.zero;

            while (next != null)
            {
                var dir = next.position - current.position;

                if ((dir != prevDir) || (next is IPortalNode))
                {
                    reversePath.Add(current);
                    prevDir = dir;
                    bends++;
                }

                current = next;
                next = current.predecessor;
            }

            //Correct the end nodes and inject a mid point if too much was pruned (can happen on straight paths with no direction change, which can lead to obstacle collision if the unit is offset)
            if (reversePath.Count == 0)
            {
                reversePath.Add(new Position(request.to));
            }
            else
            {
                reversePath[0] = new Position(request.to);
            }

            if (reversePath.Count == 1 && bends <= 0)
            {
                reversePath.Add(goal.predecessor);
            }

            reversePath.Add(new Position(request.from));
            int pathLength = reversePath.Count;

            //Next see if we can reduce the path further by excluding unnecessary bends
            if (!request.pathFinderOptions.preventDiagonalMoves)
            {
                var matrix = goal.parent;

                int indexLimit = reversePath.Count - 2;
                for (int i = 0; i < indexLimit; i++)
                {
                    var c1 = reversePath[i];
                    var c2 = reversePath[i + 1];
                    var c3 = reversePath[i + 2];

                    var skip = AdjustIfPortal(c1, c2, c3);

                    if (skip > -1)
                    {
                        //One of the candidate nodes is a portal so skip to the node following the portal and resolve the grid at the other end of the portal.
                        //Since a portal node will never be the last node we can safely do this here. Since we are moving in the reverse direction here the portal will be on the other side.
                        i += skip;
                        matrix = ((IPortalNode)reversePath[i]).parent;
                        continue;
                    }

                    while (CanReducePath(c1, c3, unitProps, matrix, costStrategy))
                    {
                        reversePath[i + 1] = null;
                        pathLength--;
                        i++;

                        if (i >= indexLimit)
                        {
                            break;
                        }

                        c3 = reversePath[i + 2];
                        if (c3 is IPortalNode)
                        {
                            break;
                        }
                    }
                }
            }

            //Construct the final path
            var path = new Path(pathLength);

            var count = reversePath.Count;
            for (int i = 0; i < count; i++)
            {
                var node = reversePath[i];
                if (node != null)
                {
                    path.Push(node);
                }
            }

            return path;
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:101,代码来源:PathSmoother.cs


注:本文中的Path.Push方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。