If you want to apply the Dont Repeat Yourself principle on the modification made to ShowGridPositionRange, and avoid copying 20 lines of code to only modify 3, then this is what you can do. Use the same method you already have, and just add an optional bool at the end.
private void ShowGridPositionRange(GridPosition centerGridPosition, int range, GridVisualType gridVisualType, bool square = false)
{
List<GridPosition> gridPositionList = new();
for (int x = -range; x <= range; x++)
for (int z = -range; z <= range; z++)
{
GridPosition possibleGridPosition = centerGridPosition + new GridPosition(x, z);
if (!LevelGrid.Instance.GridPosIsValid(possibleGridPosition))
continue;
int distance = centerGridPosition.Distance(possibleGridPosition);
// Grid pos is too far away (only for not square)
if (distance > range && !square) // <-- HERE
continue;
gridPositionList.Add(possibleGridPosition);
}
ShowGridPositions(gridPositionList, gridVisualType);
}
The square bool is used on the marked if line. So, only if the distance doesnt qualify for a sphere, and it is a sphere test, then return. If square is true, that check is always false, so it works as if that check is not there.
Hope this helps