diff --git a/.gitignore b/.gitignore index e3e7782..ec1f2ee 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ Assets/Scripts/Buttons/SaveStructs.cs.meta Assets/Scripts/Buttons/LoadButton.cs.meta Assets/Scripts/Car/Roads.cs.meta +Assets/Scripts/Buttons/SaveTravelTimes.cs.meta diff --git a/.gitignore b/.gitignore index e3e7782..ec1f2ee 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ Assets/Scripts/Buttons/SaveStructs.cs.meta Assets/Scripts/Buttons/LoadButton.cs.meta Assets/Scripts/Car/Roads.cs.meta +Assets/Scripts/Buttons/SaveTravelTimes.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 224607c..196320b 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -233,8 +233,7 @@ carMesh: {fileID: -2432090755550338912, guid: 6358fc72c8f1a5645b372c8756ff9871, type: 3} carMaterial: {fileID: 2100000, guid: 55dd6bb7e89b75f4b9958b0b7bb7c5d2, type: 2} power: 1000 - totalTravelTime: 0 - totalCars: 0 + travelTimes: [] trafficLights: {fileID: 128843417} --- !u!4 &128843416 Transform: @@ -1247,6 +1246,7 @@ - {fileID: 555903563} - {fileID: 1812881468} - {fileID: 140411786} + - {fileID: 2082588825} m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1702,3 +1702,137 @@ m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1812881467} m_CullTransparentMesh: 1 +--- !u!1 &2082588824 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2082588825} + - component: {fileID: 2082588829} + - component: {fileID: 2082588828} + - component: {fileID: 2082588827} + - component: {fileID: 2082588826} + m_Layer: 5 + m_Name: SaveData + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2082588825 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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_Children: [] + m_Father: {fileID: 1044801290} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -36, y: -36} + m_SizeDelta: {x: 36, y: 36} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2082588826 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3b14b691754f5364fa5a86c30376663d, type: 3} + m_Name: + m_EditorClassIdentifier: + config: {fileID: 128843415} +--- !u!114 &2082588827 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, 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: 2082588828} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!114 &2082588828 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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: 21300000, guid: 346a409a36b61484f83749e8addb90b1, type: 3} + 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 &2082588829 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_CullTransparentMesh: 1 diff --git a/.gitignore b/.gitignore index e3e7782..ec1f2ee 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ Assets/Scripts/Buttons/SaveStructs.cs.meta Assets/Scripts/Buttons/LoadButton.cs.meta Assets/Scripts/Car/Roads.cs.meta +Assets/Scripts/Buttons/SaveTravelTimes.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 224607c..196320b 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -233,8 +233,7 @@ carMesh: {fileID: -2432090755550338912, guid: 6358fc72c8f1a5645b372c8756ff9871, type: 3} carMaterial: {fileID: 2100000, guid: 55dd6bb7e89b75f4b9958b0b7bb7c5d2, type: 2} power: 1000 - totalTravelTime: 0 - totalCars: 0 + travelTimes: [] trafficLights: {fileID: 128843417} --- !u!4 &128843416 Transform: @@ -1247,6 +1246,7 @@ - {fileID: 555903563} - {fileID: 1812881468} - {fileID: 140411786} + - {fileID: 2082588825} m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1702,3 +1702,137 @@ m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1812881467} m_CullTransparentMesh: 1 +--- !u!1 &2082588824 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2082588825} + - component: {fileID: 2082588829} + - component: {fileID: 2082588828} + - component: {fileID: 2082588827} + - component: {fileID: 2082588826} + m_Layer: 5 + m_Name: SaveData + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2082588825 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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_Children: [] + m_Father: {fileID: 1044801290} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -36, y: -36} + m_SizeDelta: {x: 36, y: 36} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2082588826 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3b14b691754f5364fa5a86c30376663d, type: 3} + m_Name: + m_EditorClassIdentifier: + config: {fileID: 128843415} +--- !u!114 &2082588827 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, 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: 2082588828} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!114 &2082588828 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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: 21300000, guid: 346a409a36b61484f83749e8addb90b1, type: 3} + 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 &2082588829 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_CullTransparentMesh: 1 diff --git a/Assets/Scripts/Buttons/SaveTravelTimes.cs b/Assets/Scripts/Buttons/SaveTravelTimes.cs new file mode 100644 index 0000000..ba81649 --- /dev/null +++ b/Assets/Scripts/Buttons/SaveTravelTimes.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; +using System; +using UnityEditor; +using System.IO; +using System.Text; + +public class SaveTravelTimes : MonoBehaviour, IPointerDownHandler { + public Config config; + + [Serializable] + private struct Times { + public List travelTimes; + } + + public void OnPointerDown(PointerEventData eventData) { + Times time = new Times(); + time.travelTimes = config.travelTimes; + string jsonData = JsonUtility.ToJson(time); + string filePath = EditorUtility.SaveFilePanel("Save travel times", "", + "times.json", "json"); + if (filePath.Length == 0) { + return; + } + File.WriteAllBytes(filePath, Encoding.ASCII.GetBytes(jsonData)); + } +} diff --git a/.gitignore b/.gitignore index e3e7782..ec1f2ee 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ Assets/Scripts/Buttons/SaveStructs.cs.meta Assets/Scripts/Buttons/LoadButton.cs.meta Assets/Scripts/Car/Roads.cs.meta +Assets/Scripts/Buttons/SaveTravelTimes.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 224607c..196320b 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -233,8 +233,7 @@ carMesh: {fileID: -2432090755550338912, guid: 6358fc72c8f1a5645b372c8756ff9871, type: 3} carMaterial: {fileID: 2100000, guid: 55dd6bb7e89b75f4b9958b0b7bb7c5d2, type: 2} power: 1000 - totalTravelTime: 0 - totalCars: 0 + travelTimes: [] trafficLights: {fileID: 128843417} --- !u!4 &128843416 Transform: @@ -1247,6 +1246,7 @@ - {fileID: 555903563} - {fileID: 1812881468} - {fileID: 140411786} + - {fileID: 2082588825} m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1702,3 +1702,137 @@ m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1812881467} m_CullTransparentMesh: 1 +--- !u!1 &2082588824 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2082588825} + - component: {fileID: 2082588829} + - component: {fileID: 2082588828} + - component: {fileID: 2082588827} + - component: {fileID: 2082588826} + m_Layer: 5 + m_Name: SaveData + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2082588825 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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_Children: [] + m_Father: {fileID: 1044801290} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -36, y: -36} + m_SizeDelta: {x: 36, y: 36} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2082588826 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3b14b691754f5364fa5a86c30376663d, type: 3} + m_Name: + m_EditorClassIdentifier: + config: {fileID: 128843415} +--- !u!114 &2082588827 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, 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: 2082588828} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!114 &2082588828 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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: 21300000, guid: 346a409a36b61484f83749e8addb90b1, type: 3} + 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 &2082588829 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_CullTransparentMesh: 1 diff --git a/Assets/Scripts/Buttons/SaveTravelTimes.cs b/Assets/Scripts/Buttons/SaveTravelTimes.cs new file mode 100644 index 0000000..ba81649 --- /dev/null +++ b/Assets/Scripts/Buttons/SaveTravelTimes.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; +using System; +using UnityEditor; +using System.IO; +using System.Text; + +public class SaveTravelTimes : MonoBehaviour, IPointerDownHandler { + public Config config; + + [Serializable] + private struct Times { + public List travelTimes; + } + + public void OnPointerDown(PointerEventData eventData) { + Times time = new Times(); + time.travelTimes = config.travelTimes; + string jsonData = JsonUtility.ToJson(time); + string filePath = EditorUtility.SaveFilePanel("Save travel times", "", + "times.json", "json"); + if (filePath.Length == 0) { + return; + } + File.WriteAllBytes(filePath, Encoding.ASCII.GetBytes(jsonData)); + } +} diff --git a/Assets/Scripts/Car/CarData.cs b/Assets/Scripts/Car/CarData.cs index 073b9bc..c58bfab 100644 --- a/Assets/Scripts/Car/CarData.cs +++ b/Assets/Scripts/Car/CarData.cs @@ -16,8 +16,7 @@ transform.position = car.position; transform.forward = car.direction; } else { - car.config.totalTravelTime += lifetime; - car.config.totalCars++; + car.config.travelTimes.Add(lifetime); } } diff --git a/.gitignore b/.gitignore index e3e7782..ec1f2ee 100644 --- a/.gitignore +++ b/.gitignore @@ -87,3 +87,4 @@ Assets/Scripts/Buttons/SaveStructs.cs.meta Assets/Scripts/Buttons/LoadButton.cs.meta Assets/Scripts/Car/Roads.cs.meta +Assets/Scripts/Buttons/SaveTravelTimes.cs.meta diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 224607c..196320b 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -233,8 +233,7 @@ carMesh: {fileID: -2432090755550338912, guid: 6358fc72c8f1a5645b372c8756ff9871, type: 3} carMaterial: {fileID: 2100000, guid: 55dd6bb7e89b75f4b9958b0b7bb7c5d2, type: 2} power: 1000 - totalTravelTime: 0 - totalCars: 0 + travelTimes: [] trafficLights: {fileID: 128843417} --- !u!4 &128843416 Transform: @@ -1247,6 +1246,7 @@ - {fileID: 555903563} - {fileID: 1812881468} - {fileID: 140411786} + - {fileID: 2082588825} m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -1702,3 +1702,137 @@ m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1812881467} m_CullTransparentMesh: 1 +--- !u!1 &2082588824 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2082588825} + - component: {fileID: 2082588829} + - component: {fileID: 2082588828} + - component: {fileID: 2082588827} + - component: {fileID: 2082588826} + m_Layer: 5 + m_Name: SaveData + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2082588825 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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_Children: [] + m_Father: {fileID: 1044801290} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 1, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: -36, y: -36} + m_SizeDelta: {x: 36, y: 36} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2082588826 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3b14b691754f5364fa5a86c30376663d, type: 3} + m_Name: + m_EditorClassIdentifier: + config: {fileID: 128843415} +--- !u!114 &2082588827 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, 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: 2082588828} + m_OnClick: + m_PersistentCalls: + m_Calls: [] +--- !u!114 &2082588828 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + 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: 21300000, guid: 346a409a36b61484f83749e8addb90b1, type: 3} + 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 &2082588829 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2082588824} + m_CullTransparentMesh: 1 diff --git a/Assets/Scripts/Buttons/SaveTravelTimes.cs b/Assets/Scripts/Buttons/SaveTravelTimes.cs new file mode 100644 index 0000000..ba81649 --- /dev/null +++ b/Assets/Scripts/Buttons/SaveTravelTimes.cs @@ -0,0 +1,29 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; +using System; +using UnityEditor; +using System.IO; +using System.Text; + +public class SaveTravelTimes : MonoBehaviour, IPointerDownHandler { + public Config config; + + [Serializable] + private struct Times { + public List travelTimes; + } + + public void OnPointerDown(PointerEventData eventData) { + Times time = new Times(); + time.travelTimes = config.travelTimes; + string jsonData = JsonUtility.ToJson(time); + string filePath = EditorUtility.SaveFilePanel("Save travel times", "", + "times.json", "json"); + if (filePath.Length == 0) { + return; + } + File.WriteAllBytes(filePath, Encoding.ASCII.GetBytes(jsonData)); + } +} diff --git a/Assets/Scripts/Car/CarData.cs b/Assets/Scripts/Car/CarData.cs index 073b9bc..c58bfab 100644 --- a/Assets/Scripts/Car/CarData.cs +++ b/Assets/Scripts/Car/CarData.cs @@ -16,8 +16,7 @@ transform.position = car.position; transform.forward = car.direction; } else { - car.config.totalTravelTime += lifetime; - car.config.totalCars++; + car.config.travelTimes.Add(lifetime); } } diff --git a/Assets/Scripts/Config.cs b/Assets/Scripts/Config.cs index f764b52..e67af91 100644 --- a/Assets/Scripts/Config.cs +++ b/Assets/Scripts/Config.cs @@ -11,8 +11,7 @@ public Mesh carMesh; public Material carMaterial; public float power = 100000f; - public float totalTravelTime = 0f; - public int totalCars = 0; + public List travelTimes = new List(); public RoadNetwork roadNetwork = new RoadNetwork(); public TrafficLights trafficLights;