Reconfiguration added orientation switching
This commit is contained in:
parent
ccec674836
commit
c8d049b5ac
@ -393,17 +393,69 @@ namespace Parking
|
|||||||
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize,
|
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize,
|
||||||
!spot.AlignToTop);
|
!spot.AlignToTop);
|
||||||
if (Math.Abs(spotBorder - nextBorder) < 5.5f)
|
if (Math.Abs(spotBorder - nextBorder) < 5.5f)
|
||||||
continue;
|
continue; // Try parallel
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
|
float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
|
||||||
!spot.AlignToTop);
|
!spot.AlignToTop);
|
||||||
float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
|
float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
|
||||||
!spot.AlignToTop);
|
!spot.AlignToTop);
|
||||||
if(nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize])
|
if (nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize]) {
|
||||||
|
// Try perpendicular
|
||||||
|
float bottomBorder = position.y - 2.25f / 2.0f;
|
||||||
|
float topBorder = position.y + 2.25f / 2.0f;
|
||||||
|
if (spot.AlignToTop) {
|
||||||
|
float newBottomBorder = topBorder - _spotHeights[size];
|
||||||
|
float newTopBorder = topBorder;
|
||||||
|
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular,
|
||||||
|
newSize,
|
||||||
|
!spot.AlignToTop);
|
||||||
|
if (Math.Abs(nextBorder - newBottomBorder) < 5.5f) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
float newBottomBorder = bottomBorder;
|
||||||
|
float newTopBorder = bottomBorder + _spotHeights[size];
|
||||||
|
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular,
|
||||||
|
newSize,
|
||||||
|
!spot.AlignToTop);
|
||||||
|
if (Math.Abs(newTopBorder - nextBorder) < 5.5f) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newPosition.y = bottomBorder + _spotHeights[(int) newSize] / 2.0f;
|
||||||
|
float newX = nextBorderRight;
|
||||||
|
if (spot.Lane == 0) {
|
||||||
|
// float xRelativeToRight = newX - Width / 2.0f;
|
||||||
|
// xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f;
|
||||||
|
// newX = xRelativeToRight + Width / 2.0f;
|
||||||
|
float xRelativeToRight = -(newX - Width / 2.0f);
|
||||||
|
// xRelativeToRight -= (xRelativeToRight - 2.25f / 2.0f) % 2.25f;
|
||||||
|
xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f;
|
||||||
|
xRelativeToRight += 2.25f;
|
||||||
|
xRelativeToRight = Math.Max(xRelativeToRight, 2.25f / 2.0f);
|
||||||
|
newX = (-xRelativeToRight + Width / 2.0f);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float xRelativeToLeft = newX + Width / 2.0f;
|
||||||
|
xRelativeToLeft -= (xRelativeToLeft + 2.25f / 2.0f) % 2.25f;
|
||||||
|
newX = xRelativeToLeft - Width / 2.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(spot.Lane == 0 && Width / 2.0f - newX < 5.5f + 0.5f + 2.25f)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
|
||||||
|
newPosition.x = newX;
|
||||||
|
spot.Flipped = currentLaneSpots.FindIndex(spotPredicate => spotPredicate == spot) % 2 == 0;
|
||||||
|
rotation *= Quaternion.Euler(0, 0, spot.Flipped ? 90 : -90);
|
||||||
|
spot.Perpendicular = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Destroy(spot.GameObject);
|
Destroy(spot.GameObject);
|
||||||
spot.Size = (Size) size;
|
spot.Size = (Size) size;
|
||||||
@ -459,8 +511,10 @@ namespace Parking
|
|||||||
sizeOffset = 2.25f / 2.0f;
|
sizeOffset = 2.25f / 2.0f;
|
||||||
else
|
else
|
||||||
sizeOffset = _spotHeights[(int) spot1.Size] / 2.0f;
|
sizeOffset = _spotHeights[(int) spot1.Size] / 2.0f;
|
||||||
allBorders.Add(spotPosition.x + sizeOffset);
|
if(right)
|
||||||
allBorders.Add(spotPosition.x - sizeOffset);
|
allBorders.Add(spotPosition.x - sizeOffset);
|
||||||
|
else
|
||||||
|
allBorders.Add(spotPosition.x + sizeOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
allBorders.Sort();
|
allBorders.Sort();
|
||||||
@ -470,7 +524,7 @@ namespace Parking
|
|||||||
|
|
||||||
if (perpendicular)
|
if (perpendicular)
|
||||||
return position.x + (right ? 1 : -1) * _spotHeights[(int) size] / 2.0f;
|
return position.x + (right ? 1 : -1) * _spotHeights[(int) size] / 2.0f;
|
||||||
return position.x + (right ? 1 : -1) * 2.25f / 2.0f;
|
return (right ? 1 : -1) * Width / 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -547,16 +601,18 @@ namespace Parking
|
|||||||
}
|
}
|
||||||
|
|
||||||
float currentX;
|
float currentX;
|
||||||
if (i != 0) currentX = -Width / 2f - 2.25f / 2f + 2.25f;
|
if (i != 0) currentX = -Width / 2f;
|
||||||
else currentX = Width / 2f; // + 5.5f - 2.25f / 2f + 2.25f + 1.75f;
|
else currentX = Width / 2f; // + 5.5f - 2.25f / 2f + 2.25f + 1.75f;
|
||||||
|
|
||||||
bool flipped = false;
|
bool flipped = false;
|
||||||
|
|
||||||
for (int j = 0; j < spotMap[i].Count; j++) {
|
for (int j = 0; j < spotMap[i].Count; j++) {
|
||||||
if (!spotMap[i][j].Perpendicular && i == 0 && j == 0)
|
// if (!spotMap[i][j].Perpendicular)
|
||||||
currentX -= spotSizes[(int) spotMap[i][j].Size] / 2.0f;
|
// currentX -= spotSizes[(int) spotMap[i][j].Size] / 2.0f;
|
||||||
else if (spotMap[i][j].Perpendicular && i == 0 && j == 0)
|
// else if (spotMap[i][j].Perpendicular)
|
||||||
currentX -= 2.25f / 2.0f;
|
// currentX -= 2.25f / 2.0f;
|
||||||
|
currentX += (i != 0 ? 1 : -1) *
|
||||||
|
(spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f);
|
||||||
|
|
||||||
spotMap[i][j].Flipped = flipped;
|
spotMap[i][j].Flipped = flipped;
|
||||||
bool alignTop = i % 2 != 0;
|
bool alignTop = i % 2 != 0;
|
||||||
@ -594,7 +650,7 @@ namespace Parking
|
|||||||
spotMap[i][j].Lane = i;
|
spotMap[i][j].Lane = i;
|
||||||
|
|
||||||
currentX += (i != 0 ? 1 : -1) *
|
currentX += (i != 0 ? 1 : -1) *
|
||||||
(spotMap[i][j].Perpendicular ? 2.25f : spotSizes[(int) spotMap[i][j].Size]);
|
(spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f);
|
||||||
|
|
||||||
flipped = !flipped;
|
flipped = !flipped;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user