diff --git a/Assets/[Pathfinding]/Scripts/Pathfinder.cs b/Assets/[Pathfinding]/Scripts/Pathfinder.cs index b0e3703..18de25d 100644 --- a/Assets/[Pathfinding]/Scripts/Pathfinder.cs +++ b/Assets/[Pathfinding]/Scripts/Pathfinder.cs @@ -13,6 +13,7 @@ public static class Pathfinder private static List openList = new List(); private static Dictionary tileIndexToTileObjectOpen = new Dictionary(); private static HashSet closedList = new HashSet(); + private static Tile[] neighbors = new Tile[4]; public static void Initialize( GridController targetGridController ) { @@ -56,9 +57,9 @@ public static List GetPath( Vector2Int from, Vector2Int to ) if ( currentTile == destinationTile ) break; - Tile[] neighbours = GetPathTileNeighbors( currentTile ); + UpdateNeighbors( currentTile ); - foreach ( Tile neighbourPathTile in neighbours ) + foreach ( Tile neighbourPathTile in neighbors ) { if ( neighbourPathTile == null ) continue; @@ -104,9 +105,8 @@ private static float GetDistance( Tile targetFromTile, Tile targetToTile ) (targetFromTile.TilePosition.y - targetToTile.TilePosition.y); } - private static Tile[] GetPathTileNeighbors( Tile targetTile ) + private static Tile[] UpdateNeighbors( Tile targetTile ) { - Tile[] neighbors = new Tile[4]; neighbors[0] = GetNeighborAtDirection( targetTile, NeighborDirection.LEFT ); neighbors[1] = GetNeighborAtDirection( targetTile, NeighborDirection.TOP ); neighbors[2] = GetNeighborAtDirection( targetTile, NeighborDirection.RIGHT );