@@ -77,7 +77,7 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
77
77
List < Vector2Int > finalPath = new List < Vector2Int > ( ) ;
78
78
while ( tile != initialTile )
79
79
{
80
- finalPath . Add ( tile . TilePosition ) ;
80
+ finalPath . Add ( new Vector2Int ( tile . PositionX , tile . PositionY ) ) ;
81
81
tile = tile . Parent ;
82
82
}
83
83
@@ -91,10 +91,10 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
91
91
92
92
private static float GetDistance ( Tile targetFromTile , Tile targetToTile )
93
93
{
94
- return ( targetFromTile . TilePosition . x - targetToTile . TilePosition . x ) *
95
- ( targetFromTile . TilePosition . x - targetToTile . TilePosition . x ) +
96
- ( targetFromTile . TilePosition . y - targetToTile . TilePosition . y ) *
97
- ( targetFromTile . TilePosition . y - targetToTile . TilePosition . y ) ;
94
+ return ( targetFromTile . PositionX - targetToTile . PositionY ) *
95
+ ( targetFromTile . PositionX - targetToTile . PositionX ) +
96
+ ( targetFromTile . PositionY - targetToTile . PositionY ) *
97
+ ( targetFromTile . PositionY - targetToTile . PositionY ) ;
98
98
}
99
99
100
100
private static Tile [ ] UpdateNeighbors ( Tile targetTile )
@@ -109,35 +109,37 @@ private static Tile[] UpdateNeighbors( Tile targetTile )
109
109
110
110
private static Tile GetNeighborAtDirection ( Tile targetTile , NeighborDirection targetDirection )
111
111
{
112
- Vector2Int neighborPosition = GetNeighbourPosition ( targetTile , targetDirection ) ;
113
- if ( ! gridController . IsValidTilePosition ( neighborPosition ) )
112
+ int positionX ;
113
+ int positionY ;
114
+
115
+ GetNeighbourPosition ( targetTile , targetDirection , out positionX , out positionY ) ;
116
+ if ( ! gridController . IsValidTilePosition ( positionX , positionY ) )
114
117
return null ;
115
118
116
- int neighborIndex = gridController . TilePosToIndex ( neighborPosition . x , neighborPosition . y ) ;
119
+ int neighborIndex = gridController . TilePosToIndex ( positionX , positionY ) ;
117
120
118
121
return gridController . Tiles [ neighborIndex ] ;
119
122
}
120
123
121
- private static Vector2Int GetNeighbourPosition ( Tile targetTile , NeighborDirection targetDirection )
124
+ private static void GetNeighbourPosition ( Tile targetTile , NeighborDirection targetDirection , out int targetPositionX , out int targetPositionY )
122
125
{
123
- Vector2Int neighbourPosition = targetTile . TilePosition ;
126
+ targetPositionX = targetTile . PositionX ;
127
+ targetPositionY = targetTile . PositionY ;
124
128
switch ( targetDirection )
125
129
{
126
130
case NeighborDirection . LEFT :
127
- neighbourPosition . x -= 1 ;
131
+ targetPositionX -= 1 ;
128
132
break ;
129
133
case NeighborDirection . TOP :
130
- neighbourPosition . y += 1 ;
134
+ targetPositionY += 1 ;
131
135
break ;
132
136
case NeighborDirection . RIGHT :
133
- neighbourPosition . x += 1 ;
137
+ targetPositionX += 1 ;
134
138
break ;
135
139
case NeighborDirection . DOWN :
136
- neighbourPosition . y -= 1 ;
140
+ targetPositionY -= 1 ;
137
141
break ;
138
142
}
139
-
140
- return neighbourPosition ;
141
143
}
142
144
}
143
145
}
0 commit comments