52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
|
|
public class ControlsUI : MonoBehaviour {
|
|
[SerializeField]
|
|
ShipControls ship;
|
|
|
|
UIDocument uiDocument;
|
|
Label speed;
|
|
Label shields;
|
|
Label puAccel;
|
|
Label puDecel;
|
|
Label puStrafe;
|
|
Label puShield;
|
|
|
|
void OnEnable() {
|
|
Init();
|
|
}
|
|
|
|
void Init() {
|
|
uiDocument = GetComponent<UIDocument>();
|
|
speed = uiDocument.rootVisualElement.Q<Label>("speed");
|
|
shields = uiDocument.rootVisualElement.Q<Label>("shields");
|
|
|
|
// PowerUnit
|
|
puAccel = uiDocument.rootVisualElement.Q<Label>("puAccel");
|
|
puDecel = uiDocument.rootVisualElement.Q<Label>("puDecel");
|
|
puStrafe = uiDocument.rootVisualElement.Q<Label>("puStrafe");
|
|
puShield = uiDocument.rootVisualElement.Q<Label>("puShield");
|
|
}
|
|
|
|
void FixedUpdate() {
|
|
if (speed == null) {
|
|
Debug.LogWarning("no speed");
|
|
Init();
|
|
return;
|
|
}
|
|
|
|
speed.text = $"{ship.Speed():0}";
|
|
shields.text = ship.powerUnit.ShieldsPct;
|
|
|
|
puAccel.text = ship.powerUnit.Acceleration.ToString();
|
|
puDecel.text = ship.powerUnit.Deceleration.ToString();
|
|
puStrafe.text = ship.powerUnit.Strafing.ToString();
|
|
puShield.text = ship.powerUnit.ShieldsMax.ToString();
|
|
}
|
|
}
|