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


C# IGrid.GetNearestWalkableCell方法代码示例

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


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

示例1: UpdateProgressiveVectorField

        private void UpdateProgressiveVectorField(bool forceBoundsConstruction)
        {
            _lastGroupCogCell = Vector3.zero;

            if (group == null || group.count == 0)
            {
                return;
            }

            if (_currentPath == null || _currentPath.count == 0)
            {
                return;
            }

            // find the grid where the group center is at
            Vector3 groupCog = group.centerOfGravity;
            _grid = GridManager.instance.GetGrid(groupCog);
            if (_grid == null)
            {
                return;
            }

            // try to find a walkable cell near the group center of gravity
            var groupCogCell = _grid.GetNearestWalkableCell(groupCog, groupCog, false, Mathf.CeilToInt((_boundsPadding + _extraPadding) / 2f), _unitProperties);
            if (groupCogCell == null)
            {
                return;
            }

            _lastGroupCogCell = groupCogCell.position;

            if (!ConstructGroupBounds(forceBoundsConstruction))
            {
                // stop executing if we haven't moved enough, i.e. only update the vector field when we move more than recalculate bounds threshold
                return;
            }

            // The order of methods here is very important. They must be called in exactly this order.
            FindTemporaryDestination();
            AllocateFields();
            StartFastMarchingMethod();
            if (GrowOrShrinkBounds())
            {
                // if we are growing the group bounds, there is no point in executing the rest of the code
                return;
            }

            SmoothFields();
            HandlePortals();
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:50,代码来源:ProgressiveVectorField.cs

示例2: PathRequestCallback

        /// <summary>
        /// The path request callback method.
        /// </summary>
        /// <param name="result">The path result.</param>
        /// <param name="unit">This unit's UnitFacade.</param>
        /// <param name="unitPos">This unit's position.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="grid">The grid.</param>
        private void PathRequestCallback(PathResult result, IUnitFacade unit, Vector3 unitPos, Vector3 destination, IGrid grid)
        {
            // if the normal path request fails...
            Action<PathResult> callback = (secondResult) =>
            {
                if (secondResult.status == PathingStatus.Complete)
                {
                    // add the unit's current position to the path
                    var path = result.path;
                    path.Push(unit);

                    FollowPath(path, unit);
                    return;
                }

                // if the second path request fails, there is nothing to do
                _stopped = true;
            };

            // try to request a path from the nearest (from) walkable cell
            Cell fromCell = grid.GetNearestWalkableCell(unitPos, unitPos, true, 1, unit);
            if (fromCell != null)
            {
                QueuePathRequest(fromCell.position, destination, unit, callback);
                return;
            }

            // if that fails, search through all 8 neighbour cells and attempt to request a path from the nearest isWalkable neighbour
            int neighboursCount = _neighbours.count;
            for (int i = 0; i < neighboursCount; i++)
            {
                var neighbourCell = _neighbours[i];
                if (neighbourCell.isWalkable(unit.attributes))
                {
                    QueuePathRequest(neighbourCell.position, destination, unit, callback);
                    return;
                }
            }
        }
开发者ID:andrewstarnes,项目名称:wwtd2,代码行数:47,代码来源:SteerForVectorFieldComponent.cs


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