Added spot filling, other improvements

This commit is contained in:
Dawid Pietrykowski 2022-09-01 22:31:57 +02:00
parent 932b1391f6
commit 10ba11623d
15 changed files with 332 additions and 34 deletions

171
Assets/Prefabs/Car.prefab Normal file
View File

@ -0,0 +1,171 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &6930264686492252668
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6930264686492252671}
- component: {fileID: 6930264686492252670}
m_Layer: 0
m_Name: Circle
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6930264686492252671
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6930264686492252668}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.351, z: 0}
m_LocalScale: {x: 0.32, y: 0.16842106, z: 0.64}
m_ConstrainProportionsScale: 1
m_Children: []
m_Father: {fileID: 6930264687477137093}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &6930264686492252670
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6930264686492252668}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 1
m_Sprite: {fileID: -2413806693520163455, guid: a86470a33a6bf42c4b3595704624658b, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1, y: 1}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!1 &6930264687477137091
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6930264687477137093}
- component: {fileID: 6930264687477137090}
m_Layer: 0
m_Name: Car
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6930264687477137093
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6930264687477137091}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1.75, y: 3.8, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 6930264686492252671}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &6930264687477137090
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6930264687477137091}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 0
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 7482667652216324306, guid: 48e93eef0688c4a259cb0eddcd8661f7, type: 3}
m_Color: {r: 0, g: 0, b: 0, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 0.16, y: 0.16}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: e78fd5078b51c856ea96f94520af409b
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -109,8 +109,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 266166274}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: -0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 13560301962479320}
@ -193,8 +193,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 378070324}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: 0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 13560301962479320}

View File

@ -109,8 +109,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1130891335}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: -0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 13560301962479320}
@ -277,8 +277,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1413974509}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: 0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 13560301962479320}

View File

@ -25,8 +25,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5968983279822924556}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: -0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5973527577926520278}
@ -193,8 +193,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5968983280245206586}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: 0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 5973527577926520278}

View File

@ -25,8 +25,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 92791925}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: 0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 13560301962479320}
@ -109,8 +109,8 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 308329233}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.49, y: 0, z: 0}
m_LocalScale: {x: 0.02, y: 1, z: 1}
m_LocalPosition: {x: -0.47, y: 0, z: 0}
m_LocalScale: {x: 0.06, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 13560301962479320}

View File

@ -486,7 +486,7 @@ Camera:
m_TargetDisplay: 0
m_TargetEye: 0
m_HDR: 1
m_AllowMSAA: 0
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 0
@ -956,13 +956,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: af24978eff1b496b78bcc0aeccf046ed, type: 3}
m_Name:
m_EditorClassIdentifier:
stepTime: 15
stepTime: 1
timeText: {fileID: 861769593}
countsText: {fileID: 489742541}
spotPrefabA: {fileID: 13560301962479332, guid: 547c30e1f8f23f122968c9f6363ea48d, type: 3}
spotPrefabB: {fileID: 13560301962479332, guid: f665eba7844e816e8bbb45031230824f, type: 3}
spotPrefabC: {fileID: 13560301962479332, guid: a3f9da106063d979294b8c400bc015ce, type: 3}
spotPrefabD: {fileID: 13560302402692915}
carPrefab: {fileID: 6930264687477137091, guid: e78fd5078b51c856ea96f94520af409b, type: 3}
--- !u!1001 &1356388471
PrefabInstance:
m_ObjectHideFlags: 0

View File

@ -1,5 +1,9 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using UnityEngine;
namespace Parking
{
@ -46,7 +50,13 @@ namespace Parking
break;
}
Drivers.Add(new Driver(size, counter, preference));
DateTime realArrival = DateTime.Parse(lineData[4].Contains(':') ? lineData[4] : lineData[4] + ":00", CultureInfo.InvariantCulture);
DateTime realDeparture = DateTime.Parse(lineData[5].Contains(':') ? lineData[5] : lineData[5] + ":00", CultureInfo.InvariantCulture);
Driver driver = new Driver(size, counter, preference);
driver.Times = new[] {realArrival, realDeparture};
Drivers.Add(driver);
counter++;
}
}

View File

