本文整理汇总了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();
}
示例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;
}
}
}