private void Start() { LeftHandInputDevice = new PlayerHandInputDevice(HumanBodyPart.LeftHand, settings); RightHandInputDevice = new PlayerHandInputDevice(HumanBodyPart.RightHand, settings); SubsystemManager.GetInstances(_subsystems); foreach (var inputSubsystem in _subsystems) { Debug.Log("Detected subsystem " + inputSubsystem.GetType()); inputSubsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Floor); } if (_subsystems.Count == 0) { XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale); Debug.LogWarning("No Subsystems detected"); } impulse = new byte[20]; var caps = new HapticCapabilities(); int clipCount = (int)(caps.bufferFrequencyHz * 2); impulse = new byte[clipCount]; for (int i = 0; i < clipCount; i++) { impulse[i] = byte.MaxValue; } }
protected override void OnAdded() { base.OnAdded(); m_BufferedRumble = new BufferedRumble(this); HapticCapabilities capabilities = m_BufferedRumble.capabilities; }
// In implementations, overwrite this to generate clips protected virtual bool GenerateClip(XRNode node, ref byte[] clip) { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = InputDevices.GetDeviceAtXRNode(node); if (device == null || !device.TryGetHapticCapabilities(out caps) ) { return(false); } // This base implementation generates a very boring clip of solid intensity // over the max clip time. int clipTime = (int)(caps.bufferFrequencyHz * 2); // 2 seconds clip = new byte[clipTime]; for (int i = 0; i < clipTime; i++) { clip[i] = byte.MaxValue; } return(true); }
public void SetSliderExtents() { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = GetComponentInParent <HapticDeviceUnderTest>().device; if (device == null || !device.TryGetHapticCapabilities(out caps) || !caps.supportsImpulse ) { return; } switch (driveType) { case DriveType.Amplitude: m_Slider.maxValue = 1f; m_Slider.minValue = 0; break; case DriveType.Frequency: m_Slider.maxValue = 1f; m_Slider.minValue = 0; break; case DriveType.Duration: m_Slider.maxValue = 10f; m_Slider.minValue = 0; break; } m_Slider.value = m_Slider.maxValue; }
public void SetSliderExtents() { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = InputDevices.GetDeviceAtXRNode(node); if (device == null || !device.TryGetHapticCapabilities(out caps) || !caps.supportsImpulse ) { return; } switch (driveType) { case DriveType.Amplitude: m_Slider.maxValue = 1f; m_Slider.minValue = 0; break; case DriveType.Frequency: m_Slider.maxValue = 1f; m_Slider.minValue = 0; break; case DriveType.Duration: m_Slider.maxValue = 10f; m_Slider.minValue = 0; break; } m_Slider.value = m_Slider.maxValue; }
protected override void OnAdded() { base.OnAdded(); m_BufferedRumble = new BufferedRumble(this); HapticCapabilities capabilities = m_BufferedRumble.capabilities; Debug.Log(string.Format("XR Device Found with Haptic Capabilites: NumChannels:[{0}] FrequencyHz:[{1}] MaxBufferSize:[{2}]", capabilities.numChannels, capabilities.frequencyHz, capabilities.maxBufferSize)); }
private void SendImpulseToBothControllers() { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = GetComponentInParent <HapticDeviceUnderTest>().device; if (device != null && device.TryGetHapticCapabilities(out caps) ) { SendImpulse(caps, device); } }
private void Vibration(float intensity) { _device = InputDevices.GetDeviceAtXRNode(_xrNode); if (_device.isValid) { HapticCapabilities hapcap = new HapticCapabilities(); _device.TryGetHapticCapabilities(out hapcap); if (hapcap.supportsImpulse) { _device.SendHapticImpulse(0, intensity); } } }
private bool GetHapticCapabilities(XRNode xrNode, out InputDevice controller) { controller = InputDevices.GetDeviceAtXRNode(xrNode); HapticCapabilities hapcap = new HapticCapabilities(); if (controller.isValid) { controller.TryGetHapticCapabilities(out hapcap); Debug.Log("DOES XR CONTROLLER SUPPORT HAPTIC BUFFER: " + hapcap.supportsBuffer); Debug.Log("DOES XR CONTROLLER SUPPORT HAPTIC IMPULSE: " + hapcap.supportsImpulse); Debug.Log("DOES XR CONTROLLER SUPPORT HAPTIC CHANNELS: " + hapcap.numChannels); Debug.Log("DOES XR CONTROLLER SUPPORT HAPTIC BUFFER FREQUENCY HZ: " + hapcap.bufferFrequencyHz); } return(hapcap.supportsImpulse); }
private void SendImpulse(HapticCapabilities caps, InputDevice device) { float amplitude = (amplitudeSlider != null) ? (amplitudeSlider.value) : 1f; float duration = (durationSlider != null) ? (durationSlider.value) : 1f; float frequency = (frequencySlider != null) ? (frequencySlider.value) : 1f; if (device == null) { return; } device.SendHapticImpulse(0, amplitude, duration); Debug.Log("Impulse sent to " + device.name + "\n" + "Amplitude = " + amplitude + "\n" + "Duration = " + duration ); }
private void SendImpulseToNode(XRNode node, HapticCapabilities caps) { float amplitude = (amplitudeSlider != null) ? (amplitudeSlider.value) : 1f; float duration = (durationSlider != null) ? (durationSlider.value) : 1f; float frequency = (frequencySlider != null) ? (frequencySlider.value) : 1f; InputDevice hapticDevice = InputDevices.GetDeviceAtXRNode(node); if (hapticDevice == null) { return; } hapticDevice.SendHapticImpulse(0, amplitude, duration); Debug.Log("Impulse sent to " + node + "\n" + "Amplitude = " + amplitude + "\n" + "Duration = " + duration ); }
public static bool GenerateBuzzClip(float seconds, XRNode node, ref byte[] clip) { HapticCapabilities caps = new HapticCapabilities(); if (!InputDevices.GetDeviceAtXRNode(node).TryGetHapticCapabilities(out caps)) { return(false); } int clipCount = (int)(caps.bufferFrequencyHz * seconds); clip = new byte[clipCount]; for (int i = 0; i < clipCount; i++) { clip[i] = byte.MaxValue; } return(true); }
void Update() { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = InputDevices.GetDeviceAtXRNode(node); if (device == null || !device.TryGetHapticCapabilities(out caps) ) { return; } nodeCheck.text = node.ToString(); numChannels.text = caps.numChannels.ToString(); supportsImpulse.text = caps.supportsImpulse.ToString(); supportsBuffer.text = caps.supportsBuffer.ToString(); bufferFreqHz.text = caps.bufferFrequencyHz.ToString(); bufferMaxSize.text = caps.bufferMaxSize.ToString(); bufferOptimalSize.text = caps.bufferOptimalSize.ToString(); }
private void SendImpulseToBothControllers() { HapticCapabilities caps = new HapticCapabilities(); InputDevice LeftDevice = InputDevices.GetDeviceAtXRNode(XRNode.LeftHand); InputDevice RightDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand); if (LeftDevice != null && LeftDevice.TryGetHapticCapabilities(out caps) ) { SendImpulseToNode(XRNode.LeftHand, caps); } if (RightDevice != null && RightDevice.TryGetHapticCapabilities(out caps) ) { SendImpulseToNode(XRNode.RightHand, caps); } }
public static void BuzzNode(float seconds, XRNode node) { HapticCapabilities caps = new HapticCapabilities(); if (!InputDevices.GetDeviceAtXRNode(node).TryGetHapticCapabilities(out caps)) { return; } if (caps.supportsImpulse) { InputDevices.GetDeviceAtXRNode(node).SendHapticImpulse(0, 1, seconds); } else if (caps.supportsBuffer) { byte[] clip = {}; if (GenerateBuzzClip(seconds, node, ref clip)) { InputDevices.GetDeviceAtXRNode(node).SendHapticBuffer(0, clip); } } }
void Update() { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = GetComponentInParent <HapticDeviceUnderTest>().device; if (device == null || !device.TryGetHapticCapabilities(out caps) ) { deviceName.text = device.name; numChannels.text = "0"; supportsImpulse.text = "false"; supportsBuffer.text = "false"; bufferFreqHz.text = "N/A"; return; } deviceName.text = device.name; numChannels.text = caps.numChannels.ToString(); supportsImpulse.text = caps.supportsImpulse.ToString(); supportsBuffer.text = caps.supportsBuffer.ToString(); bufferFreqHz.text = caps.bufferFrequencyHz.ToString(); }
protected override bool GenerateClip(ref byte[] clip) { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = GetComponentInParent <HapticDeviceUnderTest>().device; if (device == null || !device.TryGetHapticCapabilities(out caps) ) { return(false); } // Generate actual clip int clipTime = (int)(caps.bufferFrequencyHz * 1); // 1 second clip = new byte[clipTime]; for (int i = 0; i < clipTime; i++) { clip[i] = byte.MaxValue; } return(true); }
protected override bool GenerateClip(XRNode node, ref byte[] clip) { HapticCapabilities caps = new HapticCapabilities(); InputDevice device = InputDevices.GetDeviceAtXRNode(node); if (device == null || !device.TryGetHapticCapabilities(out caps) ) { return(false); } // Generate actual clip int clipTime = (int)(caps.bufferFrequencyHz * 2); // 2 seconds clip = new byte[clipTime]; for (int i = 0; i < clipTime; i++) { clip[i] = (byte)(byte.MaxValue - ((byte)((i / (float)clipTime) * byte.MaxValue))); } return(true); }
void ColumnGUI(Rect cellRect, Item item, int column, ref RowGUIArgs args) { CenterRectUsingSingleLineHeight(ref cellRect); if (column == (int)ColumnId.Name) { args.rowRect = cellRect; base.RowGUI(args); } switch (column) { case (int)ColumnId.Role: if (item.depth > 0) { GUI.Label(cellRect, item.device.role.ToString()); } break; case (int)ColumnId.SupportsImpulse: if (item.depth > 0) { HapticCapabilities hapticCapabilities = new HapticCapabilities(); if (item.device.TryGetHapticCapabilities(out hapticCapabilities) && hapticCapabilities.supportsImpulse) { GUI.Toggle(cellRect, true, ""); } else { GUI.Toggle(cellRect, false, ""); } } break; case (int)ColumnId.SupportsBuffer: if (item.depth > 0) { HapticCapabilities hapticCapabilities = new HapticCapabilities(); if (item.device.TryGetHapticCapabilities(out hapticCapabilities) && hapticCapabilities.supportsBuffer) { GUI.Toggle(cellRect, true, ""); } else { GUI.Toggle(cellRect, false, ""); } } break; case (int)ColumnId.Amplitude: if (item.depth > 0) { item.amplitude = EditorGUI.Slider(cellRect, item.amplitude, 0.0F, 1.0F); } break; case (int)ColumnId.Duration: if (item.depth > 0) { item.duration = EditorGUI.Slider(cellRect, item.duration, 0.0F, 10.0F); } break; case (int)ColumnId.Trigger: if (item.depth > 0) { if (GUI.Button(cellRect, "Trigger")) { item.device.SendHapticImpulse(0, item.amplitude, item.duration); } } break; } }
public bool TryGetHapticCapabilities(out HapticCapabilities capabilities) { return(m_inputDevice.TryGetHapticCapabilities(out capabilities)); }
public bool TryGetHapticCapabilities(out HapticCapabilities capabilities) { capabilities = new HapticCapabilities(); return(false); }