WIP Reconfiguration

This commit is contained in:
Dawid Pietrykowski 2022-09-08 20:42:11 +02:00
parent f2f74c07a3
commit ccec674836
2 changed files with 41 additions and 71 deletions

View File

@ -2758,7 +2758,7 @@ MonoBehaviour:
mainPlanContainer: {fileID: 557435656} mainPlanContainer: {fileID: 557435656}
emergencyPlanContainer: {fileID: 632826360} emergencyPlanContainer: {fileID: 632826360}
reconfigurationToggle: {fileID: 441283505} reconfigurationToggle: {fileID: 441283505}
defaultPath: Assets/Data/Tablica1.csv defaultPath: Assets/Data/Tablica3.csv
--- !u!1 &1347097428 --- !u!1 &1347097428
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -344,37 +344,26 @@ namespace Parking
continue; continue;
if (spot.LastReconfiguration == _currentTime) if (spot.LastReconfiguration == _currentTime)
continue; continue;
if (spot.Size > newSize) {
int size = (int) newSize; 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; float diff = (_spotHeights[(int) spot.Size] - _spotHeights[size]) / 2.0f;
if (!spot.AlignToTop) if (!spot.AlignToTop)
diff *= -1; 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 offset = spot.Perpendicular ? new Vector3(0, diff, 0) : new Vector3(-diff, 0, 0);
Vector3 newPosition = position + offset; Vector3 newPosition = position + offset;
if (spot.Size > newSize) {
if (!spot.Perpendicular) { 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; _spotHeights[(int) spot.Size] / 2.0f;
newPosition = new Vector3(newX, newPosition = new Vector3(newX,
newPosition.y, newPosition.z); newPosition.y, newPosition.z);
} }
else { 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) { if (spot.Lane == 0) {
float xRelativeToRight = newX - Width / 2.0f - 2.25f / 2.0f; float xRelativeToRight = newX - Width / 2.0f - 2.25f / 2.0f;
xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f; xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f;
@ -389,22 +378,7 @@ namespace Parking
newPosition = new Vector3(newX, newPosition = new Vector3(newX,
newPosition.y, newPosition.z); newPosition.y, newPosition.z);
} }
}else if (spot.Size < newSize) {
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;
float spotBorder; float spotBorder;
float thisSizeOffset; float thisSizeOffset;
if (spot.Perpendicular) if (spot.Perpendicular)
@ -415,34 +389,30 @@ namespace Parking
spotBorder = position.y + thisSizeOffset; spotBorder = position.y + thisSizeOffset;
else else
spotBorder = position.y - thisSizeOffset; spotBorder = position.y - thisSizeOffset;
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize, !spot.AlignToTop); if (spot.Perpendicular) {
float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize,
!spot.AlignToTop);
if (Math.Abs(spotBorder - nextBorder) < 5.5f) if (Math.Abs(spotBorder - nextBorder) < 5.5f)
continue; continue;
}
spot.Size = (Size) size; else {
Quaternion rotation = Quaternion.identity; float nextBorderLeft = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
if (spot.GameObject != null) { !spot.AlignToTop);
position = spot.GameObject.transform.position; float nextBorderRight = GetNextBorderHorizontal(position, spot.Lane, spot.Perpendicular, newSize,
rotation = spot.GameObject.transform.rotation; !spot.AlignToTop);
Destroy(spot.GameObject); if(nextBorderRight - nextBorderLeft < _spotHeights[(int) newSize])
continue;
}
} }
Destroy(spot.GameObject);
spot.Size = (Size) size;
spot.Reserved = false; 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], spot.GameObject = Instantiate(_spotPrefabs[size],
newPosition, rotation, mainPlanContainer); newPosition, rotation, mainPlanContainer);
spot.LastReconfiguration = _currentTime; spot.LastReconfiguration = _currentTime;
return true; return true;
} }
}
return false; return false;
} }
@ -476,12 +446,12 @@ namespace Parking
return nextBorder; 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<float> allBorders = new List<float>(); List<float> allBorders = new List<float>();
List<Spot> targetLane = _spotMap[spot.Lane]; List<Spot> targetLane = _spotMap[lane];
foreach (Spot spot1 in targetLane) { foreach (Spot spot1 in targetLane) {
if (spot1 == spot) if (spot1.GameObject.transform.position == position)
continue; continue;
Vector3 spotPosition = spot1.GameObject.transform.position; Vector3 spotPosition = spot1.GameObject.transform.position;
float sizeOffset; float sizeOffset;
@ -498,8 +468,8 @@ namespace Parking
if (adjacentBorder > position.x) if (adjacentBorder > position.x)
return adjacentBorder; return adjacentBorder;
if (spot.Perpendicular) if (perpendicular)
return position.x + (right ? 1 : -1) * _spotHeights[(int) spot.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 position.x + (right ? 1 : -1) * 2.25f / 2.0f;
} }