diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 9b104da..6defdd5 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -140,7 +140,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &44030830 RectTransform: m_ObjectHideFlags: 0 @@ -157,7 +157,7 @@ RectTransform: - {fileID: 369720528} - {fileID: 70943246} m_Father: {fileID: 107864146} - m_RootOrder: 4 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -429,8 +429,7 @@ RectTransform: m_LocalScale: {x: 0, y: 0, z: 0} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 1365705406} - - {fileID: 799530712} + - {fileID: 1347097429} - {fileID: 489742540} - {fileID: 1540189690} - {fileID: 44030830} @@ -677,6 +676,105 @@ Transform: m_CorrespondingSourceObject: {fileID: 13560301962479320, guid: dbfe1689c60c23f129ff74156ff8e6a8, type: 3} m_PrefabInstance: {fileID: 440632606} m_PrefabAsset: {fileID: 0} +--- !u!1 &441283503 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 441283504} + - component: {fileID: 441283505} + m_Layer: 5 + m_Name: Reconfiguration toggle + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &441283504 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 441283503} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 719677295} + - {fileID: 1040615156} + m_Father: {fileID: 1347097429} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 250, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &441283505 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 441283503} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9085046f02f69544eb97fd06b6048fe2, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 719677296} + toggleTransition: 1 + graphic: {fileID: 1690960237} + m_Group: {fileID: 0} + onValueChanged: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1300650500} + m_TargetAssemblyTypeName: Parking.ParkingManager, Assembly-CSharp + m_MethodName: ReconfigurationToggle + m_Mode: 6 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_IsOn: 1 --- !u!1 &489742539 GameObject: m_ObjectHideFlags: 0 @@ -708,7 +806,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 107864146} - m_RootOrder: 2 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -1176,6 +1274,83 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &719677294 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 719677295} + - component: {fileID: 719677297} + - component: {fileID: 719677296} + m_Layer: 5 + m_Name: Background + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &719677295 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 719677294} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 1690960236} + m_Father: {fileID: 441283504} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 10, y: -10} + m_SizeDelta: {x: 20, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &719677296 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 719677294} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &719677297 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 719677294} + m_CullTransparentMesh: 1 --- !u!1 &762547645 GameObject: m_ObjectHideFlags: 0 @@ -1337,20 +1512,19 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 799530711} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 820792684} - - {fileID: 861769592} - m_Father: {fileID: 107864146} - m_RootOrder: 1 + m_Father: {fileID: 1347097429} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -300, y: -261.92} - m_SizeDelta: {x: 239.464, y: 69.846} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 250, y: 60} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &799530713 MonoBehaviour: @@ -1611,13 +1785,13 @@ RectTransform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 799530712} + m_Father: {fileID: 1347097429} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 293.212, y: 0} - m_SizeDelta: {x: 254.411, y: 69.844} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 250, y: 60} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &861769593 MonoBehaviour: @@ -1856,6 +2030,86 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 934996861} m_CullTransparentMesh: 1 +--- !u!1 &1040615155 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1040615156} + - component: {fileID: 1040615158} + - component: {fileID: 1040615157} + m_Layer: 5 + m_Name: Label + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1040615156 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1040615155} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 441283504} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 9, y: -0.5} + m_SizeDelta: {x: -28, y: -3} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1040615157 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1040615155} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_FontData: + m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + m_FontSize: 14 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 10 + m_MaxSize: 40 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: Rekonfiguracja aktywna +--- !u!222 &1040615158 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1040615155} + m_CullTransparentMesh: 1 --- !u!1 &1079236959 GameObject: m_ObjectHideFlags: 0 @@ -2503,6 +2757,75 @@ MonoBehaviour: carPrefab: {fileID: 6930264687477137091, guid: e78fd5078b51c856ea96f94520af409b, type: 3} mainPlanContainer: {fileID: 557435656} emergencyPlanContainer: {fileID: 632826360} + reconfigurationToggle: {fileID: 441283505} + defaultPath: Assets/Data/Tablica1.csv +--- !u!1 &1347097428 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1347097429} + - component: {fileID: 1347097430} + m_Layer: 5 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1347097429 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1347097428} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 799530712} + - {fileID: 861769592} + - {fileID: 1365705406} + - {fileID: 441283504} + m_Father: {fileID: 107864146} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: -261.92} + m_SizeDelta: {x: 1300, y: 90} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1347097430 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1347097428} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 30649d3a9faa99c48a7b1166b86bf2a0, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Padding: + m_Left: 0 + m_Right: 0 + m_Top: 0 + m_Bottom: 0 + m_ChildAlignment: 4 + m_Spacing: 0 + m_ChildForceExpandWidth: 1 + m_ChildForceExpandHeight: 1 + m_ChildControlWidth: 0 + m_ChildControlHeight: 0 + m_ChildScaleWidth: 0 + m_ChildScaleHeight: 0 + m_ReverseArrangement: 0 --- !u!1001 &1356388471 PrefabInstance: m_ObjectHideFlags: 0 @@ -2591,19 +2914,19 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1365705405} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1092905955} - m_Father: {fileID: 107864146} - m_RootOrder: 0 + m_Father: {fileID: 1347097429} + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0.5, y: 0.5} - m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 300, y: -261.92} - m_SizeDelta: {x: 239.464, y: 69.846} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 0, y: 0} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 250, y: 60} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1365705407 MonoBehaviour: @@ -2882,7 +3205,7 @@ RectTransform: m_Children: - {fileID: 762547646} m_Father: {fileID: 107864146} - m_RootOrder: 3 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} @@ -3083,6 +3406,82 @@ Transform: m_CorrespondingSourceObject: {fileID: 13560301962479320, guid: 547c30e1f8f23f122968c9f6363ea48d, type: 3} m_PrefabInstance: {fileID: 1623836583} m_PrefabAsset: {fileID: 0} +--- !u!1 &1690960235 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1690960236} + - component: {fileID: 1690960238} + - component: {fileID: 1690960237} + m_Layer: 5 + m_Name: Checkmark + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1690960236 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1690960235} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 719677295} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 20, y: 20} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1690960237 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1690960235} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1690960238 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1690960235} + m_CullTransparentMesh: 1 --- !u!1 &1728782014 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Driver.cs b/Assets/Scripts/Driver.cs index c25ccc7..4b8446b 100644 --- a/Assets/Scripts/Driver.cs +++ b/Assets/Scripts/Driver.cs @@ -50,6 +50,7 @@ namespace Parking public bool Reserved = false; public int ReservedPriority = 0; public Size Size; + public TimeSpan LastReconfiguration = TimeSpan.Zero; public Spot(Size size, bool flipped) { diff --git a/Assets/Scripts/ParkingManager.cs b/Assets/Scripts/ParkingManager.cs index 594c626..6c1059d 100644 --- a/Assets/Scripts/ParkingManager.cs +++ b/Assets/Scripts/ParkingManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; +using UnityEngine.UI; namespace Parking { @@ -31,6 +32,8 @@ namespace Parking [SerializeField] public GameObject carPrefab; [SerializeField] public Transform mainPlanContainer; [SerializeField] public Transform emergencyPlanContainer; + [SerializeField] public Toggle reconfigurationToggle; + [SerializeField] public string defaultPath = "Assets/Data/Tablica2.csv"; private readonly float[] _spotHeights = {4f, 4.5f, 5f, 7.5f}; @@ -38,6 +41,7 @@ namespace Parking {new List(), new List(), new List(), new List()}; private bool _emergencyActivated; + private bool _reconfigurationActive = true; private int _initialConfigurationSpotCount; private int[,] _initialSolution; @@ -52,15 +56,26 @@ namespace Parking private void Start() { _spotPrefabs = new List {spotPrefabA, spotPrefabB, spotPrefabC, spotPrefabD}; + startPanel.SetActive(true); + reconfigurationToggle.onValueChanged.AddListener(ReconfigurationToggle); + } + public void ReconfigurationToggle(bool value) + { + _reconfigurationActive = value; + Debug.Log($"Reconfiguration {(value ? "activated" : "deactivated")}"); } public void ReadDataButtonClick() { - if (!DataImporter.ReadFile(pathText.text.Replace("\u200B", ""))) { + string path = pathText.text.Replace("\u200B", ""); + if (path.Length == 0) + path = defaultPath; + if (!DataImporter.ReadFile(path)) { notFoundPanel.SetActive(true); return; } + InitiateManager(); startPanel.SetActive(false); } @@ -134,7 +149,8 @@ namespace Parking if (_emergencyActivated) return; - ReconfigureSpots(); + if(_reconfigurationActive) + ReconfigureSpots(); foreach (Driver driver in DataImporter.Drivers) { // TODO: Check if car can stay before other reservation - may not work for priority-based reservations @@ -147,7 +163,7 @@ namespace Parking && !driver.Parked && !driver.Rejected && _currentTime <= driver.Times[3].TimeOfDay; if (triesToPark && !driver.Parked && !driver.Rejected) { if (!PlaceCarOnParking(driver)) { - if (TryReconfigureSpotForSize(driver.Size)) { + if (_reconfigurationActive && TryReconfigureSpotForSize(driver.Size)) { if (!PlaceCarOnParking(driver)) { Debug.Log($"Placing failed for car {driver.Number} size {driver.Size}"); driver.Rejected = true; @@ -174,7 +190,7 @@ namespace Parking driver.Rejected = true; } } - + UpdateCounts(); } @@ -206,7 +222,7 @@ namespace Parking private int GetReservedSpotCount(int priority, Size size) { int count = 0; - foreach (var list in _spotMap) + foreach (List list in _spotMap) foreach (Spot spot in list) if (spot.Size == size && spot.Reserved && spot.ReservedPriority == priority) count++; @@ -216,7 +232,7 @@ namespace Parking private bool FindReservedSpot(Driver driver, out Spot spot) { - foreach (var list in _spotMap) + foreach (List list in _spotMap) foreach (Spot spot1 in list) if (spot1.Reserved && spot1.ReservedPriority == driver.Priority) { spot = spot1; @@ -240,7 +256,7 @@ namespace Parking } - foreach (var t in _spotMap) + foreach (List t in _spotMap) foreach (Spot spot in t) { bool spotAvailable = spot.Size == driver.Size && spot.Free && (spot.ParkingDirection == driver.ParkingPreference || @@ -253,7 +269,7 @@ namespace Parking } } - foreach (var t in _spotMap) + foreach (List t in _spotMap) foreach (Spot spot in t) if (spot.Size == driver.Size && spot.Free && !spot.Reserved) { PlaceDriverOnSpot(driver, spot); @@ -288,7 +304,7 @@ namespace Parking private void ReconfigureSpots() { int[] freeSpots = GetFreeSpotCount(); - var nextCars = GetNextCars(1); + List nextCars = GetNextCars(1); int[] plannedSpots = {0, 0, 0, 0}; foreach (Driver driver in nextCars) plannedSpots[(int) driver.Size]++; @@ -301,7 +317,7 @@ namespace Parking Debug.Log($"Needed spots = {neededSpots[0]} {neededSpots[1]} {neededSpots[2]} {neededSpots[3]}"); Debug.Log("Attempting reconfiguration..."); - var spotlessCars = new List(); + List spotlessCars = new List(); // Filter drivers by assigning free space foreach (Driver nextCar in nextCars) @@ -311,21 +327,24 @@ namespace Parking spotlessCars.Add(nextCar); - foreach (Driver nextCar in spotlessCars) { + foreach (Driver nextCar in spotlessCars) TryReconfigureSpotForSize(nextCar.Size); - } } } private bool TryReconfigureSpotForSize(Size newSize) { - foreach (var currentLaneSpots in _spotMap) + foreach (List currentLaneSpots in _spotMap) foreach (Spot spot in currentLaneSpots) { - if (spot.Size > newSize && spot.Free && spot.Size != Size.D && !spot.Reserved) { - if (GetSpotCountOfSize(Size.A) <= 2 && spot.Size == Size.A) - continue; - if (GetSpotCountOfSize(Size.B) <= 2 && spot.Size == Size.B) - continue; + if (!(spot.Free && spot.Size != Size.D)) // && !spot.Reserved)) + continue; + if (GetSpotCountOfSize(Size.A) <= 2 && spot.Size == Size.A) + continue; + if (GetSpotCountOfSize(Size.B) <= 2 && spot.Size == Size.B) + continue; + if (spot.LastReconfiguration == _currentTime) + continue; + if (spot.Size > newSize) { int size = (int) newSize; @@ -349,43 +368,146 @@ namespace Parking Vector3 newPosition = position + offset; if (!spot.Perpendicular) { - var allBorders = new List(); - foreach (Spot spot1 in currentLaneSpots) { - if (spot1 == spot) - continue; - Vector3 spotPosition = spot1.GameObject.transform.position; - float sizeOffset = _spotHeights[(int) spot1.Size] / 2.0f; - allBorders.Add(spotPosition.x + sizeOffset); - allBorders.Add(spotPosition.x - sizeOffset); + float newX = GetNextBorderHorizontal(position, spot, true) - + _spotHeights[(int) spot.Size] / 2.0f; + newPosition = new Vector3(newX, + newPosition.y, newPosition.z); + } + else { + float newX = GetNextBorderHorizontal(position, spot, true) - 2.25f / 2.0f; + if (spot.Lane == 0) { + float xRelativeToRight = newX - Width / 2.0f - 2.25f / 2.0f; + xRelativeToRight -= (xRelativeToRight + 2.25f / 2.0f) % 2.25f; + newX = xRelativeToRight + Width / 2.0f; + } + else { + float xRelativeToLeft = newX + Width / 2.0f; + xRelativeToLeft -= (xRelativeToLeft + 2.25f / 2.0f) % 2.25f; + newX = xRelativeToLeft - Width / 2.0f; } - allBorders.Sort(); - foreach (float adjacentBorder in allBorders) - if (adjacentBorder > position.x) { - newPosition = new Vector3(adjacentBorder - - _spotHeights[size] / 2.0f, - newPosition.y, newPosition.z); - break; - } + newPosition = new Vector3(newX, + newPosition.y, newPosition.z); } - // TODO: check how much space to right to push - spot.GameObject = Instantiate(_spotPrefabs[size], newPosition, rotation, mainPlanContainer); + spot.LastReconfiguration = _currentTime; + return true; + } + + if (spot.Size < newSize) { + if (!spot.Perpendicular) + continue; + int size = (int) newSize; + float diff = (_spotHeights[(int) spot.Size] - _spotHeights[size]) / 2.0f; + + + Vector3 position = spot.GameObject.transform.position; + float spotBorder; + float thisSizeOffset; + if (spot.Perpendicular) + thisSizeOffset = _spotHeights[(int) spot.Size] / 2.0f; + else + thisSizeOffset = 2.25f; + if (!spot.AlignToTop) + spotBorder = position.y + thisSizeOffset; + else + spotBorder = position.y - thisSizeOffset; + float nextBorder = GetNextBorderVectical(position, spot.Lane, spot.Perpendicular, newSize, !spot.AlignToTop); + if (Math.Abs(spotBorder - nextBorder) < 5.5f) + continue; + + spot.Size = (Size) size; + Quaternion rotation = Quaternion.identity; + if (spot.GameObject != null) { + position = spot.GameObject.transform.position; + rotation = spot.GameObject.transform.rotation; + Destroy(spot.GameObject); + } + + spot.Reserved = false; + if (!spot.AlignToTop) + diff *= -1; + + Vector3 offset = spot.Perpendicular ? new Vector3(0, diff, 0) : new Vector3(-diff, 0, 0); + Vector3 newPosition = position + offset; + + + + spot.GameObject = Instantiate(_spotPrefabs[size], + newPosition, rotation, mainPlanContainer); + spot.LastReconfiguration = _currentTime; return true; } } return false; } - - + + private float GetNextBorderVectical(Vector3 position, int lane, bool perpendicular, Size size, bool up) + { + + float minX = position.x - (perpendicular ? 2.25f : _spotHeights[(int) size]); + float maxX = position.x + (perpendicular ? 2.25f : _spotHeights[(int) size]); + + List allBorders = new(); + List targetLane = up ? _spotMap[lane + 1] : _spotMap[lane - 1]; + + foreach (Spot spot1 in targetLane) { + Vector3 targetSpotPosition = spot1.GameObject.transform.position; + if (targetSpotPosition.x < minX || targetSpotPosition.x > maxX) + continue; + float sizeOffset; + if (spot1.Perpendicular) + sizeOffset = _spotHeights[(int) spot1.Size] / 2.0f; + else + sizeOffset = 2.25f; + if (up) + allBorders.Add(targetSpotPosition.y - sizeOffset); + else + allBorders.Add(targetSpotPosition.y + sizeOffset); + } + + if (allBorders.Count == 0) + return up ? Height / 2.0f : -Height / 2.0f; + float nextBorder = up ? allBorders.Min() : allBorders.Max(); + return nextBorder; + } + + private float GetNextBorderHorizontal(Vector3 position, Spot spot, bool right) + { + List allBorders = new List(); + List targetLane = _spotMap[spot.Lane]; + foreach (Spot spot1 in targetLane) { + if (spot1 == spot) + continue; + Vector3 spotPosition = spot1.GameObject.transform.position; + float sizeOffset; + if (spot1.Perpendicular) + sizeOffset = 2.25f / 2.0f; + else + sizeOffset = _spotHeights[(int) spot1.Size] / 2.0f; + allBorders.Add(spotPosition.x + sizeOffset); + allBorders.Add(spotPosition.x - sizeOffset); + } + + allBorders.Sort(); + foreach (float adjacentBorder in allBorders) + if (adjacentBorder > position.x) + return adjacentBorder; + + if (spot.Perpendicular) + return position.x + (right ? 1 : -1) * _spotHeights[(int) spot.Size] / 2.0f; + return position.x + (right ? 1 : -1) * 2.25f / 2.0f; + } + + private int GetSpotCountOfSize(Size size) { int count = 0; - foreach (var t in _spotMap) + foreach (List t in _spotMap) foreach (Spot spot in t) if (spot.Size == size) count++; @@ -395,7 +517,7 @@ namespace Parking private int[] GetFreeSpotCount() { int[] freeSpots = {0, 0, 0, 0}; - foreach (var t in _spotMap) + foreach (List t in _spotMap) foreach (Spot spot in t) if (spot.Free) freeSpots[(int) spot.Size]++; @@ -404,7 +526,7 @@ namespace Parking private List GetNextCars(int steps) { - var nextCars = new List(); + List nextCars = new List(); TimeSpan updatedTime = _currentTime + TimeSpan.FromMinutes(stepTime * steps); foreach (Driver driver in DataImporter.Drivers) if (updatedTime <= driver.Times[1].TimeOfDay && @@ -417,7 +539,7 @@ namespace Parking private void ArrangeSpots(int[,] spotsCreated) { - var spotMap = GenerateSpotMap(spotsCreated); + List> spotMap = GenerateSpotMap(spotsCreated); float[] spotSizes = {4, 4.5f, 5, 0}; float maxP3 = 0; @@ -431,7 +553,7 @@ namespace Parking // 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]; - var prefabs = new List {spotPrefabA, spotPrefabB, spotPrefabC, spotPrefabD}; + List prefabs = new List {spotPrefabA, spotPrefabB, spotPrefabC, spotPrefabD}; for (int i = 0; i < 4; i++) { float currentY; @@ -566,7 +688,7 @@ namespace Parking private List> GenerateSpotMap(int[,] spotsCreated) { - foreach (var list in _spotMap) { + foreach (List list in _spotMap) { foreach (Spot spot in list) if (spot.GameObject != null) Destroy(spot.GameObject);