47 lines
1.1 KiB
C#
47 lines
1.1 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);
|
|
}
|
|
|
|
sectors.text = $"{String.Join(" ", timing.sectorTimes)}";
|
|
}
|
|
}
|