52 lines
1.2 KiB
C#
52 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
using BoostComponents;
|
|
|
|
public class ControlsUI : MonoBehaviour {
|
|
[SerializeField]
|
|
ShipControls ship;
|
|
|
|
UIDocument uiDocument;
|
|
Label speed;
|
|
Label shields;
|
|
|
|
BoostBar boostBar;
|
|
InterfaceIcon shield;
|
|
|
|
void OnEnable() {
|
|
Init();
|
|
}
|
|
|
|
void Init() {
|
|
uiDocument = GetComponent<UIDocument>();
|
|
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
|
shields = uiDocument.rootVisualElement.Q<Label>("shields");
|
|
|
|
shield = uiDocument.rootVisualElement.Q<InterfaceIcon>("ShieldIcon");
|
|
|
|
boostBar = uiDocument.rootVisualElement.Q<BoostBar>("boostBar");
|
|
}
|
|
|
|
void FixedUpdate() {
|
|
if (speed == null) {
|
|
Debug.LogWarning("no speed");
|
|
Init();
|
|
return;
|
|
}
|
|
|
|
speed.text = $"{ship.Speed():0}";
|
|
shield.detail = ship.powerUnit.ShieldPct switch {
|
|
"100" => "",
|
|
string pct => pct,
|
|
};
|
|
|
|
boostBar.progress = ship.powerUnit.BoostProgress;
|
|
boostBar.charges = ship.powerUnit.BoostCharges;
|
|
}
|
|
}
|