Offset.
You can set an offset on the GridSystem
and then include that in your calculations. Here is a version that only includes the bits with the offset change. All the other stuff remains as it is. Note that it also does not include the multi-layer bits. This is the GridSystem
from the first part of the course
public class GridSystem<TGridObject>
{
private Vector2 offset;
public GridSystem(int width, int height, float cellSize, Vector2 offset, Func<GridSystem<TGridObject>, GridPosition, TGridObject> createGridObject)
{
this.offset = offset;
}
public Vector3 GetWorldPosition(GridPosition gridPosition)
{
return new Vector3(offset.x + gridPosition.x, 0, offset.y + gridPosition.z) * cellSize;
}
public GridPosition GetGridPosition(Vector3 worldPosition)
{
return new GridPosition(
Mathf.RoundToInt((worldPosition.x - offset.x) / cellSize),
Mathf.RoundToInt((worldPosition.z - offset.y) / cellSize)
);
}
}