示例#1
0
        //----------------アクションシステム----------------------------

        //アクションシステムを初期化
        public bool InitActionSystem(string ActionManifestPath = "")
        {
            EVRInputError inputError = EVRInputError.None;

            //VRシステムが使えるか
            ReadyCheck(); //実行可能な状態かチェック

            //空白ならカレントディレクトリ
            if (ActionManifestPath == "")
            {
                ActionManifestPath = Directory.GetCurrentDirectory() + "\\actions.json";
            }

            //カレントパスのActionManifestを設定(これによりLegacy Modeにならなくなる)
            inputError = vrinput.SetActionManifestPath(ActionManifestPath);

            //エラーが起きたとき(ただしミスマッチエラーは起きうるので無視)
            if (inputError != EVRInputError.None && inputError != EVRInputError.MismatchedActionManifest)
            {
                //Steam VRと通信ができていないので強制終了する
                if (inputError == EVRInputError.IPCError)
                {
                    Debug.LogError("Emergency Stop(DLL Handle Invalid!)");
                    ApplicationQuit();
                }

                //基本ここでエラーが起きた場合は致命的である
                throw new IOException(inputError.ToString());
            }
            return(true);
        }
示例#2
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"));
        }
示例#3
0
        public override void Init()
        {
            base.Init();

            // make sure OpenVR is init right away
            EVRInitError e = EVRInitError.None;

            system = OpenVR.System;
            if (system == null)
            {
                system = OpenVR.Init(ref e);
            }
            Debug.Log("OpenVR version: " + system.GetRuntimeVersion());

            // init input system
            input = OpenVR.Input;
            string actionsPath;

            if (XRInput.singleton.steamSDK_InUse)
            {
                actionsPath = Path.Combine(Application.dataPath, "StreamingAssets", "SteamVR", "actions.json");
            }
            else
            {
                actionsPath = Path.Combine(Application.dataPath, "StreamingAssets", "OpenVR", "vrstudios_actions.json");
            }
            actionsPath = actionsPath.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar);
            Debug.Log($"Loading OpenVR Input actions: '{actionsPath}'");
            var error = input.SetActionManifestPath(actionsPath);

            if (error != EVRInputError.None)
            {
                Debug.LogError("Failed: 'SetActionManifestPath': " + error.ToString());
                return;
            }

            // get hands
            GetInputSourceHandle("/user/hand/right", ref viveSource_RightHand);
            GetInputSourceHandle("/user/hand/left", ref viveSource_LeftHand);

            // get action set
            actionSets = new VRActiveActionSet_t[1];
            if (!GetActionSetHandle("/actions/vrstudios", ref viveActionSetHandle))
            {
                return;
            }
            actionSets[0].ulActionSet = viveActionSetHandle;

            // get object actions (touch)
            GetActionHandle("/actions/vrstudios/in/bumpertouch", ref viveAction_BumperTouch);
            GetActionHandle("/actions/vrstudios/in/triggertouch", ref viveAction_TriggerTouch);
            GetActionHandle("/actions/vrstudios/in/griptouch", ref viveAction_GripTouch);
            GetActionHandle("/actions/vrstudios/in/menutouch", ref viveAction_MenuTouch);
            GetActionHandle("/actions/vrstudios/in/touch1", ref viveAction_Touch1);
            GetActionHandle("/actions/vrstudios/in/touch2", ref viveAction_Touch2);
            GetActionHandle("/actions/vrstudios/in/joystick1_touch", ref viveAction_Joystick1_Touch);

            // get object actions (buttons)
            GetActionHandle("/actions/vrstudios/in/bumperbutton", ref viveAction_BumperButton);
            GetActionHandle("/actions/vrstudios/in/triggerbutton", ref viveAction_TriggerButton);
            GetActionHandle("/actions/vrstudios/in/gripbutton", ref viveAction_GripButton);
            GetActionHandle("/actions/vrstudios/in/menubutton", ref viveAction_MenuButton);
            GetActionHandle("/actions/vrstudios/in/button1", ref viveAction_Button1);
            GetActionHandle("/actions/vrstudios/in/button2", ref viveAction_Button2);
            GetActionHandle("/actions/vrstudios/in/touchpad1_button", ref viveAction_Touchpad1_Button);
            GetActionHandle("/actions/vrstudios/in/joystick1_button", ref viveAction_Joystick1_Button);

            // get object actions (grips)
            GetActionHandle("/actions/vrstudios/in/grip", ref viveAction_Grip);

            // get object actions (triggers)
            GetActionHandle("/actions/vrstudios/in/trigger", ref viveAction_Trigger);

            // get object actions (touchpads)
            GetActionHandle("/actions/vrstudios/in/touchpad1", ref viveAction_Touchpad1);

            // get object actions (joysticks)
            GetActionHandle("/actions/vrstudios/in/joystick1", ref viveAction_Joystick1);

            // rumble
            GetActionHandle("/actions/vrstudios/out/haptic_right", ref viveAction_Rumble_RightHand);
            GetActionHandle("/actions/vrstudios/out/haptic_left", ref viveAction_Rumble_LeftHand);

            // finish
            isInit = true;
        }