2022-08-25 17:58:26 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2022-08-28 22:42:21 +02:00
|
|
|
using System.Linq;
|
2022-08-25 17:58:26 +02:00
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
namespace Parking
|
2022-08-25 17:58:26 +02:00
|
|
|
{
|
2022-08-31 20:50:59 +02:00
|
|
|
public class ParkingManager : MonoBehaviour
|
2022-08-28 22:42:21 +02:00
|
|
|
{
|
2022-08-31 20:50:59 +02:00
|
|
|
public const float Width = 68;
|
|
|
|
public const float Height = 29;
|
2022-08-28 22:42:21 +02:00
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
public static ParkingManager Instance;
|
2022-08-28 22:42:21 +02:00
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
private static readonly TimeSpan StartTime = TimeSpan.FromHours(5) + TimeSpan.FromMinutes(45);
|
|
|
|
private static readonly TimeSpan EndTime = TimeSpan.FromHours(17) + TimeSpan.FromMinutes(15);
|
|
|
|
private static TimeSpan _currentTime = StartTime;
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
[SerializeField] private int stepTime = 15;
|
|
|
|
[SerializeField] private TextMeshProUGUI timeText;
|
|
|
|
[SerializeField] public TextMeshProUGUI countsText;
|
2022-09-03 00:23:15 +02:00
|
|
|
[SerializeField] public TextMeshProUGUI rejectedText;
|
2022-08-31 20:50:59 +02:00
|
|
|
[SerializeField] public GameObject spotPrefabA;
|
|
|
|
[SerializeField] public GameObject spotPrefabB;
|
|
|
|
[SerializeField] public GameObject spotPrefabC;
|
2022-08-31 21:19:20 +02:00
|
|
|
[SerializeField] public GameObject spotPrefabD;
|
2022-09-01 22:31:57 +02:00
|
|
|
[SerializeField] public GameObject carPrefab;
|
2022-09-05 01:15:04 +02:00
|
|
|
[SerializeField] public Transform mainPlanContainer;
|
|
|
|
[SerializeField] public Transform emergencyPlanContainer;
|
2022-08-28 22:42:21 +02:00
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
private readonly float[] _spotHeights = {3.5f, 4f, 5f, 7.5f};
|
2022-08-28 22:42:21 +02:00
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
private readonly List<List<Spot>> _spotMap = new()
|
2022-09-03 00:23:15 +02:00
|
|
|
{new List<Spot>(), new List<Spot>(), new List<Spot>(), new List<Spot>()};
|
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
private bool _emergencyActivated;
|
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
private int _initialConfigurationSpotCount;
|
2022-09-03 21:27:31 +02:00
|
|
|
private int[] _rejectedDrivers = {0, 0, 0, 0};
|
2022-08-28 22:42:21 +02:00
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
private void Awake()
|
2022-08-28 22:42:21 +02:00
|
|
|
{
|
2022-08-31 20:50:59 +02:00
|
|
|
Instance = this;
|
2022-08-28 22:42:21 +02:00
|
|
|
}
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
timeText.text = _currentTime.ToString();
|
2022-09-03 21:27:31 +02:00
|
|
|
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
|
|
|
|
$"Duże: {_rejectedDrivers[2]}";
|
2022-09-05 01:15:04 +02:00
|
|
|
GenerateEmergencyPlan();
|
|
|
|
|
|
|
|
DataImporter.ReadFile("Assets/Data/Tablica4.csv");
|
2022-08-31 20:50:59 +02:00
|
|
|
InitialConfigurationGenerator generator = new();
|
|
|
|
ArrangeSpots(generator.FindSolution());
|
2022-09-04 00:35:45 +02:00
|
|
|
ReserveInitialSpots();
|
|
|
|
}
|
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
public void Emergency()
|
|
|
|
{
|
|
|
|
ResetDrivers();
|
|
|
|
_emergencyActivated = true;
|
|
|
|
}
|
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
private void ReserveInitialSpots()
|
|
|
|
{
|
2022-09-05 01:15:04 +02:00
|
|
|
for (int j = 3; j >= 0; j--)
|
2022-09-04 12:47:46 +02:00
|
|
|
foreach (Spot spot in _spotMap[j]) {
|
|
|
|
spot.Reserved = false;
|
|
|
|
spot.ReservedPriority = 0;
|
|
|
|
}
|
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
for (int i = 0; i < Math.Min(DataImporter.Drivers.Count, _initialConfigurationSpotCount); i++) {
|
2022-09-04 00:35:45 +02:00
|
|
|
bool found = false;
|
|
|
|
// Find spot
|
2022-09-05 01:15:04 +02:00
|
|
|
for (int j = 3; j >= 0 && !found; j--)
|
2022-09-04 00:35:45 +02:00
|
|
|
foreach (Spot spot in _spotMap[j])
|
|
|
|
if (spot.Size == DataImporter.Drivers[i].Size && !spot.Reserved) {
|
|
|
|
spot.Reserved = true;
|
|
|
|
spot.ReservedPriority = DataImporter.Drivers[i].Priority;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find spot
|
2022-09-05 00:47:52 +02:00
|
|
|
// 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");
|
2022-08-28 22:42:21 +02:00
|
|
|
}
|
2022-08-29 23:01:18 +02:00
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
public void AdvanceTime()
|
|
|
|
{
|
2022-09-04 00:35:45 +02:00
|
|
|
// Update time
|
2022-09-03 21:27:31 +02:00
|
|
|
_currentTime += TimeSpan.FromMinutes(stepTime);
|
2022-09-04 00:35:45 +02:00
|
|
|
if (_currentTime > EndTime) {
|
2022-09-03 21:27:31 +02:00
|
|
|
_currentTime = StartTime;
|
2022-09-05 01:15:04 +02:00
|
|
|
timeText.text = _currentTime.ToString();
|
2022-09-04 00:35:45 +02:00
|
|
|
_rejectedDrivers = new[] {0, 0, 0, 0};
|
2022-09-03 21:27:31 +02:00
|
|
|
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
|
|
|
|
$"Duże: {_rejectedDrivers[2]}";
|
2022-09-05 01:15:04 +02:00
|
|
|
if (_emergencyActivated) {
|
|
|
|
emergencyPlanContainer.gameObject.SetActive(true);
|
|
|
|
mainPlanContainer.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ReserveInitialSpots();
|
|
|
|
ResetDrivers();
|
|
|
|
}
|
2022-09-03 21:27:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2022-09-04 00:35:45 +02:00
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
timeText.text = _currentTime.ToString();
|
2022-09-04 00:35:45 +02:00
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
if (_emergencyActivated)
|
|
|
|
return;
|
2022-09-04 00:35:45 +02:00
|
|
|
|
|
|
|
foreach (Driver driver in DataImporter.Drivers) {
|
2022-09-04 12:47:46 +02:00
|
|
|
// TODO: Check if car can stay before other reservation - may not work for priority-based reservations
|
2022-09-05 01:15:04 +02:00
|
|
|
bool triesToPark = _currentTime <= driver.Times[3].TimeOfDay &&
|
|
|
|
_currentTime > driver.Times[2].TimeOfDay;
|
|
|
|
bool leftTheParking = _currentTime > driver.Times[3].TimeOfDay && driver.Parked;
|
2022-09-04 13:36:19 +02:00
|
|
|
bool reservedButTimedout =
|
2022-09-05 01:15:04 +02:00
|
|
|
(_currentTime - driver.Times[0].TimeOfDay).TotalMinutes > driver.UpdateInterval &&
|
2022-09-04 13:36:19 +02:00
|
|
|
GetReservedSpotCount(driver.Priority, driver.Size) > 0
|
|
|
|
&& !driver.Parked && !driver.Rejected && _currentTime <= driver.Times[3].TimeOfDay;
|
2022-09-04 00:35:45 +02:00
|
|
|
if (triesToPark && !driver.Parked && !driver.Rejected) {
|
|
|
|
if (!PlaceCarOnParking(driver)) {
|
2022-09-03 21:27:31 +02:00
|
|
|
Debug.Log($"Placing failed for car {driver.Number}");
|
2022-09-03 00:23:15 +02:00
|
|
|
driver.Rejected = true;
|
2022-09-04 00:35:45 +02:00
|
|
|
_rejectedDrivers[(int) driver.Size]++;
|
2022-09-03 21:27:31 +02:00
|
|
|
rejectedText.text = $"Małe: {_rejectedDrivers[0]} Średnie: {_rejectedDrivers[1]} " +
|
|
|
|
$"Duże: {_rejectedDrivers[2]}";
|
2022-09-03 00:23:15 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-04 00:35:45 +02:00
|
|
|
else if (leftTheParking) {
|
|
|
|
driver.Spot.Reserved = false;
|
2022-09-03 21:27:31 +02:00
|
|
|
driver.Reset();
|
2022-09-05 01:15:04 +02:00
|
|
|
}
|
|
|
|
else if (reservedButTimedout) {
|
2022-09-04 13:36:19 +02:00
|
|
|
Debug.Log($"Reserved but timed out driver {driver.Number}");
|
|
|
|
driver.Rejected = true;
|
2022-09-01 22:31:57 +02:00
|
|
|
}
|
2022-09-04 00:35:45 +02:00
|
|
|
}
|
2022-09-04 13:36:19 +02:00
|
|
|
|
|
|
|
ReconfigureSpots();
|
2022-09-01 22:31:57 +02:00
|
|
|
}
|
|
|
|
|
2022-09-03 21:27:31 +02:00
|
|
|
private void ResetDrivers()
|
|
|
|
{
|
2022-09-05 01:15:04 +02:00
|
|
|
foreach (Driver driver in DataImporter.Drivers) {
|
2022-09-04 12:47:46 +02:00
|
|
|
if (driver.Spot != null) {
|
|
|
|
driver.Spot.Reserved = false;
|
|
|
|
driver.Spot.ReservedPriority = 0;
|
|
|
|
}
|
2022-09-05 01:15:04 +02:00
|
|
|
|
2022-09-03 21:27:31 +02:00
|
|
|
driver.Reset();
|
2022-09-04 12:47:46 +02:00
|
|
|
}
|
2022-09-04 00:35:45 +02:00
|
|
|
}
|
|
|
|
|
2022-09-04 13:36:19 +02:00
|
|
|
private int GetReservedSpotCount(int priority, Size size)
|
|
|
|
{
|
|
|
|
int count = 0;
|
2022-09-05 01:15:04 +02:00
|
|
|
foreach (var list in _spotMap)
|
|
|
|
foreach (Spot spot in list)
|
|
|
|
if (spot.Size == size && spot.Reserved && spot.ReservedPriority == priority)
|
|
|
|
count++;
|
2022-09-04 13:36:19 +02:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
private bool FindReservedSpot(Driver driver, out Spot spot)
|
|
|
|
{
|
|
|
|
foreach (var list in _spotMap)
|
|
|
|
foreach (Spot spot1 in list)
|
|
|
|
if (spot1.Reserved && spot1.ReservedPriority == driver.Priority) {
|
|
|
|
spot = spot1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
spot = new Spot();
|
|
|
|
|
|
|
|
return false;
|
2022-09-03 21:27:31 +02:00
|
|
|
}
|
|
|
|
|
2022-09-03 00:23:15 +02:00
|
|
|
private bool PlaceCarOnParking(Driver driver)
|
2022-09-01 22:31:57 +02:00
|
|
|
{
|
2022-09-04 00:35:45 +02:00
|
|
|
if (FindReservedSpot(driver, out Spot reservedSpot)) {
|
|
|
|
if (reservedSpot.Free) {
|
|
|
|
PlaceDriverOnSpot(driver, reservedSpot);
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-05 01:15:04 +02:00
|
|
|
|
|
|
|
Debug.Log("Spot should be reserved but is taken");
|
2022-09-04 00:35:45 +02:00
|
|
|
}
|
2022-09-03 00:23:15 +02:00
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
|
|
|
|
foreach (var t in _spotMap)
|
|
|
|
foreach (Spot spot in t) {
|
2022-09-05 01:15:04 +02:00
|
|
|
bool spotAvailable = spot.Size == driver.Size && spot.Free &&
|
|
|
|
(spot.ParkingDirection == driver.ParkingPreference ||
|
|
|
|
spot.ParkingDirection == ParkingPreference.Any)
|
|
|
|
&& !spot.Reserved;
|
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
if (spotAvailable) {
|
|
|
|
PlaceDriverOnSpot(driver, spot);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var t in _spotMap)
|
|
|
|
foreach (Spot spot in t)
|
|
|
|
if (spot.Size == driver.Size && spot.Free && !spot.Reserved) {
|
|
|
|
PlaceDriverOnSpot(driver, spot);
|
|
|
|
return true;
|
|
|
|
}
|
2022-09-03 00:23:15 +02:00
|
|
|
|
|
|
|
return false;
|
2022-08-31 20:50:59 +02:00
|
|
|
}
|
2022-08-29 23:01:18 +02:00
|
|
|
|
2022-09-04 00:35:45 +02:00
|
|
|
private void PlaceDriverOnSpot(Driver driver, Spot spot)
|
|
|
|
{
|
|
|
|
spot.Free = false;
|
|
|
|
spot.Reserved = false;
|
|
|
|
driver.Spot = spot;
|
|
|
|
driver.Parked = true;
|
|
|
|
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
|
|
|
|
driver.GameObject.GetComponentInChildren<TextMeshProUGUI>().text = driver.Number.ToString();
|
|
|
|
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.rotation =
|
|
|
|
Quaternion.Euler(new Vector3(0, 0, spot.Flipped ? 180 : 0));
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
public void UpdateText(string text)
|
2022-08-29 23:01:18 +02:00
|
|
|
{
|
2022-08-31 20:50:59 +02:00
|
|
|
countsText.text = text;
|
2022-08-29 23:01:18 +02:00
|
|
|
}
|
2022-08-29 23:32:16 +02:00
|
|
|
|
2022-09-03 21:27:31 +02:00
|
|
|
private void ReconfigureSpots()
|
|
|
|
{
|
2022-09-05 01:15:04 +02:00
|
|
|
int[] freeSpots = GetFreeSpotCount();
|
2022-09-04 00:35:45 +02:00
|
|
|
var nextCars = GetNextCars(10);
|
|
|
|
int[] plannedSpots = {0, 0, 0, 0};
|
2022-09-03 21:27:31 +02:00
|
|
|
foreach (Driver driver in nextCars)
|
2022-09-04 00:35:45 +02:00
|
|
|
plannedSpots[(int) driver.Size]++;
|
|
|
|
|
|
|
|
int[] neededSpots = {0, 0, 0, 0};
|
2022-09-03 21:27:31 +02:00
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
for (int i = 0; i < neededSpots.Length; i++)
|
2022-09-04 13:36:19 +02:00
|
|
|
neededSpots[i] = Math.Max(plannedSpots[i] - freeSpots[i], 0);
|
|
|
|
if (neededSpots.Sum() > 5) {
|
2022-09-03 21:27:31 +02:00
|
|
|
Debug.Log($"Needed spots = {neededSpots[0]} {neededSpots[1]} {neededSpots[2]} {neededSpots[3]}");
|
2022-09-04 00:35:45 +02:00
|
|
|
Debug.Log("Attempting reconfiguration...");
|
2022-09-03 21:27:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private int[] GetFreeSpotCount()
|
|
|
|
{
|
2022-09-04 00:35:45 +02:00
|
|
|
int[] freeSpots = {0, 0, 0, 0};
|
|
|
|
foreach (var t in _spotMap)
|
2022-09-03 21:27:31 +02:00
|
|
|
foreach (Spot spot in t)
|
|
|
|
if (spot.Free)
|
2022-09-04 00:35:45 +02:00
|
|
|
freeSpots[(int) spot.Size]++;
|
2022-09-03 21:27:31 +02:00
|
|
|
return freeSpots;
|
|
|
|
}
|
2022-09-04 00:35:45 +02:00
|
|
|
|
2022-09-03 21:27:31 +02:00
|
|
|
private List<Driver> GetNextCars(int n)
|
|
|
|
{
|
2022-09-04 00:35:45 +02:00
|
|
|
var nextCars = new List<Driver>();
|
2022-09-03 21:27:31 +02:00
|
|
|
TimeSpan updatedTime = _currentTime + TimeSpan.FromMinutes(stepTime);
|
2022-09-04 00:35:45 +02:00
|
|
|
while (nextCars.Count < n && updatedTime < EndTime) {
|
2022-09-03 21:27:31 +02:00
|
|
|
foreach (Driver driver in DataImporter.Drivers)
|
2022-09-04 13:36:19 +02:00
|
|
|
if (updatedTime <= driver.Times[1].TimeOfDay &&
|
|
|
|
updatedTime > driver.Times[0].TimeOfDay &&
|
2022-09-03 21:27:31 +02:00
|
|
|
!driver.Parked && !driver.Rejected && !nextCars.Contains(driver))
|
|
|
|
nextCars.Add(driver);
|
|
|
|
updatedTime += TimeSpan.FromMinutes(stepTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextCars;
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
private void ArrangeSpots(int[,] spotsCreated)
|
2022-08-29 23:01:18 +02:00
|
|
|
{
|
2022-08-31 20:50:59 +02:00
|
|
|
var spotMap = GenerateSpotMap(spotsCreated);
|
|
|
|
|
2022-09-05 00:47:52 +02:00
|
|
|
float[] spotSizes = {4, 4.5f, 5, 0};
|
|
|
|
float maxP3 = 0;
|
|
|
|
float maxP2 = 0;
|
2022-09-05 01:15:04 +02:00
|
|
|
foreach (Spot spot in spotMap[2])
|
|
|
|
if (spot.Size != Size.D)
|
2022-09-05 00:47:52 +02:00
|
|
|
maxP3 = Math.Max(maxP3, _spotHeights[(int) spot.Size]);
|
2022-09-05 01:15:04 +02:00
|
|
|
foreach (Spot spot in spotMap[1])
|
|
|
|
if (spot.Size != Size.D)
|
2022-09-05 00:47:52 +02:00
|
|
|
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];
|
2022-08-31 20:50:59 +02:00
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2022-08-31 20:50:59 +02:00
|
|
|
float currentY;
|
2022-09-05 00:47:52 +02:00
|
|
|
bool parkingFromTop = i % 2 != 0;
|
2022-09-04 00:35:45 +02:00
|
|
|
switch (i) {
|
2022-08-31 20:50:59 +02:00
|
|
|
case 0:
|
2022-09-05 00:47:52 +02:00
|
|
|
currentY = -Height / 2.0f;
|
2022-08-31 20:50:59 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2022-09-05 00:47:52 +02:00
|
|
|
currentY = Height / 2.0f - 5.5f - 5.0f - maxP3;
|
2022-08-29 23:01:18 +02:00
|
|
|
break;
|
2022-08-31 20:50:59 +02:00
|
|
|
case 2:
|
2022-09-05 00:47:52 +02:00
|
|
|
currentY = Height / 2.0f - 5.5f - 5.0f - maxP3;
|
2022-08-29 23:01:18 +02:00
|
|
|
break;
|
2022-08-31 20:50:59 +02:00
|
|
|
case 3:
|
2022-09-05 00:47:52 +02:00
|
|
|
currentY = Height / 2.0f;
|
2022-08-29 23:01:18 +02:00
|
|
|
break;
|
|
|
|
default:
|
2022-08-31 20:50:59 +02:00
|
|
|
currentY = -10;
|
2022-08-29 23:01:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
float currentX;
|
|
|
|
if (i != 0) currentX = -Width / 2f - 2.25f / 2f + 2.25f;
|
|
|
|
else currentX = -Width / 2f + 5.5f - 2.25f / 2f + 2.25f + 1.75f;
|
2022-08-28 22:42:21 +02:00
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
bool flipped = false;
|
2022-08-28 22:42:21 +02:00
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
for (int j = 0; j < spotMap[i].Count; j++) {
|
2022-08-31 20:50:59 +02:00
|
|
|
spotMap[i][j].Flipped = flipped;
|
2022-09-05 01:15:04 +02:00
|
|
|
bool alignTop = i % 2 != 0;
|
2022-09-04 00:35:45 +02:00
|
|
|
switch (spotMap[i][j].Size) {
|
2022-08-31 20:50:59 +02:00
|
|
|
case Size.A:
|
2022-09-05 01:15:04 +02:00
|
|
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA, mainPlanContainer);
|
2022-08-31 20:50:59 +02:00
|
|
|
break;
|
|
|
|
case Size.B:
|
2022-09-05 01:15:04 +02:00
|
|
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabB, mainPlanContainer);
|
2022-08-31 20:50:59 +02:00
|
|
|
break;
|
|
|
|
case Size.C:
|
2022-09-05 01:15:04 +02:00
|
|
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabC, mainPlanContainer);
|
2022-08-31 20:50:59 +02:00
|
|
|
break;
|
2022-08-31 21:19:20 +02:00
|
|
|
case Size.D:
|
2022-09-05 01:15:04 +02:00
|
|
|
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabD, mainPlanContainer);
|
2022-08-31 21:19:20 +02:00
|
|
|
spotMap[i][j].GameObject.transform.position =
|
2022-09-05 00:47:52 +02:00
|
|
|
new Vector3(currentX, currentY, 0);
|
2022-08-31 21:19:20 +02:00
|
|
|
break;
|
2022-08-31 20:50:59 +02:00
|
|
|
}
|
2022-09-05 01:15:04 +02:00
|
|
|
|
2022-09-05 00:47:52 +02:00
|
|
|
spotMap[i][j].GameObject.transform.position =
|
2022-09-05 01:15:04 +02:00
|
|
|
new Vector3(currentX,
|
|
|
|
currentY + (alignTop ? -1 : 1) * spotSizes[(int) spotMap[i][j].Size] / 2.0f, 0);
|
2022-09-05 00:47:52 +02:00
|
|
|
|
2022-09-03 00:23:15 +02:00
|
|
|
|
2022-09-01 22:31:57 +02:00
|
|
|
spotMap[i][j].GameObject.transform.rotation =
|
|
|
|
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 0));
|
2022-08-31 20:50:59 +02:00
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
bool frontalParking = !parkingFromTop ^ flipped;
|
2022-09-03 00:23:15 +02:00
|
|
|
spotMap[i][j].ParkingDirection = frontalParking ? ParkingPreference.Front : ParkingPreference.Back;
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
currentX += 2.25f;
|
|
|
|
|
|
|
|
flipped = !flipped;
|
2022-08-28 22:42:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 01:15:04 +02:00
|
|
|
private void GenerateEmergencyPlan()
|
|
|
|
{
|
|
|
|
emergencyPlanContainer.gameObject.SetActive(false);
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
float currentY;
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
currentY = -Height / 2.0f;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
currentY = Height / 2.0f - 5.5f - 5.0f - 5.0f;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
currentY = Height / 2.0f - 5.5f - 5.0f - 5.0f;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
currentY = Height / 2.0f;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
currentY = -10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
float currentX;
|
|
|
|
if (i != 0) currentX = -Width / 2f - 2.25f / 2f + 2.25f;
|
|
|
|
else currentX = Width / 2f - 5.0f / 2f;
|
|
|
|
|
|
|
|
bool flipped = false;
|
|
|
|
|
|
|
|
GameObject spawnedSpot;
|
|
|
|
|
|
|
|
int[] emergencyMap = new[] {12, 27, 27, 20};
|
|
|
|
|
|
|
|
for (int j = 0; j < emergencyMap[i]; j++) {
|
|
|
|
|
|
|
|
if (i == 0) {
|
|
|
|
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;
|
|
|
|
Vector3 position = new Vector3(currentX, currentY, 0);
|
|
|
|
spawnedSpot = Instantiate(Instance.spotPrefabC, position,
|
|
|
|
Quaternion.Euler(new Vector3(0, 0, 0)), emergencyPlanContainer);
|
|
|
|
|
|
|
|
spawnedSpot.transform.position =
|
|
|
|
new Vector3(currentX,
|
|
|
|
currentY + (alignTop ? -1 : 1) * 5.0f / 2.0f,
|
|
|
|
0);
|
|
|
|
|
|
|
|
currentX += 2.25f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:50:59 +02:00
|
|
|
private List<List<Spot>> GenerateSpotMap(int[,] spotsCreated)
|
2022-08-28 22:42:21 +02:00
|
|
|
{
|
2022-09-05 01:15:04 +02:00
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
for (int j = 0; j < spotsCreated.GetLength(1); j++)
|
|
|
|
for (int k = 0; k < spotsCreated[i, j]; k++) {
|
2022-09-04 00:35:45 +02:00
|
|
|
_spotMap[i].Add(new Spot((Size) j, false));
|
|
|
|
_initialConfigurationSpotCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
_spotMap[0].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
|
|
|
|
_spotMap[1].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
|
|
|
|
_spotMap[2].Sort((a, b) => b.Size.CompareTo(a.Size)); // descending sort
|
|
|
|
_spotMap[3].Sort((a, b) => a.Size.CompareTo(b.Size)); // ascending sort
|
|
|
|
_spotMap[2].Add(new Spot(Size.D, false));
|
|
|
|
return _spotMap;
|
2022-08-28 22:42:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|