@ -9,6 +9,10 @@ namespace Parking
public ParkingPreference ParkingPreference = ParkingPreference.Any;
public int Priority;
public readonly Size Size;
public DateTime[] Times;
public Spot Spot;
public bool Parked = false;
public GameObject GameObject;
public Driver(Size size, int priority, ParkingPreference parkingPreference)
{
@ -23,6 +27,7 @@ namespace Parking
public Size Size;
public bool Flipped;
public GameObject GameObject;
public bool Free = true;
public Spot(Size size, bool flipped)
{

View File

@ -17,7 +17,7 @@ namespace Parking
var spotsCreated = new int[4, 4];
var count = 80;
var count = 98;
var maxCount = 0;
@ -112,7 +112,7 @@ namespace Parking
int[] requiredCountsRef, int[,] spotsCreated)
{
var sizes = sizeIds.Select(x => AvailableSizesCombinations[x]).ToArray();
Debug.Log($"Testing: {sizes[0]} {sizes[1]} {sizes[2]} {sizes[3]} sum: {sizes.Sum()}");
// Debug.Log($"Testing: {sizes[0]} {sizes[1]} {sizes[2]} {sizes[3]} sum: {sizes.Sum()}");
for (var i = 0; i < spotsCreated.GetLength(0); i++)
for (var j = 0; j < spotsCreated.GetLength(1); j++)

View File

@ -21,10 +21,11 @@ namespace Parking
[SerializeField] public GameObject spotPrefabB;
[SerializeField] public GameObject spotPrefabC;
[SerializeField] public GameObject spotPrefabD;
[SerializeField] public GameObject carPrefab;
private readonly float[] _spotHeights = {3.5f, 4f, 5f, 7.5f};
private TimeSpan _currentTime = TimeSpan.FromHours(8);
private TimeSpan _currentTime = TimeSpan.FromHours(5);
private void Awake()
{
@ -44,6 +45,39 @@ namespace Parking
{
_currentTime += TimeSpan.FromMinutes(15);
timeText.text = _currentTime.ToString();
foreach (Driver driver in DataImporter.Drivers)
{
if (_currentTime <= driver.Times[1].TimeOfDay && _currentTime > driver.Times[0].TimeOfDay && !driver.Parked)
{
PlaceCarOnParking(driver);
}else if (_currentTime > driver.Times[1].TimeOfDay && driver.Parked)
{
driver.Spot.Free = true;
driver.Parked = false;
driver.Spot = null;
Destroy(driver.GameObject);
}
}
}
private void PlaceCarOnParking(Driver driver)
{
for (int i = 0; i < SpotMap.Count; i++)
{
foreach (Spot spot in SpotMap[i])
{
if (spot.Size == driver.Size && spot.Free)
{
spot.Free = false;
driver.Spot = spot;
driver.Parked = true;
driver.GameObject = Instantiate(carPrefab, spot.GameObject.transform, true);
driver.GameObject.transform.position = spot.GameObject.transform.position;
return;
}
}
}
Debug.Log($"Placing failed for car {driver.Priority}");
}
public void UpdateText(string text)
@ -95,31 +129,25 @@ namespace Parking
case Size.A:
spotMap[i][j].GameObject = Instantiate(Instance.spotPrefabA);
spotMap[i][j].GameObject.transform.position = new Vector3(currentX, currentY, 0);
spotMap[i][j].GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 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);
spotMap[i][j].GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 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);
spotMap[i][j].GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 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);
spotMap[i][j].GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 0));
break;
}
spotMap[i][j].GameObject.transform.rotation =
Quaternion.Euler(new Vector3(0, 0, spotMap[i][j].Flipped ? 180 : 0));
currentX += 2.25f;

View File

@ -0,0 +1,16 @@
{
"MonoBehaviour": {
"Version": 4,
"EnableBurstCompilation": true,
"EnableOptimisations": true,
"EnableSafetyChecks": false,
"EnableDebugInAllBuilds": false,
"UsePlatformSDKLinker": false,
"CpuMinTargetX32": 0,
"CpuMaxTargetX32": 0,
"CpuMinTargetX64": 0,
"CpuMaxTargetX64": 0,
"CpuTargetsX64": 72,
"OptimizeFor": 0
}
}

View File

@ -0,0 +1,6 @@
{
"MonoBehaviour": {
"Version": 4,
"DisabledWarnings": ""
}
}

View File

@ -3,7 +3,7 @@
--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 13
serializedVersion: 14
m_Deferred:
m_Mode: 1
m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
@ -38,13 +38,65 @@ GraphicsSettings:
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_PreloadShadersBatchTimeLimit: -1
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_CustomRenderPipeline: {fileID: 0}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}
m_DefaultRenderingPath: 1
m_DefaultMobileRenderingPath: 1
m_TierSettings: []
m_TierSettings:
- serializedVersion: 5
m_BuildTarget: 1
m_Tier: 0
m_Settings:
standardShaderQuality: 2
renderingPath: 1
hdrMode: 1
realtimeGICPUUsage: 25
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
useHDR: 0
useDetailNormalMap: 1
useCascadedShadowMaps: 1
prefer32BitShadowMaps: 0
enableLPPV: 1
useDitherMaskForAlphaBlendedShadows: 1
m_Automatic: 0
- serializedVersion: 5
m_BuildTarget: 1
m_Tier: 1
m_Settings:
standardShaderQuality: 2
renderingPath: 1
hdrMode: 1
realtimeGICPUUsage: 25
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
useHDR: 0
useDetailNormalMap: 1
useCascadedShadowMaps: 1
prefer32BitShadowMaps: 0
enableLPPV: 1
useDitherMaskForAlphaBlendedShadows: 1
m_Automatic: 0
- serializedVersion: 5
m_BuildTarget: 1
m_Tier: 2
m_Settings:
standardShaderQuality: 2
renderingPath: 1
hdrMode: 1
realtimeGICPUUsage: 50
useReflectionProbeBoxProjection: 1
useReflectionProbeBlending: 1
useHDR: 0
useDetailNormalMap: 1
useCascadedShadowMaps: 1
prefer32BitShadowMaps: 0
enableLPPV: 1
useDitherMaskForAlphaBlendedShadows: 1
m_Automatic: 0
m_LightmapStripping: 0
m_FogStripping: 0
m_InstancingStripping: 0
@ -62,3 +114,4 @@ GraphicsSettings:
m_LightsUseColorTemperature: 0
m_DefaultRenderingLayerMask: 1
m_LogWhenShaderIsCompiled: 0
m_SRPDefaultSettings: {}

View File

@ -201,7 +201,7 @@ QualitySettings:
skinWeights: 255
textureQuality: 0
anisotropicTextures: 2
antiAliasing: 2
antiAliasing: 8
softParticles: 1
softVegetation: 1
realtimeReflectionProbes: 1
@ -224,12 +224,13 @@ QualitySettings:
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality:
Android: 2
Lumin: 5
GameCoreScarlett: 5
GameCoreXboxOne: 5
Lumin: 5
Nintendo Switch: 5
PS4: 5
PS5: 5
Server: 0
Stadia: 5
Standalone: 5
WebGL: 3