Basic reconfiguration added

This commit is contained in:
Dawid Pietrykowski 2022-09-05 22:00:15 +02:00
parent 1d16f1dc7e
commit a2c9647681
5 changed files with 50 additions and 5 deletions

3
.gitignore vendored
View File

@ -74,5 +74,8 @@ crashlytics-build.properties
/[Aa]ssets/[Ss]treamingAssets/aa.meta
/[Aa]ssets/[Ss]treamingAssets/aa/*
# Lock files
**/.~lock*
# Notes
/Notes/

View File

@ -1 +0,0 @@
,davp,arch-desktop,04.09.2022 23:00,file:///home/davp/.config/libreoffice/4;

View File

@ -532,7 +532,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 557435655}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.6363324, y: 1.5066413, z: -0.28673837}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -647,7 +647,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 632826359}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -1.6363324, y: 1.5066413, z: -0.28673837}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []

View File

@ -47,6 +47,9 @@ namespace Parking
public bool Reserved = false;
public int ReservedPriority = 0;
public ParkingPreference ParkingDirection = ParkingPreference.Any;
public int Lane = 0;
public bool Perpendicular = true;
public bool AlignToTop = true;
public Spot(Size size, bool flipped)
{

View File

@ -29,7 +29,7 @@ namespace Parking
[SerializeField] public Transform mainPlanContainer;
[SerializeField] public Transform emergencyPlanContainer;
private readonly float[] _spotHeights = {3.5f, 4f, 5f, 7.5f};
private readonly float[] _spotHeights = {4f, 4.5f, 5f, 7.5f};
private readonly List<List<Spot>> _spotMap = new()
{new List<Spot>(), new List<Spot>(), new List<Spot>(), new List<Spot>()};
@ -231,6 +231,7 @@ namespace Parking
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
driver.GameObject.transform.position = spot.GameObject.transform.position;
driver.GameObject.transform.localPosition += new Vector3(0, 0, -1);
driver.GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
}
@ -242,6 +243,8 @@ namespace Parking
private void ReconfigureSpots()
{
List<GameObject> prefabs = new List<GameObject>()
{spotPrefabA, spotPrefabB, spotPrefabC};
int[] freeSpots = GetFreeSpotCount();
var nextCars = GetNextCars(10);
int[] plannedSpots = {0, 0, 0, 0};
@ -255,8 +258,41 @@ namespace Parking
if (neededSpots.Sum() > 5) {
Debug.Log($"Needed spots = {neededSpots[0]} {neededSpots[1]} {neededSpots[2]} {neededSpots[3]}");
Debug.Log("Attempting reconfiguration...");
}
for (int size = 0; size < 3; size++) {
bool foundReplacement = true;
while (foundReplacement && neededSpots[size] != 0) {
foundReplacement = false;
foreach (var t in _spotMap) {
foreach (Spot spot in t) {
if ((int) spot.Size > size && spot.Free && spot.Lane != 3 && spot.Size != Size.D) {
foundReplacement = true;
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.GameObject = Instantiate(prefabs[size],
position + new Vector3(0, diff, 0), rotation, mainPlanContainer);
goto whileEnd;
}
}
}
whileEnd:;
}
}
}
}
private int[] GetFreeSpotCount()
@ -353,6 +389,7 @@ namespace Parking
new Vector3(currentX,
currentY + (alignTop ? -1 : 1) * spotSizes[(int) spotMap[i][j].Size] / 2.0f, 0);
spotMap[i][j].AlignToTop = alignTop;
spotMap[i][j].GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 0));
@ -360,6 +397,8 @@ namespace Parking
bool frontalParking = !parkingFromTop ^ flipped;
spotMap[i][j].ParkingDirection = frontalParking ? ParkingPreference.Front : ParkingPreference.Back;
spotMap[i][j].Lane = i;
currentX += 2.25f;
flipped = !flipped;
@ -406,6 +445,7 @@ namespace Parking
Vector3 position = new Vector3(currentX, currentY + 2.25f/2.0f, 0);
spawnedSpot = Instantiate(Instance.spotPrefabC, position,
Quaternion.Euler(new Vector3(0, 0, 90)), emergencyPlanContainer);
currentX -= 5;
}else {
bool alignTop = i % 2 != 0;