Esempio n. 1
0
        public void Init()
        {
            Console.CancelKeyPress += CancelKeyPressed;

            var initError = EVRInitError.None;

            vrSystem = OpenVR.Init(ref initError, EVRApplicationType.VRApplication_Background);
            if (initError != EVRInitError.None)
            {
                var message = OpenVR.GetStringForHmdError(initError);
                throw new Exception($"Failed to initialize OpenVR: {message}");
            }

            vrInput    = OpenVR.Input;
            vrSettings = OpenVR.Settings;

            var appDir       = AppDomain.CurrentDomain.BaseDirectory;
            var manifestPath = Path.Combine(appDir, "action_manifest.json");

            var inputError = vrInput.SetActionManifestPath(manifestPath);

            if (inputError != EVRInputError.None)
            {
                var message = inputError.ToString();
                throw new Exception($"Failed to set action manifest path: {message}");
            }

            inputError = vrInput.GetActionSetHandle("/actions/main", ref inputSet);
            if (inputError != EVRInputError.None)
            {
                var message = inputError.ToString();
                throw new Exception($"Failed to action set handle: {message}");
            }

            inputError = vrInput.GetActionHandle("/actions/main/in/activate", ref inputActivate);
            if (inputError != EVRInputError.None)
            {
                var message = inputError.ToString();
                throw new Exception($"Failed to get action handle for Activate: {message}");
            }

            inputError = vrInput.GetActionHandle("/actions/main/in/reset-auto", ref inputResetAuto);
            if (inputError != EVRInputError.None)
            {
                var message = inputError.ToString();
                throw new Exception($"Failed to get action handle for Reset (Auto): {message}");
            }

            inputError = vrInput.GetActionHandle("/actions/main/in/reset", ref inputResetHold);
            if (inputError != EVRInputError.None)
            {
                var message = inputError.ToString();
                throw new Exception($"Failed to get action handle for Reset (Hold): {message}");
            }

            activateSound = new SoundPlayer(Path.Combine(appDir, "activate.wav"));
            resetSound    = new SoundPlayer(Path.Combine(appDir, "reset.wav"));
        }
Esempio n. 2
0
        private bool GetActionHandle(string path, ref ulong handle)
        {
            var e = input.GetActionHandle(path, ref handle);

            if (e != EVRInputError.None)
            {
                Debug.LogError($"Failed: 'GetActionHandle' with path '{path}': {e}");
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        private static ulong SafeGetActionHandle(CVRInput vrInput, string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(0ul);
            }

            var handle = OpenVR.k_ulInvalidActionHandle;
            var error  = vrInput.GetActionHandle(path, ref handle);

            if (error != EVRInputError.None)
            {
                Debug.LogError("Load " + path + " action failed! error=" + error);
                return(OpenVR.k_ulInvalidActionHandle);
            }
            else
            {
                return(handle);
            }
        }
Esempio n. 4
0
        //アクションを登録してハンドルを格納
        public void RegisterAction(string path)
        {
            ReadyCheck(); //実行可能な状態かチェック

            EVRInputError inputError = EVRInputError.None;
            ulong         handle     = InvalidInputHandle;

            //ハンドルが存在しない場合登録。すでにある場合は無視
            if (!ActionHandles.ContainsKey(path))
            {
                inputError = vrinput.GetActionHandle(path, ref handle);
                if (inputError != EVRInputError.None)
                {
                    //だいたいハンドル名が間違っている。いずれにせよ致命的エラー
                    throw new IOException(inputError.ToString());
                }
                ActionHandles.Add(path, handle);
            }
            return;
        }