diff --git a/Assets/Scripts/ParkingManager.cs b/Assets/Scripts/ParkingManager.cs index aa8c0d3..22295f6 100644 --- a/Assets/Scripts/ParkingManager.cs +++ b/Assets/Scripts/ParkingManager.cs @@ -78,7 +78,7 @@ namespace Parking } dateText.text = path.Substring(path.Length - 1 - 4 - 9, 10); - + InitiateManager(); startPanel.SetActive(false); } @@ -237,8 +237,7 @@ namespace Parking { foreach (List list in _spotMap) foreach (Spot spot1 in list) - if (spot1.Reserved && spot1.ReservedPriority == driver.Priority && driver.Size == spot1.Size) - { + if (spot1.Reserved && spot1.ReservedPriority == driver.Priority && driver.Size == spot1.Size) { spot = spot1; return true; } @@ -362,14 +361,16 @@ namespace Parking if (spot.Size > newSize) { if (!spot.Perpendicular) { - float newX = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, true) - - _spotHeights[(int) spot.Size] / 2.0f - 0.5f; + float newX = + GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, true) - + _spotHeights[(int) spot.Size] / 2.0f - 0.5f; newPosition = new Vector3(newX, newPosition.y, newPosition.z); } else { - float newX = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, true) - - 2.25f / 2.0f; + float newX = + GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, true) - + 2.25f / 2.0f; if (spot.Lane == 0) { float xRelativeToRight = newX - Width / 2.0f - 2.25f / 2.0f; xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f; @@ -397,13 +398,14 @@ namespace Parking else spotBorder = newPosition.y - thisSizeOffset; if (spot.Perpendicular) { - float nextBorder = GetNextBorderVectical(newPosition, spot.Lane, spot.Perpendicular, newSize, + float nextBorder = GetNextBorderVectical(newPosition, spot.Lane, spot.Perpendicular, + newSize, !spot.AlignToTop); if (Math.Abs(spotBorder - nextBorder) < 5.5f) continue; } else { - float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, + float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, spot.Size, false); float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, @@ -430,7 +432,8 @@ namespace Parking newPosition.x = nextBorderRight - _spotHeights[(int) newSize] - 0.5f; newPosition.y = position.y; foundByRemoval = true; - }else + } + else continue; } } @@ -451,11 +454,12 @@ namespace Parking newPosition.x = nextBorderRight - _spotHeights[(int) newSize] - 0.5f; newPosition.y = position.y; foundByRemoval = true; - }else + } + else continue; } } - + } if (!foundByRemoval) { @@ -480,13 +484,12 @@ namespace Parking // Try to remove one spot next continue; } - else { - newPosition.x = newX; - spot.Flipped = currentLaneSpots.FindIndex(spotPredicate => spotPredicate == spot) % - 2 == 0; - rotation *= Quaternion.Euler(0, 0, spot.Flipped ? 90 : -90); - spot.Perpendicular = true; - } + + newPosition.x = newX; + spot.Flipped = currentLaneSpots.FindIndex(spotPredicate => spotPredicate == spot) % + 2 == 0; + rotation *= Quaternion.Euler(0, 0, spot.Flipped ? 90 : -90); + spot.Perpendicular = true; } } else { @@ -546,8 +549,8 @@ namespace Parking else allBorders.Add(targetSpotPosition.y + sizeOffset); } - - if(12.85 - 2.5/2.0f <= maxX && lane == 2 && up) + + if (12.85 - 2.5 / 2.0f <= maxX && lane == 2 && up) allBorders.Add(Height / 2.0f - 5); if (allBorders.Count == 0) @@ -574,7 +577,7 @@ namespace Parking else allBorders.Add(spotPosition.x + sizeOffset); } - + allBorders.Sort(); if (right) { foreach (float adjacentBorder in allBorders) @@ -592,8 +595,7 @@ namespace Parking return position.x + (right ? 1 : -1) * _spotHeights[(int) size] / 2.0f; if (right) return Width / 2.0f; - else - return -Width / 2.0f + 5.5f; + return -Width / 2.0f + 5.5f; } @@ -678,19 +680,21 @@ namespace Parking // (spotMap[i][j].Perpendicular // ? 2.25f / 2.0f // : spotSizes[(int) spotMap[i][j].Size] / 2.0f); - - if(spotMap[i][j].Size != Size.D) + + if (spotMap[i][j].Size != Size.D) { currentX += (i != 0 ? 1 : -1) * (spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f + (j != 0 ? 0.25f : 0)); - else + } + else { currentX += (i != 0 ? 1 : -1) * (spotMap[i][j].Perpendicular ? 2.5f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f + (j != 0 ? 0.25f : 0)); + } + - spotMap[i][j].Flipped = flipped; bool alignTop = i % 2 != 0; spotMap[i][j].GameObject = Instantiate(prefabs[(int) spotMap[i][j].Size], mainPlanContainer); @@ -724,21 +728,20 @@ namespace Parking bool frontalParking = !(!parkingFromTop ^ flipped); spotMap[i][j].ParkingDirection = frontalParking ? ParkingPreference.Front : ParkingPreference.Back; - if(frontalParking) - spotMap[i][j].GameObject.transform.localScale *= 0.5f; - spotMap[i][j].Lane = i; - if(spotMap[i][j].Size != Size.D) + if (spotMap[i][j].Size != Size.D) { currentX += (i != 0 ? 1 : -1) * (spotMap[i][j].Perpendicular ? 2.25f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f + 0.25f); - else + } + else { currentX += (i != 0 ? 1 : -1) * (spotMap[i][j].Perpendicular ? 2.5f / 2.0f : spotSizes[(int) spotMap[i][j].Size] / 2.0f + 0.25f); + } flipped = !flipped; }