From 69a97e3c760bbc2bc0f6741a703baff9c7ee0e19 Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 1 Aug 2023 22:30:20 +1000 Subject: [PATCH] recent lap --- Assets/Scenes/testTrack/TestTrack.unity | 34 +++++++++++++++++++++++-- Assets/Src/Timing.cs | 27 +++++++++++++++++--- Assets/Src/UI/Crosshair.uxml | 2 +- Assets/Src/UI/Timing.uxml | 6 ++--- Assets/Src/UI/TimingUI.cs | 21 +++++++-------- Assets/Src/UI/TimingUi.uss | 20 +-------------- 6 files changed, 71 insertions(+), 39 deletions(-) diff --git a/Assets/Scenes/testTrack/TestTrack.unity b/Assets/Scenes/testTrack/TestTrack.unity index 903d5d0..54f15ca 100644 --- a/Assets/Scenes/testTrack/TestTrack.unity +++ b/Assets/Scenes/testTrack/TestTrack.unity @@ -474,7 +474,7 @@ PrefabInstance: - target: {fileID: 5313449993149091347, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} propertyPath: shipControls value: - objectReference: {fileID: 0} + objectReference: {fileID: 699883395} - target: {fileID: 9074617566735061565, guid: ebed5434f18ca13e38d2d7bfcc18d6c3, type: 3} propertyPath: m_RootOrder value: 4 @@ -656,6 +656,17 @@ Transform: m_CorrespondingSourceObject: {fileID: 7588376663361902483, guid: 73ab56de058af21389c312279181f856, type: 3} m_PrefabInstance: {fileID: 679062965} m_PrefabAsset: {fileID: 0} +--- !u!114 &699883395 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 1093091269199902593, guid: 217f9c8f922f2d41cac52c3699bde478, type: 3} + m_PrefabInstance: {fileID: 702758806} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 40716ff800be8d74ead775a18a496d89, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &702758806 PrefabInstance: m_ObjectHideFlags: 0 @@ -664,6 +675,10 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 1093091269199902593, guid: 217f9c8f922f2d41cac52c3699bde478, type: 3} + propertyPath: timing + value: + objectReference: {fileID: 1643546426} - target: {fileID: 3589635702276405719, guid: 217f9c8f922f2d41cac52c3699bde478, type: 3} propertyPath: m_RootOrder value: 5 @@ -1253,6 +1268,17 @@ Transform: m_CorrespondingSourceObject: {fileID: 7588376663361902483, guid: 73ab56de058af21389c312279181f856, type: 3} m_PrefabInstance: {fileID: 1549479480} m_PrefabAsset: {fileID: 0} +--- !u!114 &1643546426 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 8438506523596255020, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + m_PrefabInstance: {fileID: 6345872851367721384} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 385acf04d40a396a9a95f738b7353198, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1799749852 PrefabInstance: m_ObjectHideFlags: 0 @@ -1950,11 +1976,15 @@ PrefabInstance: - target: {fileID: 5975136821837370545, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} propertyPath: ship value: - objectReference: {fileID: 0} + objectReference: {fileID: 699883395} - target: {fileID: 5975136821837370545, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} propertyPath: m_Enabled value: 1 objectReference: {fileID: 0} + - target: {fileID: 8438506523596255020, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} + propertyPath: ui + value: + objectReference: {fileID: 1292078235} - target: {fileID: 8438506523596255020, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3} propertyPath: sectors.Array.size value: 2 diff --git a/Assets/Src/Timing.cs b/Assets/Src/Timing.cs index 38e2e87..5437cb7 100644 --- a/Assets/Src/Timing.cs +++ b/Assets/Src/Timing.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Linq; @@ -9,6 +10,9 @@ using UnityEditor; using UnityEngine.SceneManagement; public class Timing: MonoBehaviour { + [SerializeField] + TimingUI ui; + public List sectorTimes; public bool timerEnabled; @@ -16,7 +20,7 @@ public class Timing: MonoBehaviour { public double sectorTime; public double lapTime; public Sector[] sectors; - public LapJSON recentLap; + public Lap recentLap = null; double sectorStart; double lapStart; @@ -33,6 +37,7 @@ public class Timing: MonoBehaviour { Debug.Log("Track Sector Count - " + sectors.Length); LapStorageService.GetPlayerLaps(mapName); + recentLap = null; } void Update() { @@ -107,7 +112,19 @@ public class Timing: MonoBehaviour { Debug.Log($"Ending lap Sectors={sectorTimes.Count} Name={mapName}"); Lap l = new Lap { Map = mapName, Sectors = sectorTimes }; Debug.Log($"EndLap {l}"); + LapStorageService.PersistLap(l); + StartCoroutine(RecentLapLifecycle(l)); + } + + IEnumerator RecentLapLifecycle(Lap l) { + ui.ShowRecentLap(l); + yield return new WaitForSeconds(3); + ui.HideRecentLap(); + } + + public Lap PB() { + return LapStorageService.PB(mapName); } public double PBSectorDiff(SectorTime s) => PB() switch { @@ -118,8 +135,10 @@ public class Timing: MonoBehaviour { null => -1d, }; - public Lap PB() { - return LapStorageService.PB(mapName); - } + public double PBLapDiff(Lap lap) => PB() switch { + Lap pb => lap.TotalTime() - pb.TotalTime(), + null => -1d, + }; + } diff --git a/Assets/Src/UI/Crosshair.uxml b/Assets/Src/UI/Crosshair.uxml index df41da6..7a16ff2 100644 --- a/Assets/Src/UI/Crosshair.uxml +++ b/Assets/Src/UI/Crosshair.uxml @@ -1,6 +1,6 @@