@@ -14,16 +14,16 @@ public static class Pathfinder
14
14
private static FastPriorityQueue < Tile > openListPriorityQueue ;
15
15
private static HashSet < Tile > closedList = new HashSet < Tile > ( ) ;
16
16
private static Tile [ ] neighbors = new Tile [ 4 ] ;
17
+ private static List < Tile > finalPath = new List < Tile > ( ) ;
17
18
18
19
public static void Initialize ( GridController targetGridController )
19
20
{
20
21
gridController = targetGridController ;
21
22
openListPriorityQueue = new FastPriorityQueue < Tile > ( gridController . GridSizeX * gridController . GridSizeY ) ;
22
23
}
23
24
24
- public static List < Vector2Int > GetPath ( Vector2Int from , Vector2Int to )
25
+ public static List < Tile > GetPath ( Vector2Int from , Vector2Int to )
25
26
{
26
-
27
27
int fromIndex = gridController . TilePosToIndex ( from . x , from . y ) ;
28
28
int toIndex = gridController . TilePosToIndex ( to . x , to . y ) ;
29
29
@@ -72,10 +72,10 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
72
72
}
73
73
}
74
74
75
- List < Vector2Int > finalPath = new List < Vector2Int > ( ) ;
75
+ finalPath . Clear ( ) ;
76
76
while ( currentTile != initialTile )
77
77
{
78
- finalPath . Add ( new Vector2Int ( currentTile . PositionX , currentTile . PositionY ) ) ;
78
+ finalPath . Add ( currentTile ) ;
79
79
currentTile = currentTile . Parent ;
80
80
}
81
81
@@ -99,14 +99,12 @@ private static float GetDistance( Tile targetFromTile, Tile targetToTile )
99
99
( fromPositionY - toPositionY ) ;
100
100
}
101
101
102
- private static Tile [ ] UpdateNeighbors ( Tile targetTile )
102
+ private static void UpdateNeighbors ( Tile targetTile )
103
103
{
104
104
neighbors [ 0 ] = GetNeighborAtDirection ( targetTile , NeighborDirection . LEFT ) ;
105
105
neighbors [ 1 ] = GetNeighborAtDirection ( targetTile , NeighborDirection . TOP ) ;
106
106
neighbors [ 2 ] = GetNeighborAtDirection ( targetTile , NeighborDirection . RIGHT ) ;
107
107
neighbors [ 3 ] = GetNeighborAtDirection ( targetTile , NeighborDirection . DOWN ) ;
108
-
109
- return neighbors ;
110
108
}
111
109
112
110
private static Tile GetNeighborAtDirection ( Tile targetTile , NeighborDirection targetDirection )
0 commit comments