Fixed initial spot instantiation
This commit is contained in:
parent
66558149ca
commit
c056b9389d
@ -162,14 +162,14 @@ namespace Parking
|
|||||||
// $"P3: {spotCountsPerpendicular[2]} P4: {spotCountsPerpendicular[3]} " +
|
// $"P3: {spotCountsPerpendicular[2]} P4: {spotCountsPerpendicular[3]} " +
|
||||||
// $"Sum: {spotCountsPerpendicular.Sum()}");
|
// $"Sum: {spotCountsPerpendicular.Sum()}");
|
||||||
|
|
||||||
Debug.Log("Generating combinations...");
|
// Debug.Log("Generating combinations...");
|
||||||
int[] arr = {0, 1, 2, 3, 4};
|
int[] arr = {0, 1, 2, 3, 4};
|
||||||
var n = arr.Length;
|
var n = arr.Length;
|
||||||
var r = 4;
|
var r = 4;
|
||||||
CombinationRepetition(arr, n, r);
|
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);
|
Combinations.Sort(UsesMoreSpaceComparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,10 +74,10 @@ namespace Parking
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find spot
|
// Find spot
|
||||||
for (var j = 3; j >= 0; j--)
|
// for (var j = 3; j >= 0; j--)
|
||||||
foreach (Spot spot in _spotMap[j])
|
// foreach (Spot spot in _spotMap[j])
|
||||||
if (!spot.Reserved && spot.Size != Size.D)
|
// if (!spot.Reserved && spot.Size != Size.D)
|
||||||
Debug.Log("Spot not reserved");
|
// Debug.Log("Spot not reserved");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AdvanceTime()
|
public void AdvanceTime()
|
||||||
@ -269,23 +269,34 @@ namespace Parking
|
|||||||
{
|
{
|
||||||
var spotMap = GenerateSpotMap(spotsCreated);
|
var spotMap = GenerateSpotMap(spotsCreated);
|
||||||
|
|
||||||
var maxP3 = spotMap[2].Count == 0 ? 0 : _spotHeights[(int) spotMap[2].Max().Size];
|
float[] spotSizes = {4, 4.5f, 5, 0};
|
||||||
var maxP2 = spotMap[1].Count == 0 ? 0 : _spotHeights[(int) spotMap[1].Max().Size];
|
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++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
float currentY;
|
float currentY;
|
||||||
|
bool parkingFromTop = i % 2 != 0;
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
currentY = -Height / 2.0f + 2f;
|
currentY = -Height / 2.0f;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
currentY = Height / 2 - 5.5f - 5f - maxP3 / 2.0f - maxP2;
|
currentY = Height / 2.0f - 5.5f - 5.0f - maxP3;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
currentY = Height / 2 - 5.5f - 5f - maxP3 / 2.0f;
|
currentY = Height / 2.0f - 5.5f - 5.0f - maxP3;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
currentY = Height / 2.0f - 2f;
|
currentY = Height / 2.0f;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
currentY = -10;
|
currentY = -10;
|
||||||
@ -297,7 +308,6 @@ namespace Parking
|
|||||||
else currentX = -Width / 2f + 5.5f - 2.25f / 2f + 2.25f + 1.75f;
|
else currentX = -Width / 2f + 5.5f - 2.25f / 2f + 2.25f + 1.75f;
|
||||||
|
|
||||||
var flipped = false;
|
var flipped = false;
|
||||||
var parkingFromTop = i % 2 != 0;
|
|
||||||
|
|
||||||
for (var j = 0; j < spotMap[i].Count; j++) {
|
for (var j = 0; j < spotMap[i].Count; j++) {
|
||||||
spotMap[i][j].Flipped = flipped;
|
spotMap[i][j].Flipped = flipped;
|
||||||
@ -305,24 +315,22 @@ namespace Parking
|
|||||||
switch (spotMap[i][j].Size) {
|
switch (spotMap[i][j].Size) {
|
||||||
case Size.A:
|
case Size.A:
|
||||||
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA);
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA);
|
||||||
spotMap[i][j].GameObject.transform.position = new Vector3(currentX, currentY, 0);
|
|
||||||
break;
|
break;
|
||||||
case Size.B:
|
case Size.B:
|
||||||
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabB);
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabB);
|
||||||
spotMap[i][j].GameObject.transform.position =
|
|
||||||
new Vector3(currentX, currentY + (alignTop ? -1 : 1) * 0.25f, 0);
|
|
||||||
break;
|
break;
|
||||||
case Size.C:
|
case Size.C:
|
||||||
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabC);
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabC);
|
||||||
spotMap[i][j].GameObject.transform.position =
|
|
||||||
new Vector3(currentX, currentY + (alignTop ? -1 : 1) * 0.5f, 0);
|
|
||||||
break;
|
break;
|
||||||
case Size.D:
|
case Size.D:
|
||||||
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabD);
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabD);
|
||||||
spotMap[i][j].GameObject.transform.position =
|
spotMap[i][j].GameObject.transform.position =
|
||||||
new Vector3(currentX, currentY - 2.0f, 0);
|
new Vector3(currentX, currentY, 0);
|
||||||
break;
|
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 =
|
spotMap[i][j].GameObject.transform.rotation =
|
||||||
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 0));
|
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 0));
|
||||||
|
Loading…
Reference in New Issue
Block a user