1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using Controller.Bicycle;
- using Sensors;
- using TMPro;
- using UnityEngine;
- namespace Display
- {
- public class BikeDataDisplay : MonoBehaviour
- {
- public TextMeshProUGUI cadenceDisplay;
- private bool cadenceDisplayAvailable;
- public TextMeshProUGUI heartRateDisplay;
- private bool heartRateDisplayAvailable;
- public TextMeshProUGUI powerDisplay;
- private bool powerDisplayAvailable;
- private BikeSensorData sensorData;
- [Header("Speed")] public RbBicycleController bicycleController;
- public TextMeshProUGUI speedDisplay;
- public bool useSpeedFromBicycleController = true;
- private bool speedDisplayAvailable;
- public TextMeshProUGUI torqueDisplay;
- private bool torqueDisplayAvailable;
- // Start is called before the first frame update
- private void Start()
- {
- sensorData = BikeSensorData.Instance;
- speedDisplayAvailable = speedDisplay != null;
- powerDisplayAvailable = powerDisplay != null;
- torqueDisplayAvailable = torqueDisplay != null;
- cadenceDisplayAvailable = cadenceDisplay != null;
- heartRateDisplayAvailable = heartRateDisplay != null;
- }
- // Update is called once per frame
- private void Update()
- {
- var bikeSpeed = useSpeedFromBicycleController
- ? bicycleController.CurrentSpeedKph
- : sensorData.SpeedData?.SpeedKmh ?? 0f;
- if (speedDisplayAvailable) speedDisplay.text = $"{bikeSpeed:n2} km/h";
- if (powerDisplayAvailable) powerDisplay.text = $"{sensorData.PowermeterData?.InstantaneousPower ?? 0f:0} W";
- if (cadenceDisplayAvailable)
- cadenceDisplay.text = $"{sensorData.PowermeterData?.InstantaneousCadence ?? 0f:0} rpm";
- if (torqueDisplayAvailable) torqueDisplay.text = $"{sensorData.PowermeterData?.CrankTorque ?? 0f:F2} Nm";
- if (heartRateDisplayAvailable) heartRateDisplay.text = $"{sensorData.HrData?.HeartRate ?? 0:0} bpm";
- }
- }
- }
|