Skip to content

Commit d9520b8

Browse files
committed
FIX Static return list, as List<Tile> instead of List<Vector2Int>
1 parent dfb86e9 commit d9520b8

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Assets/[Pathfinding]/Scripts/Gameplay/GameplayController.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ private void OnUserClickOnTilePosition( int targetX, int targetY )
6767
return;
6868
}
6969

70-
List<Vector2Int> result = Pathfinder.GetPath( selectedTilePosition, clickPosition );
71-
foreach ( Vector2Int vector2Int in result )
70+
List<Tile> result = Pathfinder.GetPath( selectedTilePosition, clickPosition );
71+
int resultCount = result.Count;
72+
for ( int i = 0; i < resultCount; ++i )
7273
{
73-
gridController.SetTileType(vector2Int, TileType.ROAD);
74+
Tile tile = result[i];
75+
tile.SetType( TileType.ROAD );
7476
}
7577

7678
hasFirstNodeSelected = false;

Assets/[Pathfinding]/Scripts/Grid/GridController.cs

+1
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,6 @@ public void Clear()
137137
for ( int i = tiles.Length - 1; i >= 0; i-- )
138138
SetTileType( i, TileType.EMPTY );
139139
}
140+
140141
}
141142
}

Assets/[Pathfinding]/Scripts/Pathfinder.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public static class Pathfinder
1414
private static FastPriorityQueue<Tile> openListPriorityQueue;
1515
private static HashSet<Tile> closedList = new HashSet<Tile>();
1616
private static Tile[] neighbors = new Tile[4];
17+
private static List<Tile> finalPath = new List<Tile>();
1718

1819
public static void Initialize( GridController targetGridController )
1920
{
2021
gridController = targetGridController;
2122
openListPriorityQueue = new FastPriorityQueue<Tile>( gridController.GridSizeX * gridController.GridSizeY );
2223
}
2324

24-
public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
25+
public static List<Tile> GetPath( Vector2Int from, Vector2Int to )
2526
{
26-
2727
int fromIndex = gridController.TilePosToIndex( from.x, from.y );
2828
int toIndex = gridController.TilePosToIndex( to.x, to.y );
2929

@@ -72,10 +72,10 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
7272
}
7373
}
7474

75-
List<Vector2Int> finalPath = new List<Vector2Int>();
75+
finalPath.Clear();
7676
while ( currentTile != initialTile )
7777
{
78-
finalPath.Add( new Vector2Int( currentTile.PositionX, currentTile.PositionY ) );
78+
finalPath.Add( currentTile );
7979
currentTile = currentTile.Parent;
8080
}
8181

@@ -99,14 +99,12 @@ private static float GetDistance( Tile targetFromTile, Tile targetToTile )
9999
(fromPositionY - toPositionY);
100100
}
101101

102-
private static Tile[] UpdateNeighbors( Tile targetTile )
102+
private static void UpdateNeighbors( Tile targetTile )
103103
{
104104
neighbors[0] = GetNeighborAtDirection( targetTile, NeighborDirection.LEFT );
105105
neighbors[1] = GetNeighborAtDirection( targetTile, NeighborDirection.TOP );
106106
neighbors[2] = GetNeighborAtDirection( targetTile, NeighborDirection.RIGHT );
107107
neighbors[3] = GetNeighborAtDirection( targetTile, NeighborDirection.DOWN );
108-
109-
return neighbors;
110108
}
111109

112110
private static Tile GetNeighborAtDirection( Tile targetTile, NeighborDirection targetDirection )

0 commit comments

Comments
 (0)