示例#1
0
        /// <summary>
        /// Callback for when a Haptic Pulse is requested for SteamVR
        /// </summary>
        /// <param name="onHapticRequested"></param>
        private void OnHapticEventCallback(OnHapticRequestedEvent onHapticRequested)
        {
            XRNode hand = onHapticRequested.Hand == EHand.LEFT ? XRNode.LeftHand : XRNode.RightHand;

            if (InputDevices.GetDeviceAtXRNode(hand).isValid)
            {
                SendImpulseToNode(hand, onHapticRequested.HapticAmplitude, onHapticRequested.HapticDuration);
            }

            // If Oculus Go or GearVR, we send it to the two hands, just in case
            if (VRDF_Components.DeviceLoaded == SetupVR.EDevice.GEAR_VR || VRDF_Components.DeviceLoaded == SetupVR.EDevice.OCULUS_GO)
            {
                SendImpulseToNode(hand == XRNode.LeftHand ? XRNode.RightHand : XRNode.LeftHand, onHapticRequested.HapticAmplitude, onHapticRequested.HapticDuration);
            }


            void SendImpulseToNode(XRNode node, float amplitude, float duration)
            {
                InputDevices.GetDeviceAtXRNode(node).SendHapticImpulse(0, amplitude, duration);
            }
        }
示例#2
0
 protected override void OnDestroy()
 {
     base.OnDestroy();
     OnHapticRequestedEvent.UnregisterListener(OnHapticEventCallback);
 }
示例#3
0
 protected override void OnCreate()
 {
     base.OnCreate();
     OnHapticRequestedEvent.RegisterListener(OnHapticEventCallback);
 }