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


C# Path.Peek方法代码示例

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


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

示例1: SetPath

        private void SetPath(Path path, bool isWaypoint)
        {
            _endOfResolvedPath = path.Last().position;
            _currentGrid = GridManager.instance.GetGrid(path.Peek().position);

            if (isWaypoint)
            {
                _remainingPathDistance += path.CalculateLength();

                _currentPath = _currentPath.AppendSegment(path);
            }
            else
            {
                if (!TrimPath(path))
                {
                    RequestPath(_transform.position, _wayPoints.desiredEndOfPath, InternalPathRequest.Type.Normal);
                    _currentPath = null;
                    return;
                }

                _currentPath = path;
                _remainingPathDistance = path.CalculateLength();

                //Pop the first node as our next destination.
                _currentDestination = path.Pop();
                _curPlannedDirection = _transform.position.DirToXZ(_currentDestination.position);
            }

            _unit.hasArrivedAtDestination = false;
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:30,代码来源:SteerForPathComponent.cs

示例2: TrimPath

        private bool TrimPath(Path path)
        {
            //Make sure that the path was resolved before moving too far from where it was requested.
            var nn = _pathSettings.nextNodeDistance;
            if (_unit.position.DirToXZ(path.Peek().position).sqrMagnitude < nn * nn)
            {
                return true;
            }

            //First thing to do is to remove any waypoints that have already been reached.
            //Since the actual waypoints may differ from the requested ones (if they were corrected to allow the unit to access them)
            //we cannot remove them by comparison.
            //Since the last point is now always a waypoint (but not a via point), we skip that as obviously the last point cannot be pruned.
            int currentWaypointCount = _wayPoints.viaPointsCount;
            int pathCount = path.count;
            int encounteredWaypoints = 0;
            for (int i = pathCount - 2; i >= 0; i--)
            {
                var node = path[i];
                if (node is Waypoint)
                {
                    if (encounteredWaypoints == currentWaypointCount)
                    {
                        path.Truncate(i + 1);
                        break;
                    }

                    encounteredWaypoints++;
                }
            }

            //Next find the last node on the path to which we can move directly, i.e. skipping nodes already reached.
            var gridBounds = _currentGrid.bounds;
            var matrix = _currentGrid.cellMatrix;
            var costStrategy = GameServices.cellCostStrategy;

            int firstNodeIdx = -1;
            pathCount = path.count;
            for (int i = 0; i < pathCount; i++)
            {
                //If we haven't yet found an accessible node move on if the inspected node is outside the current grid or is a portal.
                //Otherwise stop, we do not move past portals.
                var node = path[i];
                if (node is IPortalNode || !gridBounds.Contains(node.position))
                {
                    if (firstNodeIdx < 0)
                    {
                        continue;
                    }

                    break;
                }

                if (PathSmoother.CanReducePath(node, _unit, _unit, matrix, costStrategy))
                {
                    firstNodeIdx = i;
                }
                else if (firstNodeIdx >= 0)
                {
                    break;
                }

                //We must visit waypoint so they cannot be smoothed away
                if (node is Waypoint)
                {
                    break;
                }
            }

            if (firstNodeIdx < 0)
            {
                return false;
            }

            path.Truncate(firstNodeIdx);
            return true;
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:77,代码来源:SteerForPathComponent.cs


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