Пример #1
0
        void Update()
        {
            foreach (var index in controllerIndices)
            {
                foreach (var buttonId in buttonIds)
                {
                    if (Varjo_SteamVR_Controller.Input(index).GetPressDown(buttonId))
                    {
                        Debug.Log(buttonId + " press down");
                    }
                    if (Varjo_SteamVR_Controller.Input(index).GetPressUp(buttonId))
                    {
                        Debug.Log(buttonId + " press up");
                        if (buttonId == EVRButtonId.k_EButton_SteamVR_Trigger)
                        {
                            Varjo_SteamVR_Controller.Input(index).TriggerHapticPulse();
                            PrintControllerStatus(index);
                        }
                    }
                    if (Varjo_SteamVR_Controller.Input(index).GetPress(buttonId))
                    {
                        Debug.Log(buttonId);
                    }
                }

                foreach (var buttonId in axisIds)
                {
                    if (Varjo_SteamVR_Controller.Input(index).GetTouchDown(buttonId))
                    {
                        Debug.Log(buttonId + " touch down");
                    }
                    if (Varjo_SteamVR_Controller.Input(index).GetTouchUp(buttonId))
                    {
                        Debug.Log(buttonId + " touch up");
                    }
                    if (Varjo_SteamVR_Controller.Input(index).GetTouch(buttonId))
                    {
                        var axis = Varjo_SteamVR_Controller.Input(index).GetAxis(buttonId);
                        Debug.Log("axis: " + axis);
                    }
                }
            }
        }
Пример #2
0
        void PrintControllerStatus(int index)
        {
            var device = Varjo_SteamVR_Controller.Input(index);

            Debug.Log("index: " + device.index);
            Debug.Log("connected: " + device.connected);
            Debug.Log("hasTracking: " + device.hasTracking);
            Debug.Log("outOfRange: " + device.outOfRange);
            Debug.Log("calibrating: " + device.calibrating);
            Debug.Log("uninitialized: " + device.uninitialized);
            Debug.Log("pos: " + device.transform.pos);
            Debug.Log("rot: " + device.transform.rot.eulerAngles);
            Debug.Log("velocity: " + device.velocity);
            Debug.Log("angularVelocity: " + device.angularVelocity);

            var l = Varjo_SteamVR_Controller.GetDeviceIndex(Varjo_SteamVR_Controller.DeviceRelation.Leftmost);
            var r = Varjo_SteamVR_Controller.GetDeviceIndex(Varjo_SteamVR_Controller.DeviceRelation.Rightmost);

            Debug.Log((l == r) ? "first" : (l == index) ? "left" : "right");
        }
Пример #3
0
        void Update()
        {
            if (!VarjoPlugin.SessionValid || OpenVR.System == null)
            {
                return;
            }

            // Force controller update in case no one else called this frame to ensure prevState gets updated.
            Varjo_SteamVR_Controller.Update();

            // Dispatch any OpenVR events.
            var system = OpenVR.System;

            if (system != null)
            {
                var vrEvent = new VREvent_t();
                var size    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t));
                for (int i = 0; i < 64; i++)
                {
                    if (!system.PollNextEvent(ref vrEvent, size))
                    {
                        break;
                    }

                    switch ((EVREventType)vrEvent.eventType)
                    {
                    case EVREventType.VREvent_ShowRenderModels:
                        Varjo_SteamVR_Events.HideRenderModels.Send(false);
                        break;

                    case EVREventType.VREvent_HideRenderModels:
                        Varjo_SteamVR_Events.HideRenderModels.Send(true);
                        break;

                    default:
                        Varjo_SteamVR_Events.System((EVREventType)vrEvent.eventType).Send(vrEvent);
                        break;
                    }
                }
            }
        }