@@ -13,6 +13,7 @@ public static class Pathfinder
13
13
private static List < Tile > openList = new List < Tile > ( ) ;
14
14
private static Dictionary < int , Tile > tileIndexToTileObjectOpen = new Dictionary < int , Tile > ( ) ;
15
15
private static HashSet < Tile > closedList = new HashSet < Tile > ( ) ;
16
+ private static Tile [ ] neighbors = new Tile [ 4 ] ;
16
17
17
18
public static void Initialize ( GridController targetGridController )
18
19
{
@@ -56,9 +57,9 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
56
57
if ( currentTile == destinationTile )
57
58
break ;
58
59
59
- Tile [ ] neighbours = GetPathTileNeighbors ( currentTile ) ;
60
+ UpdateNeighbors ( currentTile ) ;
60
61
61
- foreach ( Tile neighbourPathTile in neighbours )
62
+ foreach ( Tile neighbourPathTile in neighbors )
62
63
{
63
64
if ( neighbourPathTile == null )
64
65
continue ;
@@ -104,9 +105,8 @@ private static float GetDistance( Tile targetFromTile, Tile targetToTile )
104
105
( targetFromTile . TilePosition . y - targetToTile . TilePosition . y ) ;
105
106
}
106
107
107
- private static Tile [ ] GetPathTileNeighbors ( Tile targetTile )
108
+ private static Tile [ ] UpdateNeighbors ( Tile targetTile )
108
109
{
109
- Tile [ ] neighbors = new Tile [ 4 ] ;
110
110
neighbors [ 0 ] = GetNeighborAtDirection ( targetTile , NeighborDirection . LEFT ) ;
111
111
neighbors [ 1 ] = GetNeighborAtDirection ( targetTile , NeighborDirection . TOP ) ;
112
112
neighbors [ 2 ] = GetNeighborAtDirection ( targetTile , NeighborDirection . RIGHT ) ;
0 commit comments