Skip to content

Commit 98646c0

Browse files
committed
FIX using static neighbors array, just updating the values
1 parent f2c6cb6 commit 98646c0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Assets/[Pathfinding]/Scripts/Pathfinder.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public static class Pathfinder
1313
private static List<Tile> openList = new List<Tile>();
1414
private static Dictionary<int, Tile> tileIndexToTileObjectOpen = new Dictionary<int, Tile>();
1515
private static HashSet<Tile> closedList = new HashSet<Tile>();
16+
private static Tile[] neighbors = new Tile[4];
1617

1718
public static void Initialize( GridController targetGridController )
1819
{
@@ -56,9 +57,9 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
5657
if ( currentTile == destinationTile )
5758
break;
5859

59-
Tile[] neighbours = GetPathTileNeighbors( currentTile );
60+
UpdateNeighbors( currentTile );
6061

61-
foreach ( Tile neighbourPathTile in neighbours )
62+
foreach ( Tile neighbourPathTile in neighbors )
6263
{
6364
if ( neighbourPathTile == null )
6465
continue;
@@ -104,9 +105,8 @@ private static float GetDistance( Tile targetFromTile, Tile targetToTile )
104105
(targetFromTile.TilePosition.y - targetToTile.TilePosition.y);
105106
}
106107

107-
private static Tile[] GetPathTileNeighbors( Tile targetTile )
108+
private static Tile[] UpdateNeighbors( Tile targetTile )
108109
{
109-
Tile[] neighbors = new Tile[4];
110110
neighbors[0] = GetNeighborAtDirection( targetTile, NeighborDirection.LEFT );
111111
neighbors[1] = GetNeighborAtDirection( targetTile, NeighborDirection.TOP );
112112
neighbors[2] = GetNeighborAtDirection( targetTile, NeighborDirection.RIGHT );

0 commit comments

Comments
 (0)