public OpenVREvents(bool lazyLoadEvents = false)
        {
            if (OpenVRHelpers.IsUsingSteamVRInput())
            {
                enabled = false; //let the steamvr plugin handle events
                return;
            }

            instance = this;
            events   = new OpenVREvent[(int)EVREventType.VREvent_VendorSpecific_Reserved_End];

            vrEvent     = new VREvent_t();
            vrEventSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));

            if (lazyLoadEvents == false)
            {
                for (int eventIndex = 0; eventIndex < events.Length; eventIndex++)
                {
                    events[eventIndex] = new OpenVREvent();
                }
            }
            else
            {
                preloadedEvents = true;
            }

            RegisterDefaultEvents();
        }
Exemple #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.mirrorViewMode      = (ushort)settings.GetMirrorViewMode();

                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;

                SetUserDefinedSettings(userDefinedSettings);
            }
#endif

            CreateSubsystem <XRDisplaySubsystemDescriptor, XRDisplaySubsystem>(s_DisplaySubsystemDescriptors, "OpenVR Display");

            EVRInitError result = GetInitializationResult();
            if (result != EVRInitError.None)
            {
                DestroySubsystem <XRDisplaySubsystem>();
                Debug.LogError("<b>[OpenVR]</b> Could not initialize OpenVR. Error code: " + result.ToString());
                return(false);
            }

            CreateSubsystem <XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "OpenVR Input");

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

            return(displaySubsystem != null && inputSubsystem != null);
        }
Exemple #3
0
        public OpenVREvents(bool lazyLoadEvents = false)
        {
            instance = this;
            events   = new OpenVREvent[(int)API.EVREventType.VREvent_VendorSpecific_Reserved_End];

            vrEvent     = new API.VREvent_t();
            vrEventSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(API.VREvent_t));

            if (lazyLoadEvents == false)
            {
                for (int eventIndex = 0; eventIndex < events.Length; eventIndex++)
                {
                    events[eventIndex] = new OpenVREvent();
                }
            }
            else
            {
                preloadedEvents = true;
            }

            RegisterDefaultEvents();
        }
Exemple #4
0
 private void TickCallback(int value)
 {
     OpenVREvents.Update();
 }
Exemple #5
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);
        }
Exemple #6
0
 public static void Initialize(bool lazyLoadEvents = false)
 {
     instance = new OpenVREvents(lazyLoadEvents);
 }
Exemple #7
0
 public static void TickCallback(int value)
 {
     OpenVREvents.Update();
 }