Skip to content

Commit ec80d08

Browse files
committedMar 11, 2018
FIX replace Vector2Int by simple int for positiong x and y
1 parent 3c865bf commit ec80d08

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed
 

‎Assets/[Pathfinding]/Scripts/Fill/FillController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public void Fill(GridController targetGrid)
3636
for (int i = 0; i < targetGrid.Tiles.Length; i++)
3737
{
3838
Tile tile = targetGrid.Tiles[i];
39-
float noise = Mathf.PerlinNoise(((float)(tile.TilePosition.x+randomOffset) / targetGrid.GridSizeX) * mapScale,
40-
((float)(tile.TilePosition.y+randomOffset) / targetGrid.GridSizeY) * mapScale);
39+
float noise = Mathf.PerlinNoise(((float)(tile.PositionX+randomOffset) / targetGrid.GridSizeX) * mapScale,
40+
((float)(tile.PositionY+randomOffset) / targetGrid.GridSizeY) * mapScale);
4141

4242
if ( noise > mimumValueAsBlock )
4343
{

‎Assets/[Pathfinding]/Scripts/Grid/GridController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void GenerateTiles()
106106
int positionX;
107107
int positionY;
108108
IndexToTilePos( i, out positionX, out positionY );
109-
tiles[i] = new Tile( i, new Vector2Int(positionX, positionY) );
109+
tiles[i] = new Tile( i, positionX, positionY );
110110
}
111111
}
112112

‎Assets/[Pathfinding]/Scripts/Pathfinder.cs

+18-16
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
7777
List<Vector2Int> finalPath = new List<Vector2Int>();
7878
while ( tile != initialTile )
7979
{
80-
finalPath.Add( tile.TilePosition );
80+
finalPath.Add( new Vector2Int( tile.PositionX, tile.PositionY ) );
8181
tile = tile.Parent;
8282
}
8383

@@ -91,10 +91,10 @@ public static List<Vector2Int> GetPath( Vector2Int from, Vector2Int to )
9191

9292
private static float GetDistance( Tile targetFromTile, Tile targetToTile )
9393
{
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);
9898
}
9999

100100
private static Tile[] UpdateNeighbors( Tile targetTile )
@@ -109,35 +109,37 @@ private static Tile[] UpdateNeighbors( Tile targetTile )
109109

110110
private static Tile GetNeighborAtDirection( Tile targetTile, NeighborDirection targetDirection )
111111
{
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 ) )
114117
return null;
115118

116-
int neighborIndex = gridController.TilePosToIndex( neighborPosition.x, neighborPosition.y );
119+
int neighborIndex = gridController.TilePosToIndex( positionX, positionY );
117120

118121
return gridController.Tiles[neighborIndex];
119122
}
120123

121-
private static Vector2Int GetNeighbourPosition( Tile targetTile, NeighborDirection targetDirection )
124+
private static void GetNeighbourPosition( Tile targetTile, NeighborDirection targetDirection ,out int targetPositionX, out int targetPositionY)
122125
{
123-
Vector2Int neighbourPosition = targetTile.TilePosition;
126+
targetPositionX = targetTile.PositionX;
127+
targetPositionY = targetTile.PositionY;
124128
switch ( targetDirection )
125129
{
126130
case NeighborDirection.LEFT:
127-
neighbourPosition.x -= 1;
131+
targetPositionX -= 1;
128132
break;
129133
case NeighborDirection.TOP:
130-
neighbourPosition.y += 1;
134+
targetPositionY += 1;
131135
break;
132136
case NeighborDirection.RIGHT:
133-
neighbourPosition.x += 1;
137+
targetPositionX += 1;
134138
break;
135139
case NeighborDirection.DOWN:
136-
neighbourPosition.y -= 1;
140+
targetPositionY -= 1;
137141
break;
138142
}
139-
140-
return neighbourPosition;
141143
}
142144
}
143145
}

‎Assets/[Pathfinding]/Scripts/Tile.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,20 @@ public Tile Parent
1212
get { return parent; }
1313
}
1414

15-
private Vector2Int tilePosition;
16-
public Vector2Int TilePosition
15+
private int positionX;
16+
public int PositionX
1717
{
1818
get
1919
{
20-
return tilePosition;
20+
return positionX;
21+
}
22+
}
23+
private int positionY;
24+
public int PositionY
25+
{
26+
get
27+
{
28+
return positionY;
2129
}
2230
}
2331

@@ -62,20 +70,21 @@ public int Index
6270
}
6371
}
6472

65-
public Tile( int targetTileIndex, Vector2Int targetPosition )
73+
public Tile( int targetTileIndex, int targetPositionX, int targetPOsitionY )
6674
{
6775
index = targetTileIndex;
68-
SetTilePostion( targetPosition );
76+
SetTilePostion( targetPositionX, targetPOsitionY );
6977
}
7078

7179
public void SetParent( Tile targetTile )
7280
{
7381
parent = targetTile;
7482
}
7583

76-
private void SetTilePostion( Vector2Int targetTilePosition )
84+
private void SetTilePostion( int targetPositionX, int targetPOsitionY )
7785
{
78-
tilePosition = targetTilePosition;
86+
positionX = targetPositionX;
87+
positionY = targetPOsitionY;
7988
}
8089

8190
public void SetGCost( float targetGCost )

‎Assets/[Pathfinding]/Scripts/Visualization/VisualizationController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void OnTileTypeChanged( Tile targetTile )
5959
{
6060
GameObject tileVisual = SimplePool.Spawn( typesPrefabs[(int) targetTile.TileType], transform );
6161
tileVisual.transform.localPosition =
62-
new Vector3( targetTile.TilePosition.x, 0, targetTile.TilePosition.y );
62+
new Vector3( targetTile.PositionX, 0, targetTile.PositionY );
6363
tilesGameObjects[targetTile.Index] = tileVisual;
6464

6565
if ( targetTile.TileType == TileType.ROAD )
@@ -108,7 +108,7 @@ private void CreateTerrain()
108108
continue;
109109

110110
GameObject blockTile = SimplePool.Spawn( typesPrefabs[(int) TileType.BLOCK], transform );
111-
blockTile.transform.localPosition = new Vector3( gridTile.TilePosition.x, 0, gridTile.TilePosition.y );
111+
blockTile.transform.localPosition = new Vector3( gridTile.PositionX, 0, gridTile.PositionY );
112112

113113
tilesGameObjects[i] = blockTile;
114114
}

0 commit comments

Comments
 (0)
Please sign in to comment.