Exemple #1
0
        public static void Init()
        {
            if (!string.Equals(XRSettings.loadedDeviceName, "OpenVR", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new OpenVRInitException($"OpenVR is not the selected VR SDK ({XRSettings.loadedDeviceName})");
            }
            if (!OpenVRFacade.IsRuntimeInstalled())
            {
                throw new OpenVRInitException("OpenVR runtime is not installed");
            }

            EVRInitError error  = EVRInitError.None;
            CVRSystem    system = OpenVR.Init(ref error);

            if (error != EVRInitError.None)
            {
                throw new OpenVRInitException(error);
            }

            if (system == null)
            {
                throw new OpenVRInitException("OpenVR.Init returned null");
            }

            isInitialized = true;
        }
Exemple #2
0
        private void TryAddActionSet(string actionSetName)
        {
            Logger.Trace($"Registering action set '{actionSetName}'");

            if (_actionSetNames.Contains(actionSetName))
            {
                throw new InvalidOperationException($"Action set '{actionSetName}' has already been registered");
            }

            try
            {
                _actionSetNames.Add(actionSetName);
                _actionSetHandles.Add(OpenVRFacade.GetActionSetHandle(actionSetName));
            }
            catch (OpenVRInputException ex)
            {
                Logger.Error($"An unexpected OpenVR error occurred when fetching handle for action set '{actionSetName}'.");
                Logger.Error(ex);
            }
            catch (NullReferenceException ex)
            {
                Logger.Error($"A null reference exception occured when fetching handle for action set '{actionSetName}'. This is most likely caused by an internal OpenVR issue. Action has been disabled.");
                Logger.Error(ex);
            }
            catch (Exception ex)
            {
                Logger.Error($"An unexpected error occurred when fetching handle for action set '{actionSetName}'.");
                Logger.Error(ex);
            }
        }
Exemple #3
0
        public void Initialize(string actionManifestPath)
        {
            if (initialized)
            {
                throw new InvalidOperationException("Already initialized");
            }

            Logger.Info($"Initializing {nameof(OpenVRActionManager)}");

            _actionManifestPath = actionManifestPath;

            CombineAndWriteManifest();

            OpenVRFacade.SetActionManifestPath(actionManifestPath);

            IEnumerable <string> actionSetNames = _actions.Values.Select(action => action.GetActionSetName()).Distinct();

            foreach (string actionSetName in actionSetNames)
            {
                TryAddActionSet(actionSetName);
            }

            foreach (var action in _actions.Values.ToList())
            {
                TryUpdateHandle(action);
            }

            initialized = true;
        }
Exemple #4
0
        public void Update()
        {
            if (!initialized)
            {
                return;               // do nothing until initialized
            }
            if (_actionSetHandles != null)
            {
                OpenVRFacade.UpdateActionState(_actionSetHandles);
            }

            foreach (var action in _actions.Values.OfType <OVRInput>().ToList())
            {
                try
                {
                    action.UpdateData();
                }
                catch (OpenVRInputException ex)
                {
                    Logger.Error($"An unexpected OpenVR error occurred when fetching data for action '{action.name}'. Action has been disabled.");
                    Logger.Error(ex);

                    DeregisterAction(action);
                }
                catch (NullReferenceException ex)
                {
                    Logger.Error($"A null reference exception occurred when fetching data for action '{action.name}'. This is most likely caused by an internal OpenVR issue. Action has been disabled.");
                    Logger.Error(ex);

                    DeregisterAction(action);
                }
                catch (Exception ex)
                {
                    Logger.Error($"An unexpected error occurred when fetching data for action '{action.name}'. Action has been disabled.");
                    Logger.Error(ex);

                    DeregisterAction(action);
                }
            }
        }