/// <summary> /// Processes the grid southwards and assigns all distances per tile in the southward direction. /// </summary> private void ProcessGridSouthwards(NavTileSurfaceData inData) { int currentDistance = 0; RectInt gridBounds = inData.GridBounds.AsRect(); Vector2Int coordinate = new Vector2Int(); for (coordinate.x = gridBounds.xMin; coordinate.x <= gridBounds.xMax; coordinate.x++) { for (coordinate.y = gridBounds.yMin; coordinate.y <= gridBounds.yMax; coordinate.y++) { TileData tile = inData.GetTileData(coordinate); if (tile == null) { continue; } AdditionalJPSPlusData addedData = tile.AdditionalData; if (coordinate.y == gridBounds.yMin || !inData.IsTileWalkable(coordinate + new Vector2Int(0, -1), 1)) { addedData.SetJumpDistance(JumpPointDirection.South, 0); } else if (inData.IsTileWalkable(coordinate + new Vector2Int(0, -1), 1) && (inData.GetTileData(coordinate + new Vector2Int(0, -1))?.AdditionalData.GetJumpDistance(JumpPointDirection.West) > 0 || inData.GetTileData(coordinate + new Vector2Int(0, -1))?.AdditionalData.GetJumpDistance(JumpPointDirection.East) > 0)) { addedData.SetJumpDistance(JumpPointDirection.South, 1); } else { currentDistance = inData.GetTileData(coordinate + new Vector2Int(0, -1)).AdditionalData.GetJumpDistance(JumpPointDirection.South); if (currentDistance > 0) { addedData.SetJumpDistance(JumpPointDirection.South, currentDistance + 1); } else { addedData.SetJumpDistance(JumpPointDirection.South, currentDistance - 1); } } } } }
/// <summary> /// Checks whether the given position has a traversable node in the given direction next to it. /// </summary> private bool HasAdjacentTraverseNode(Vector2Int inPosition, JumpPointDirection inDirection, NavTileSurfaceData inData) { Vector2Int adjacentCoordinate = GetNextPositionInDirection(inPosition, inDirection); return(inData.IsTileWalkable(adjacentCoordinate, 1)); }