Files
spacerace/Assets/Src/ShipUi.cs
T
2023-07-16 21:51:40 +10:00

52 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class ShipUi : MonoBehaviour {
[SerializeField]
UIDocument uiDocument = null;
[SerializeField]
ShipControls ship;
[SerializeField]
Timing timing;
Label speed;
Label timer;
Label sectors;
VisualElement timeSheet;
void OnEnable() {
speed = uiDocument.rootVisualElement.Q<Label>("speed");
timer = uiDocument.rootVisualElement.Q<Label>("timer");
sectors = uiDocument.rootVisualElement.Q<Label>("sectors");
timeSheet = uiDocument.rootVisualElement.Q<VisualElement>("timeSheet");
}
void FixedUpdate() {
timer.text = $"{timing.sectorTime:0.0}";
speed.text = $"{ship.Speed():0}";
UpdateTimesheet();
}
public void UpdateTimesheet() {
timeSheet.Clear();
foreach (Lap lap in timing.lapTimes) {
Label l = new Label();
l.text = $"{lap}";
timeSheet.Add(l);
}
foreach (SectorTime sector in timing.sectorTimes) {
Label l = new Label();
l.text = $"{sector}";
l.AddToClassList(sector.ColourClass());
sectors.Add(l);
}
}
}