TrackingManager.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Unity.XR.CoreUtils;
  2. using UnityEngine;
  3. namespace Ximmerse.XR.Tag
  4. {
  5. /// <summary>
  6. /// Calculate the offset of XROrigin and correct the Tag Tracking data coordinates.
  7. /// </summary>
  8. public class TrackingManager : MonoBehaviour
  9. {
  10. #region Property
  11. private XROrigin _xROrigin;
  12. float Y;
  13. Vector3 Tran;
  14. private static TrackingManager instance;
  15. public static TrackingManager Instance
  16. {
  17. get
  18. {
  19. return instance;
  20. }
  21. }
  22. public XROrigin xROrigin
  23. {
  24. get => _xROrigin;
  25. }
  26. private void Awake()
  27. {
  28. instance = this;
  29. _xROrigin = GameObject.FindObjectOfType<XROrigin>();
  30. }
  31. #endregion
  32. #region Unity
  33. void Start()
  34. {
  35. if (xROrigin != null)
  36. {
  37. Y = _xROrigin.GetComponent<XROrigin>().CameraYOffset;
  38. }
  39. }
  40. void Update()
  41. {
  42. if (xROrigin != null)
  43. {
  44. Tran = new Vector3(_xROrigin.transform.position.x, _xROrigin.transform.position.y + Y, _xROrigin.transform.position.z);
  45. transform.position = Tran;
  46. transform.rotation = _xROrigin.transform.rotation;
  47. }
  48. }
  49. #endregion
  50. }
  51. }