fix all kinds of timer problems
This commit is contained in:
1 parent
d424edf9be
commit
437db96756
5 files changed
+62
-22
No files matched your search
@@ -2187,6 +2187,10 @@ PrefabInstance:
|
|||||||
propertyPath: m_Name
|
propertyPath: m_Name
|
||||||
value: Timing
|
value: Timing
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3132636987330744835, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
||||||
|
propertyPath: m_IsActive
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 4743817676494260426, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
- target: {fileID: 4743817676494260426, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
||||||
propertyPath: m_RootOrder
|
propertyPath: m_RootOrder
|
||||||
value: 4
|
value: 4
|
||||||
@@ -2231,10 +2235,18 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 5878833558283183865, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
||||||
|
propertyPath: m_Enabled
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 5975136821837370545, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
- target: {fileID: 5975136821837370545, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
||||||
propertyPath: ship
|
propertyPath: ship
|
||||||
value:
|
value:
|
||||||
objectReference: {fileID: 1972710421}
|
objectReference: {fileID: 1972710421}
|
||||||
|
- target: {fileID: 5975136821837370545, guid: dcb64e3a91f1fec7ab6098f4f407830b, type: 3}
|
||||||
|
propertyPath: m_Enabled
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents: []
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
m_AddedGameObjects: []
|
m_AddedGameObjects: []
|
||||||
|
|||||||
+21
-8
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UIElements;
|
using UnityEngine.UIElements;
|
||||||
@@ -16,24 +17,28 @@ public class ShipUi : MonoBehaviour {
|
|||||||
|
|
||||||
Label speed;
|
Label speed;
|
||||||
Label timer;
|
Label timer;
|
||||||
Label sectors;
|
VisualElement sectors;
|
||||||
VisualElement timeSheet;
|
VisualElement timeSheet;
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
||||||
timer = uiDocument.rootVisualElement.Q<Label>("timer");
|
timer = uiDocument.rootVisualElement.Q<Label>("timer");
|
||||||
sectors = uiDocument.rootVisualElement.Q<Label>("sectors");
|
sectors = uiDocument.rootVisualElement.Q<VisualElement>("sectors");
|
||||||
timeSheet = uiDocument.rootVisualElement.Q<VisualElement>("timeSheet");
|
timeSheet = uiDocument.rootVisualElement.Q<VisualElement>("timeSheet");
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate() {
|
void FixedUpdate() {
|
||||||
timer.text = $"{timing.sectorTime:0.0}";
|
timer.text = $"{timing.lapTime:0.0}";
|
||||||
speed.text = $"{ship.Speed():0}";
|
speed.text = $"{ship.Speed():0} u/s";
|
||||||
|
|
||||||
|
// clearly this is not ideal but idk atm
|
||||||
UpdateTimesheet();
|
UpdateTimesheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateTimesheet() {
|
public void UpdateTimesheet() {
|
||||||
|
if (sectors == null)
|
||||||
|
Debug.LogWarning("null sectors");
|
||||||
|
|
||||||
timeSheet.Clear();
|
timeSheet.Clear();
|
||||||
foreach (Lap lap in timing.lapTimes) {
|
foreach (Lap lap in timing.lapTimes) {
|
||||||
Label l = new Label();
|
Label l = new Label();
|
||||||
@@ -41,10 +46,18 @@ public class ShipUi : MonoBehaviour {
|
|||||||
timeSheet.Add(l);
|
timeSheet.Add(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (SectorTime sector in timing.sectorTimes) {
|
sectors.Clear();
|
||||||
Label l = new Label();
|
foreach (Sector sector in timing.sectors) {
|
||||||
l.text = $"{sector}";
|
Label l = timing.sectorTimes
|
||||||
l.AddToClassList(sector.ColourClass());
|
.Where(s => s.Sector == sector.sector)
|
||||||
|
.Select(s => {
|
||||||
|
Label l = new Label($"{s}");
|
||||||
|
l.AddToClassList(s.ColourClass());
|
||||||
|
return l;
|
||||||
|
})
|
||||||
|
.DefaultIfEmpty(new Label("-"))
|
||||||
|
.Single();
|
||||||
|
|
||||||
sectors.Add(l);
|
sectors.Add(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
--red: rgb(165, 42, 42);
|
--red: rgb(165, 42, 42);
|
||||||
--blue: rgb(48, 80, 248);
|
--blue: rgb(48, 80, 248);
|
||||||
--purple: rgb(164, 35, 188);
|
--purple: rgb(164, 35, 188);
|
||||||
--yellow: #ffa100;
|
--yellow: rgb(255, 161, 0);
|
||||||
--white: #f5f5f5;
|
--white: rgb(245, 245, 245);
|
||||||
}
|
}
|
||||||
|
|
||||||
#shipUi {
|
#shipUi {
|
||||||
color: var(--white);
|
color: var(--white);
|
||||||
font-size: 21px;
|
font-size: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#list-entry {
|
#list-entry {
|
||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
.green {
|
.green {
|
||||||
color: var(--green);
|
color: var(--green);
|
||||||
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
.purple {
|
.purple {
|
||||||
@@ -40,3 +41,7 @@
|
|||||||
.red {
|
.red {
|
||||||
color: var(--red);
|
color: var(--red);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.yellow {
|
||||||
|
color: var(--yellow);
|
||||||
|
}
|
||||||
+12
-4
@@ -23,7 +23,7 @@ public readonly struct SectorTime {
|
|||||||
public double Value { get; }
|
public double Value { get; }
|
||||||
public SectorColour Colour { get; }
|
public SectorColour Colour { get; }
|
||||||
|
|
||||||
public override string ToString() => $"{Sector} {Value:0.000}";
|
public override string ToString() => $"{Value:0.000}";
|
||||||
|
|
||||||
public string ColourClass() => Colour switch {
|
public string ColourClass() => Colour switch {
|
||||||
SectorColour.Green => "green",
|
SectorColour.Green => "green",
|
||||||
@@ -55,21 +55,25 @@ public class Timing: MonoBehaviour {
|
|||||||
public bool timerEnabled;
|
public bool timerEnabled;
|
||||||
|
|
||||||
public double sectorTime;
|
public double sectorTime;
|
||||||
|
public double lapTime;
|
||||||
double sectorStart;
|
double sectorStart;
|
||||||
Sector[] sectors;
|
double lapStart;
|
||||||
|
public Sector[] sectors;
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
lapTimes = new();
|
lapTimes = new();
|
||||||
sectorTimes = new List<SectorTime>();
|
sectorTimes = new List<SectorTime>();
|
||||||
sectorStart = 0.0;
|
sectorStart = 0.0;
|
||||||
sectorTime = 0.0;
|
sectorTime = 0.0;
|
||||||
sectors = GetComponentsInChildren<Sector>();
|
sectors = GetComponentsInChildren<Sector>().OrderBy(s => s.sector).ToArray();
|
||||||
Debug.Log("Track Sector Count - " + sectors.Length);
|
Debug.Log("Track Sector Count - " + sectors.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (timerEnabled)
|
if (timerEnabled) {
|
||||||
sectorTime = Time.timeAsDouble - sectorStart;
|
sectorTime = Time.timeAsDouble - sectorStart;
|
||||||
|
lapTime = Time.timeAsDouble - lapStart;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StartTimer() {
|
public void StartTimer() {
|
||||||
@@ -81,6 +85,7 @@ public class Timing: MonoBehaviour {
|
|||||||
Debug.Log("Started Timer");
|
Debug.Log("Started Timer");
|
||||||
|
|
||||||
timerEnabled = true;
|
timerEnabled = true;
|
||||||
|
lapStart = Time.timeAsDouble;
|
||||||
sectorStart = Time.timeAsDouble;
|
sectorStart = Time.timeAsDouble;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +93,7 @@ public class Timing: MonoBehaviour {
|
|||||||
sectorTimes = new List<SectorTime>();
|
sectorTimes = new List<SectorTime>();
|
||||||
timerEnabled = false;
|
timerEnabled = false;
|
||||||
sectorTime = 0;
|
sectorTime = 0;
|
||||||
|
lapTime = 0;
|
||||||
Debug.Log("Timer Stopped");
|
Debug.Log("Timer Stopped");
|
||||||
|
|
||||||
EndLap();
|
EndLap();
|
||||||
@@ -115,6 +121,8 @@ public class Timing: MonoBehaviour {
|
|||||||
SectorTime s = new SectorTime(sector, sTime);
|
SectorTime s = new SectorTime(sector, sTime);
|
||||||
sectorTimes.Add(s);
|
sectorTimes.Add(s);
|
||||||
|
|
||||||
|
sectorStart = Time.timeAsDouble;
|
||||||
|
|
||||||
if (sectorTimes.Count == sectors.Length) {
|
if (sectorTimes.Count == sectors.Length) {
|
||||||
EndLap();
|
EndLap();
|
||||||
NextLap();
|
NextLap();
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
||||||
<Style src="project://database/Assets/Src/ShipUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#ShipUi" />
|
<Style src="project://database/Assets/Src/ShipUi.uss?fileID=7433441132597879392&guid=cf92f075876ddf7ffb4cd5c59633ad7b&type=3#ShipUi" />
|
||||||
<ui:VisualElement name="shipUi" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); color: rgb(255, 255, 255); font-size: 24px; -unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Regular.otf?fileID=12800000&guid=11752fd494516326b889605754cb9e26&type=3#Jura-Regular'); -unity-font-definition: initial;">
|
<ui:VisualElement name="shipUi" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); color: rgb(255, 255, 255); font-size: 28px; -unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&guid=65648a14640996362a6b0929c723b6e4&type=3#Jura-Medium'); -unity-font-definition: initial;">
|
||||||
<ui:VisualElement name="timeSheet" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); align-items: flex-end;">
|
<ui:VisualElement name="timeSheet" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); align-items: flex-end;">
|
||||||
<ui:Label tabindex="-1" text="Lap 00 - 1:28.64" display-tooltip-when-elided="true" />
|
<ui:Label tabindex="-1" text="Lap 00 - 1:28.64" display-tooltip-when-elided="true" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:VisualElement name="Middle" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);" />
|
<ui:VisualElement name="Middle" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0);" />
|
||||||
<ui:VisualElement name="Bottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: column; align-items: center; justify-content: flex-end; color: rgb(255, 255, 255);">
|
<ui:VisualElement name="Bottom" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0.26); flex-direction: column; align-items: stretch; justify-content: flex-end; color: rgb(255, 255, 255); width: 33%; align-self: center;">
|
||||||
<ui:Label tabindex="-1" text="Time" display-tooltip-when-elided="true" name="timer" />
|
<ui:VisualElement name="upper" style="flex-grow: 1; background-color: rgba(0, 0, 0, 0); flex-direction: row; justify-content: space-between; align-items: auto; width: auto; align-self: stretch; flex-shrink: 0;">
|
||||||
<ui:VisualElement name="sectors" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row;">
|
<ui:Label tabindex="-1" text="Speed" display-tooltip-when-elided="true" name="speed" style="align-self: flex-start; align-items: auto;" />
|
||||||
<ui:Label tabindex="-1" text="32.0" display-tooltip-when-elided="true" class="red" />
|
<ui:Label tabindex="-1" text="Time" display-tooltip-when-elided="true" name="timer" style="align-self: flex-end; align-items: auto;" />
|
||||||
<ui:Label tabindex="-1" text="64.0" display-tooltip-when-elided="true" class="green" />
|
</ui:VisualElement>
|
||||||
|
<ui:VisualElement name="sectors" style="flex-grow: 0; background-color: rgba(0, 0, 0, 0); flex-direction: row; align-self: stretch; align-items: stretch; justify-content: space-between;">
|
||||||
|
<ui:Label tabindex="-1" text="32.0" display-tooltip-when-elided="true" class="yellow" />
|
||||||
|
<ui:Label tabindex="-1" text="64.0" display-tooltip-when-elided="true" class="green" style="-unity-font-style: normal; -unity-font: url('project://database/Assets/UI%20Toolkit/Fonts/Jura-Medium.otf?fileID=12800000&guid=65648a14640996362a6b0929c723b6e4&type=3#Jura-Medium');" />
|
||||||
<ui:Label tabindex="-1" text="1:28.8" display-tooltip-when-elided="true" class="purple" />
|
<ui:Label tabindex="-1" text="1:28.8" display-tooltip-when-elided="true" class="purple" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
<ui:Label tabindex="-1" text="Speed" display-tooltip-when-elided="true" name="speed" />
|
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
Reference in new issue
Block a user