diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 6defdd5..ff78782 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -2758,7 +2758,7 @@ MonoBehaviour: mainPlanContainer: {fileID: 557435656} emergencyPlanContainer: {fileID: 632826360} reconfigurationToggle: {fileID: 441283505} - defaultPath: Assets/Data/Tablica1.csv + defaultPath: Assets/Data/Tablica3.csv --- !u!1 &1347097428 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/ParkingManager.cs b/Assets/Scripts/ParkingManager.cs index 6c1059d..95d78d0 100644 --- a/Assets/Scripts/ParkingManager.cs +++ b/Assets/Scripts/ParkingManager.cs @@ -344,37 +344,26 @@ namespace Parking continue; if (spot.LastReconfiguration == _currentTime) continue; + + int size = (int) newSize; + Vector3 position = spot.GameObject.transform.position; + Quaternion rotation = spot.GameObject.transform.rotation; + + float diff = (_spotHeights[(int) spot.Size] - _spotHeights[size]) / 2.0f; + if (!spot.AlignToTop) + diff *= -1; + Vector3 offset = spot.Perpendicular ? new Vector3(0, diff, 0) : new Vector3(-diff, 0, 0); + Vector3 newPosition = position + offset; + if (spot.Size > newSize) { - - int size = (int) newSize; - - float diff = (_spotHeights[(int) spot.Size] - _spotHeights[size]) / 2.0f; - if (!spot.AlignToTop) - diff *= -1; - - spot.Size = (Size) size; - Vector3 position = Vector3.zero; - Quaternion rotation = Quaternion.identity; - if (spot.GameObject != null) { - position = spot.GameObject.transform.position; - rotation = spot.GameObject.transform.rotation; - Destroy(spot.GameObject); - } - - spot.Reserved = false; - - Vector3 offset = spot.Perpendicular ? new Vector3(0, diff, 0) : new Vector3(-diff, 0, 0); - - Vector3 newPosition = position + offset; - if (!spot.Perpendicular) { - float newX = GetNextBorderHorizontal(position, spot, true) - + float newX = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, true) - _spotHeights[(int) spot.Size] / 2.0f; newPosition = new Vector3(newX, newPosition.y, newPosition.z); } else { - float newX = GetNextBorderHorizontal(position, spot, 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; @@ -389,22 +378,7 @@ namespace Parking newPosition = new Vector3(newX, newPosition.y, newPosition.z); } - - spot.GameObject = Instantiate(_spotPrefabs[size], - newPosition, rotation, mainPlanContainer); - - spot.LastReconfiguration = _currentTime; - return true; - } - - if (spot.Size < newSize) { - if (!spot.Perpendicular) - continue; - int size = (int) newSize; - float diff = (_spotHeights[(int) spot.Size] - _spotHeights[size]) / 2.0f; - - - Vector3 position = spot.GameObject.transform.position; + }else if (spot.Size < newSize) { float spotBorder; float thisSizeOffset; if (spot.Perpendicular) @@ -415,34 +389,30 @@ namespace Parking spotBorder = position.y + thisSizeOffset; else spotBorder = position.y - thisSizeOffset; - float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize, !spot.AlignToTop); - if (Math.Abs(spotBorder - nextBorder) < 5.5f) - continue; - - spot.Size = (Size) size; - Quaternion rotation = Quaternion.identity; - if (spot.GameObject != null) { - position = spot.GameObject.transform.position; - rotation = spot.GameObject.transform.rotation; - Destroy(spot.GameObject); + if (spot.Perpendicular) { + float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize, + !spot.AlignToTop); + if (Math.Abs(spotBorder - nextBorder) < 5.5f) + continue; + } + else { + float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, + !spot.AlignToTop); + float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize, + !spot.AlignToTop); + if(nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize]) + continue; } - - spot.Reserved = false; - if (!spot.AlignToTop) - diff *= -1; - - Vector3 offset = spot.Perpendicular ? new Vector3(0, diff, 0) : new Vector3(-diff, 0, 0); - Vector3 newPosition = position + offset; - - - - spot.GameObject = Instantiate(_spotPrefabs[size], - newPosition, rotation, mainPlanContainer); - spot.LastReconfiguration = _currentTime; - return true; } + + Destroy(spot.GameObject); + spot.Size = (Size) size; + spot.Reserved = false; + spot.GameObject = Instantiate(_spotPrefabs[size], + newPosition, rotation, mainPlanContainer); + spot.LastReconfiguration = _currentTime; + return true; } - return false; } @@ -476,12 +446,12 @@ namespace Parking return nextBorder; } - private float GetNextBorderHorizontal(Vector3 position, Spot spot, bool right) + private float GetNextBorderHorizontal(Vector3 position, int lane, bool perpendicular, Size size, bool right) { List allBorders = new List(); - List targetLane = _spotMap[spot.Lane]; + List targetLane = _spotMap[lane]; foreach (Spot spot1 in targetLane) { - if (spot1 == spot) + if (spot1.GameObject.transform.position == position) continue; Vector3 spotPosition = spot1.GameObject.transform.position; float sizeOffset; @@ -498,8 +468,8 @@ namespace Parking if (adjacentBorder > position.x) return adjacentBorder; - if (spot.Perpendicular) - return position.x + (right ? 1 : -1) * _spotHeights[(int) spot.Size] / 2.0f; + if (perpendicular) + return position.x + (right ? 1 : -1) * _spotHeights[(int) size] / 2.0f; return position.x + (right ? 1 : -1) * 2.25f / 2.0f; }