From c056b9389d47fec08fe4e3a05329dd0788fc68d1 Mon Sep 17 00:00:00 2001 From: Dawid Pietrykowski Date: Mon, 5 Sep 2022 00:47:52 +0200 Subject: [PATCH] Fixed initial spot instantiation --- .../Scripts/InitialConfigurationGenerator.cs | 6 +-- Assets/Scripts/ParkingManager.cs | 42 +++++++++++-------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/Assets/Scripts/InitialConfigurationGenerator.cs b/Assets/Scripts/InitialConfigurationGenerator.cs index 2591a8a..ca5a2f0 100644 --- a/Assets/Scripts/InitialConfigurationGenerator.cs +++ b/Assets/Scripts/InitialConfigurationGenerator.cs @@ -162,14 +162,14 @@ namespace Parking // $"P3: {spotCountsPerpendicular[2]} P4: {spotCountsPerpendicular[3]} " + // $"Sum: {spotCountsPerpendicular.Sum()}"); - Debug.Log("Generating combinations..."); + // Debug.Log("Generating combinations..."); int[] arr = {0, 1, 2, 3, 4}; var n = arr.Length; var r = 4; CombinationRepetition(arr, n, r); - Debug.Log($"Found {Combinations.Count} available combinations"); + // Debug.Log($"Found {Combinations.Count} available combinations"); - Debug.Log("Sorting available combinations..."); + // Debug.Log("Sorting available combinations..."); Combinations.Sort(UsesMoreSpaceComparator); } diff --git a/Assets/Scripts/ParkingManager.cs b/Assets/Scripts/ParkingManager.cs index 1d13306..6895e87 100644 --- a/Assets/Scripts/ParkingManager.cs +++ b/Assets/Scripts/ParkingManager.cs @@ -74,10 +74,10 @@ namespace Parking } // Find spot - for (var j = 3; j >= 0; j--) - foreach (Spot spot in _spotMap[j]) - if (!spot.Reserved && spot.Size != Size.D) - Debug.Log("Spot not reserved"); + // for (var j = 3; j >= 0; j--) + // foreach (Spot spot in _spotMap[j]) + // if (!spot.Reserved && spot.Size != Size.D) + // Debug.Log("Spot not reserved"); } public void AdvanceTime() @@ -269,23 +269,34 @@ namespace Parking { var spotMap = GenerateSpotMap(spotsCreated); - var maxP3 = spotMap[2].Count == 0 ? 0 : _spotHeights[(int) spotMap[2].Max().Size]; - var maxP2 = spotMap[1].Count == 0 ? 0 : _spotHeights[(int) spotMap[1].Max().Size]; + float[] spotSizes = {4, 4.5f, 5, 0}; + float maxP3 = 0; + float maxP2 = 0; + foreach (Spot spot in spotMap[2]) + if(spot.Size != Size.D) + maxP3 = Math.Max(maxP3, _spotHeights[(int) spot.Size]); + foreach (Spot spot in spotMap[1]) + if(spot.Size != Size.D) + maxP2 = Math.Max(maxP2, _spotHeights[(int) spot.Size]); + + // float maxP3 = spotMap[2].Count == 0 ? 0 : _spotHeights[(int) spotMap[2].Max().Size]; + // float maxP2 = spotMap[1].Count == 0 ? 0 : _spotHeights[(int) spotMap[1].Max().Size]; for (var i = 0; i < 4; i++) { float currentY; + bool parkingFromTop = i % 2 != 0; switch (i) { case 0: - currentY = -Height / 2.0f + 2f; + currentY = -Height / 2.0f; break; case 1: - currentY = Height / 2 - 5.5f - 5f - maxP3 / 2.0f - maxP2; + currentY = Height / 2.0f - 5.5f - 5.0f - maxP3; break; case 2: - currentY = Height / 2 - 5.5f - 5f - maxP3 / 2.0f; + currentY = Height / 2.0f - 5.5f - 5.0f - maxP3; break; case 3: - currentY = Height / 2.0f - 2f; + currentY = Height / 2.0f; break; default: currentY = -10; @@ -297,7 +308,6 @@ namespace Parking else currentX = -Width / 2f + 5.5f - 2.25f / 2f + 2.25f + 1.75f; var flipped = false; - var parkingFromTop = i % 2 != 0; for (var j = 0; j < spotMap[i].Count; j++) { spotMap[i][j].Flipped = flipped; @@ -305,24 +315,22 @@ namespace Parking switch (spotMap[i][j].Size) { case Size.A: spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA); - spotMap[i][j].GameObject.transform.position = new Vector3(currentX, currentY, 0); break; case Size.B: spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabB); - spotMap[i][j].GameObject.transform.position = - new Vector3(currentX, currentY + (alignTop ? -1 : 1) * 0.25f, 0); break; case Size.C: spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabC); - spotMap[i][j].GameObject.transform.position = - new Vector3(currentX, currentY + (alignTop ? -1 : 1) * 0.5f, 0); break; case Size.D: spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabD); spotMap[i][j].GameObject.transform.position = - new Vector3(currentX, currentY - 2.0f, 0); + new Vector3(currentX, currentY, 0); break; } + spotMap[i][j].GameObject.transform.position = + new Vector3(currentX, currentY + (alignTop ? -1 : 1) * spotSizes[(int)spotMap[i][j].Size] / 2.0f, 0); + spotMap[i][j].GameObject.transform.rotation = Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 0));