public override bool Initialize()
        {
            if (IsDeviceSupported() != DeviceSupportedResult.Supported
#if UNITY_EDITOR_WIN
                || SystemInfo.graphicsDeviceType != GraphicsDeviceType.Direct3D11
#endif
                )
            {
                return(false);
            }

#if UNITY_INPUT_SYSTEM
            InputLayoutLoader.RegisterInputLayouts();
#endif // UNITY_INPUT_SYSTEM

            OculusSettings settings = GetSettings();
            if (settings != null)
            {
                NativeMethods.UserDefinedSettings userDefinedSettings;
                userDefinedSettings.sharedDepthBuffer      = (ushort)(settings.SharedDepthBuffer ? 1 : 0);
                userDefinedSettings.dashSupport            = (ushort)(settings.DashSupport ? 1 : 0);
                userDefinedSettings.stereoRenderingMode    = (ushort)settings.GetStereoRenderingMode();
                userDefinedSettings.colorSpace             = (ushort)((QualitySettings.activeColorSpace == ColorSpace.Linear) ? 1 : 0);
                userDefinedSettings.lowOverheadMode        = (ushort)(settings.LowOverheadMode ? 1 : 0);
                userDefinedSettings.protectedContext       = (ushort)(settings.ProtectedContext ? 1 : 0);
                userDefinedSettings.focusAware             = (ushort)(settings.FocusAware ? 1 : 0);
                userDefinedSettings.optimizeBufferDiscards = (ushort)(settings.OptimizeBufferDiscards ? 1 : 0);
                userDefinedSettings.phaseSync        = (ushort)(settings.PhaseSync ? 1 : 0);
                userDefinedSettings.subsampledLayout = (ushort)(settings.SubsampledLayout ? 1 : 0);
                NativeMethods.SetUserDefinedSettings(userDefinedSettings);
            }

            CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "oculus display");
            CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "oculus input");

            if (displaySubsystem == null && inputSubsystem == null)
            {
#if (UNITY_ANDROID && !UNITY_EDITOR)
                Debug.LogWarning("Unable to start Oculus XR Plugin.");
#else
                Debug.LogWarning("Unable to start Oculus XR Plugin.\n" +
                                 "Possible causes include a headset not being attached, or the Oculus runtime is not installed or up to date.\n" +
                                 "If you've recently installed or updated the Oculus runtime, you may need to reboot or close Unity and the Unity Hub and try again.");
#endif
            }
            else if (displaySubsystem == null)
            {
                Debug.LogError("Unable to start Oculus XR Plugin. Failed to load display subsystem.");
            }
            else if (inputSubsystem == null)
            {
                Debug.LogError("Unable to start Oculus XR Plugin. Failed to load input subsystem.");
            }
            else
            {
                RegisterUpdateCallback.Initialize();
            }

            return(displaySubsystem != null && inputSubsystem != null);
        }
예제 #2
0
        public override bool Initialize()
        {
#if UNITY_EDITOR
            if (!EditorLoadOVRPlugin())
            {
                return(false);
            }
#else
            if (!LoadOVRPlugin(""))
            {
                Debug.LogError("Failed to load OVRPlugin.dll");
                return(false);
            }
#endif

#if UNITY_INPUT_SYSTEM
            InputLayoutLoader.RegisterInputLayouts();
#endif

            OculusSettings settings = GetSettings();
            if (settings != null)
            {
                UserDefinedSettings userDefinedSettings;
                userDefinedSettings.sharedDepthBuffer   = (ushort)(settings.SharedDepthBuffer ? 1 : 0);
                userDefinedSettings.dashSupport         = (ushort)(settings.DashSupport ? 1 : 0);
                userDefinedSettings.stereoRenderingMode = (ushort)settings.GetStereoRenderingMode();
                userDefinedSettings.colorSpace          = (ushort)((QualitySettings.activeColorSpace == ColorSpace.Linear) ? 1 : 0);
                userDefinedSettings.lowOverheadMode     = (ushort)(settings.LowOverheadMode ? 1 : 0);
                userDefinedSettings.protectedContext    = (ushort)(settings.ProtectedContext ? 1 : 0);
                userDefinedSettings.focusAware          = (ushort)(settings.FocusAware ? 1 : 0);
                SetUserDefinedSettings(userDefinedSettings);
            }

            CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "oculus display");
            CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "oculus input");

            if (displaySubsystem == null || inputSubsystem == null)
            {
                Debug.LogError("Unable to start Oculus XR Plugin.");
            }

            if (displaySubsystem == null)
            {
                Debug.LogError("Failed to load display subsystem.");
            }

            if (inputSubsystem == null)
            {
                Debug.LogError("Failed to load input subsystem.");
            }

            return(displaySubsystem != null && inputSubsystem != null);
        }