1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- 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<SteamVR_TrackedObject>();
- legTrackedObject = legTracker.GetComponent<SteamVR_TrackedObject>();
- 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);
- }
- }
- }
- }
|