Fixed initial spot instantiation

This commit is contained in:
Dawid Pietrykowski 2022-09-05 00:47:52 +02:00
parent 66558149ca
commit c056b9389d
2 changed files with 28 additions and 20 deletions

View File

@ -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);
}

View File

@ -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));