Example #1
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());
        }
Example #2
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;
        }