Added perpendicular spot generation

This commit is contained in:
Dawid Pietrykowski 2022-10-29 21:36:32 +02:00
parent d7218e6352
commit d4a4bcbebe
3 changed files with 18 additions and 48 deletions

View File

@ -2932,7 +2932,7 @@ MonoBehaviour:
mainPlanContainer: {fileID: 557435656} mainPlanContainer: {fileID: 557435656}
emergencyPlanContainer: {fileID: 632826360} emergencyPlanContainer: {fileID: 632826360}
reconfigurationToggle: {fileID: 441283505} reconfigurationToggle: {fileID: 441283505}
defaultPath: /home/dawp/Projects/Commisions/Parking/Assets/Data/Tablica5_2022-09-09.csv defaultPath: /home/davp/Projects/Customers/Parking/Assets/Data/Tablica5.csv
--- !u!1 &1347097428 --- !u!1 &1347097428
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -840,36 +840,32 @@ namespace Parking
} }
// return false; // return false;
float lastLeftBorder = Width / 2.0f;
spaceNeeded = 2.25f; spaceNeeded = 2.25f;
// Try for perpendicular // Try for perpendicular
for (int i = _spotMap[0].Count - 1; i >= -1; i--) { for (int i = 0; i < _spotMap[0].Count; i++) {
float leftBorder; float rightBorder = _spotMap[0][i].RightBorder;
if (i >= 0) { if (lastLeftBorder - rightBorder >= spaceNeeded) {
leftBorder = _spotMap[0][i].LeftBorder; newPosition.x = (lastLeftBorder - (2.25f / 2.0f));
} if(newPosition.x < Width / 2.0f - 2.25f && newPosition.x > Width / 2.0f - 5.5f - 2.25f)
else continue;
leftBorder = Width / 2.0f; newPosition.y = (-Height / 2.0f) + SpotHeights[(int)(size)] / 2.0f;
if (leftBorder - lastRightBorder >= spaceNeeded) {
newPosition.x = (lastRightBorder + 0.5f + SpotHeights[(int)size] / 2.0f);
newPosition.y = (-Height / 2.0f) + 2.25f / 2.0f;
float nextBorder = GetNextBorderVectical(newPosition, 0, true, size, true); float nextBorder = GetNextBorderVectical(newPosition, 0, true, size, true);
float spotBorder = -Height / 2.0f + SpotHeights[(int) size]; float spotBorder = -Height / 2.0f + SpotHeights[(int) size];
if(nextBorder - spotBorder < 5.5f) if(nextBorder - spotBorder < 5.5f)
continue; continue;
Spot newSpot = new Spot(size, false); Spot newSpot = new Spot(size, false);
//newPosition.x = (lastRightBorder + SpotHeights[(int)size] / 2.0f); //newPosition.x = (lastRightBorder + SpotHeights[(int)size] / 2.0f);
newSpot.Perpendicular = false; newSpot.Perpendicular = true;
newSpot.GameObject = Instantiate(_spotPrefabs[(int)size], newSpot.GameObject = Instantiate(_spotPrefabs[(int)size],
newPosition, Quaternion.Euler(0, 0, 90), mainPlanContainer); // TODO: Account for order
newPosition, Quaternion.Euler(0, 0, 0), mainPlanContainer);
_spotMap[0].Add(newSpot); _spotMap[0].Add(newSpot);
_spotMap[0].Sort((a, b) => Comparer<float>.Default.Compare(b.Position.x, a.Position.x)); _spotMap[0].Sort((a, b) => Comparer<float>.Default.Compare(b.Position.x, a.Position.x));
return true; return true;
} }
if (i >= 0) lastLeftBorder = _spotMap[0][i].LeftBorder;
lastRightBorder = _spotMap[0][i].RightBorder;
} }
return false; return false;
@ -928,8 +924,8 @@ namespace Parking
private float GetNextBorderVectical(Vector3 position, int lane, bool perpendicular, Size size, bool up) private float GetNextBorderVectical(Vector3 position, int lane, bool perpendicular, Size size, bool up)
{ {
float minX = position.x - (perpendicular ? 2.25f : SpotHeights[(int) size]); float minX = position.x - (perpendicular ? 2.25f : SpotHeights[(int) size]) - 2.25f/2.0f;
float maxX = position.x + (perpendicular ? 2.25f : SpotHeights[(int) size]); float maxX = position.x + (perpendicular ? 2.25f : SpotHeights[(int) size]) + 2.25f/2.0f;
List<float> allBorders = new(); List<float> allBorders = new();
List<Spot> targetLane = up ? _spotMap[lane + 1] : _spotMap[lane - 1]; List<Spot> targetLane = up ? _spotMap[lane + 1] : _spotMap[lane - 1];

File diff suppressed because one or more lines are too long