コード例 #1
0
ファイル: OpenVRLoader.cs プロジェクト: zite/TestPackage
        public override bool Initialize()
        {
            Debug.Log("Initialize openvr loader");

#if UNITY_INPUT_SYSTEM
            InputLayoutLoader.RegisterInputLayouts();
#endif

            OpenVRSettings settings = OpenVRSettings.GetSettings();
            if (settings != null)
            {
                if (string.IsNullOrEmpty(settings.EditorAppKey))
                {
                    settings.EditorAppKey = settings.GenerateEditorAppKey();
                }

                UserDefinedSettings userDefinedSettings;
                userDefinedSettings.stereoRenderingMode  = (ushort)settings.GetStereoRenderingMode();
                userDefinedSettings.initializationType   = (ushort)settings.GetInitializationType();
                userDefinedSettings.applicationName      = null;
                userDefinedSettings.editorAppKey         = null;
                userDefinedSettings.isSteamVRLegacyInput = settings.IsLegacy;
                userDefinedSettings.mirrorViewMode       = (ushort)settings.GetMirrorViewMode();
                //todo: determine legacy state?

#if UNITY_EDITOR
                userDefinedSettings.editorAppKey    = settings.EditorAppKey; //only set the key if we're in the editor. Otherwise let steamvr set the key.
                userDefinedSettings.applicationName = string.Format("[Testing] {0}", GetEscapedApplicationName());

                settings.InitializeActionManifestFileRelativeFilePath();
#endif
                //only set the path if the file exists
                FileInfo actionManifestFileInfo = new FileInfo(settings.ActionManifestFileRelativeFilePath);
                if (actionManifestFileInfo.Exists)
                {
                    userDefinedSettings.actionManifestPath = actionManifestFileInfo.FullName.Replace("\\", "\\\\");
                }
                else
                {
                    userDefinedSettings.actionManifestPath = null;
                }


                SetUserDefinedSettings(userDefinedSettings);
            }

            CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display");
            CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input");

            Debug.Log(displaySubsystem);
            Debug.Log(inputSubsystem);


            return(displaySubsystem != null && inputSubsystem != null);
        }
コード例 #2
0
        public override bool Initialize()
        {
#if UNITY_INPUT_SYSTEM
            InputLayoutLoader.RegisterInputLayouts();
#endif


//this only works at the right time in editor. In builds we use a different method (reading the asset manually)
#if UNITY_EDITOR
            OpenVRSettings settings = OpenVRSettings.GetSettings();
            if (settings != null)
            {
                if (string.IsNullOrEmpty(settings.EditorAppKey))
                {
                    settings.EditorAppKey = settings.GenerateEditorAppKey();
                }

                UserDefinedSettings userDefinedSettings;
                userDefinedSettings.stereoRenderingMode  = (ushort)settings.GetStereoRenderingMode();
                userDefinedSettings.initializationType   = (ushort)settings.GetInitializationType();
                userDefinedSettings.applicationName      = null;
                userDefinedSettings.editorAppKey         = null;
                userDefinedSettings.isSteamVRLegacyInput = settings.IsLegacy;
                userDefinedSettings.mirrorViewMode       = (ushort)settings.GetMirrorViewMode();

                if (OpenVRHelpers.IsUsingSteamVRInput())
                {
                    userDefinedSettings.isSteamVRLegacyInput = false;
                    settings.IsLegacy = false;
                }

                userDefinedSettings.editorAppKey = settings.EditorAppKey; //only set the key if we're in the editor. Otherwise let steamvr set the key.

                if (OpenVRHelpers.IsUsingSteamVRInput())
                {
                    userDefinedSettings.editorAppKey = OpenVRHelpers.GetEditorAppKeyFromPlugin();
                }

                userDefinedSettings.applicationName = string.Format("[Testing] {0}", GetEscapedApplicationName());
                settings.InitializeActionManifestFileRelativeFilePath();

                userDefinedSettings.actionManifestPath = settings.ActionManifestFileRelativeFilePath;


                //only set the path if the file exists
                FileInfo actionManifestFileInfo = new FileInfo(userDefinedSettings.actionManifestPath);
                if (actionManifestFileInfo.Exists)
                {
                    userDefinedSettings.actionManifestPath = actionManifestFileInfo.FullName.Replace("\\", "\\\\");
                }
                else
                {
                    userDefinedSettings.actionManifestPath = null;
                }


                SetUserDefinedSettings(userDefinedSettings);
            }
#endif

            CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display");
            CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input");

            OpenVREvents.Initialize();
            TickCallbackDelegate callback = TickCallback;
            RegisterTickCallback(callback);
            callback(0);

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