XrUtils.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright (c) 2021 Vuplex Inc. All rights reserved.
  3. *
  4. * Licensed under the Vuplex Commercial Software Library License, you may
  5. * not use this file except in compliance with the License. You may obtain
  6. * a copy of the License at
  7. *
  8. * https://vuplex.com/commercial-library-license
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. using System;
  17. using UnityEngine;
  18. namespace Vuplex.WebView {
  19. /// <summary>
  20. /// XR-related utility methods used internally by 3D WebView.
  21. /// </summary>
  22. public static class XrUtils {
  23. public static XRSettingsWrapper XRSettings {
  24. get {
  25. return XRSettingsWrapper.Instance;
  26. }
  27. }
  28. public static bool SdkIsActive(string sdkNameFragment) {
  29. // This approach is taken because the legacy Oculus XR plugin identifies itself as "Oculus", but
  30. // the new XR plugin shows up two devices named "oculus input" and "oculus display". Similarly,
  31. // The MockHMD plugin used to identify itself as "MockHMD" but now it shows up as "MockHMD Head Tracking"
  32. // and "MockHMD Display".
  33. return XRSettings.loadedDeviceName.ToLower().Contains(sdkNameFragment.ToLower());
  34. }
  35. public static bool SinglePassRenderingIsEnabled {
  36. get {
  37. // For some headsets like HTC Vive Focus, XRSettings.eyeTextureDesc.vrUsage returns a value
  38. // other than VRTextureUsage.TwoEyes, so the VUPLEX_FORCE_SINGLE_PASS scripting symbol can be
  39. // used to force single pass in that scenario.
  40. #if VUPLEX_FORCE_SINGLE_PASS
  41. return XRSettings.enabled;
  42. #elif UNITY_2017_2_OR_NEWER
  43. return XRSettings.enabled && XRSettings.eyeTextureDesc.vrUsage == VRTextureUsage.TwoEyes;
  44. #else
  45. return false;
  46. #endif
  47. }
  48. }
  49. }
  50. }