using System.Globalization; using TMPro; using Tracking; using UnityEngine; using UnityEngine.UI; using Valve.VR; using Valve.VR.InteractionSystem; namespace Display { public class ViveTrackerDebugDisplay : MonoBehaviour { public TextMeshProUGUI posText; public TextMeshProUGUI rotText; public Image fwImage; public Image legImage; public FrontWheelTracker fwTracker; public KineticLegTracker legTracker; private SteamVR_TrackedObject fwTrackedObject; private SteamVR_TrackedObject legTrackedObject; private bool isFwTrackerNull; private bool islegTrackerNull; private bool isFwTrackedObjectNull; private bool isLegTrackedObjectNull; // Start is called before the first frame update private void Start() { isFwTrackerNull = fwTracker == null; islegTrackerNull = legTracker == null; fwTrackedObject = fwTracker.GetComponent(); legTrackedObject = legTracker.GetComponent(); isFwTrackedObjectNull = fwTrackedObject == null; isLegTrackedObjectNull = legTrackedObject == null; } // Update is called once per frame private void Update() { if (!isFwTrackerNull & fwTracker.isActiveAndEnabled & !isFwTrackerNull && fwTrackedObject.isValid) { posText.text = $"Pos: {fwTracker.RelativePosition.ToString()}"; rotText.text = $"Rot: {fwTracker.SteerRotation:n2}"; fwImage.color = Color.green; } else { posText.text = $"Pos: -"; rotText.text = $"Rot: -"; fwImage.color = Color.grey.ColorWithAlpha(100); } if (!islegTrackerNull & legTracker.isActiveAndEnabled && !isLegTrackedObjectNull && legTrackedObject.isValid) { legImage.color = Color.green; } else { legImage.color = Color.grey.ColorWithAlpha(100); } } } }