ForceTrackingSpaceType.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.XR;
  5. /// <summary>
  6. /// Forces Unity's XR tracking mode to be set to room scale. This happens automatically with SteamVR
  7. /// but does not happen with the Oculus platform, and allows object positions to be consistent between the two.
  8. /// </summary>
  9. public class ForceTrackingSpaceType : MonoBehaviour
  10. {
  11. #if UNITY_2019_3_OR_NEWER
  12. public TrackingOriginModeFlags trackingType = TrackingOriginModeFlags.Floor;
  13. // Use this for initialization
  14. void Start()
  15. {
  16. List<XRInputSubsystem> subsystems = new List<XRInputSubsystem>();
  17. SubsystemManager.GetInstances<XRInputSubsystem>(subsystems);
  18. for (int i = 0; i < subsystems.Count; i++)
  19. {
  20. subsystems[i].TrySetTrackingOriginMode(TrackingOriginModeFlags.Floor);
  21. }
  22. }
  23. #else
  24. public TrackingSpaceType trackingType = TrackingSpaceType.RoomScale;
  25. // Use this for initialization
  26. void Start ()
  27. {
  28. XRDevice.SetTrackingSpaceType(trackingType);
  29. }
  30. #endif
  31. }