private void OnEnable() { bool paddleInLeftHand = System.Convert.ToBoolean(PlayerPrefs.GetInt("PaddleInLeftHand")); var controllers = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode( paddleInLeftHand ? UnityEngine.XR.XRNode.LeftHand : UnityEngine.XR.XRNode.RightHand, controllers ); if (controllers.Count != 1) { string handType = paddleInLeftHand ? "left" : "right"; throw new System.Exception($"Error: Found {controllers.Count} {handType} hands."); } _controller = controllers[0]; // Make sure the controller supports haptics, or else we can't do vibrations. UnityEngine.XR.HapticCapabilities capabilities; if (!_controller.TryGetHapticCapabilities(out capabilities) || !capabilities.supportsImpulse) { this.enabled = false; } }
void Start() { initializer = GameObject.FindGameObjectWithTag("initVR"); initVR = initializer.GetComponent <initVR>(); // deviceL = initVR.deviceL; deviceR = initVR.deviceR; a = GetComponent <Renderer>(); bikeTransform = GetComponent <Transform>(); player = GameObject.FindGameObjectWithTag("test"); pMM = player.GetComponent <playerMoveManager>(); // var inputDevices = new List<UnityEngine.XR.InputDevice>(); // var leftHandDevices = new List<UnityEngine.XR.InputDevice>(); // var rightHandDevices = new List<UnityEngine.XR.InputDevice>(); // InputDevices.GetDevices(inputDevices); // foreach (var device in inputDevices) // { // Debug.Log(string.Format("Device found with name '{0}' and role '{1}'", device.name, device.characteristics.ToString())); // } // UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, rightHandDevices); // if (rightHandDevices.Count == 1) // { // deviceR = rightHandDevices[0]; // Debug.Log(string.Format("Device name '{0}' with role '{1}'", deviceR.name, deviceR.characteristics.ToString())); // } }
/// <summary> /// Return a quaternion for the Y axis of the HMD's orientation. /// Used by orientation handlers to track the current heading before processing user input to adjust it. /// </summary> /// <returns></returns> public Quaternion GetHeadRotationY() { Quaternion headRotation = Quaternion.identity; #if UNITY_2019_1_OR_NEWER UnityEngine.XR.InputDevice device = UnityEngine.XR.InputDevices.GetDeviceAtXRNode(UnityEngine.XR.XRNode.Head); if (device.isValid) { device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.deviceRotation, out headRotation); } #elif UNITY_2017_2_OR_NEWER List <UnityEngine.XR.XRNodeState> nodeStates = new List <UnityEngine.XR.XRNodeState>(); UnityEngine.XR.InputTracking.GetNodeStates(nodeStates); foreach (UnityEngine.XR.XRNodeState n in nodeStates) { if (n.nodeType == UnityEngine.XR.XRNode.Head) { n.TryGetRotation(out headRotation); break; } } #else headRotation = InputTracking.GetLocalRotation(VRNode.Head); #endif Vector3 euler = headRotation.eulerAngles; euler.x = 0; euler.z = 0; headRotation = Quaternion.Euler(euler); return(headRotation); }
void ReadControllers(BioIKGroup group, UnityEngine.XR.InputDevice controller, bool isLeft) { if (controller == null) { return; } var _enabled = 0.0f; var trigger = false; if (controller.isValid) { controller.TryGetFeatureValue(UnityEngine.XR.CommonUsages.trigger, out _enabled); controller.TryGetFeatureValue(UnityEngine.XR.CommonUsages.gripButton, out trigger); } int i = isLeft ? 0 : 1; // Show that the arm is active in the state manager //WidgetInteraction.SetBodyPartActive(53 - i, _enabled > 0.9f); // Show that the fingers are active in the state manager //WidgetInteraction.SetBodyPartActive(55 - i, trigger); #if SENSEGLOVE group.WeakSetEnabled(true); #else group.SetEnabled(_enabled > 0.9f); group.UpdateFingers(System.Convert.ToDouble(trigger)); #endif }
private void RegisterDevices() { // For now, we keep this simple: // We look at all connected devices and add as "the" inputDevice if the type matches the `device` field selected. // We don't do anything with ambidextrous controllers or if, say, the user has two HMDs connected. // Nor do we do anything if a controller is disconnected. List <UnityEngine.XR.InputDevice> allInputDevices = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevices(allInputDevices); List <XRNodeState> allNodeStates = new List <XRNodeState>(); UnityEngine.XR.InputTracking.GetNodeStates(allNodeStates); for (int i = 0; i < allInputDevices.Count; i++) { if ((allInputDevices[i].characteristics & UnityEngine.XR.InputDeviceCharacteristics.HeadMounted) == UnityEngine.XR.InputDeviceCharacteristics.HeadMounted) { if (deviceType == DeviceType.HMD) { inputDevice = allInputDevices[i]; positionAction = new InputAction(); positionAction.AddBinding(new InputBinding("<XRHMD>/centerEyePosition")); positionAction.performed += OnPositionAction; positionAction.Enable(); rotationAction = new InputAction(); rotationAction.AddBinding(new InputBinding("<XRHMD>/centerEyeRotation")); rotationAction.performed += OnRotationAction; rotationAction.Enable(); } } else if ((allInputDevices[i].characteristics & UnityEngine.XR.InputDeviceCharacteristics.HeldInHand) == UnityEngine.XR.InputDeviceCharacteristics.HeldInHand) { if ((allInputDevices[i].characteristics & UnityEngine.XR.InputDeviceCharacteristics.Left) == UnityEngine.XR.InputDeviceCharacteristics.Left) { if (deviceType == DeviceType.LeftHand) { inputDevice = allInputDevices[i]; poseAction = new InputAction(); poseAction.AddBinding("<XRController>{LeftHand}/devicePose"); poseAction.performed += OnPoseAction; poseAction.Enable(); } } else if ((allInputDevices[i].characteristics & UnityEngine.XR.InputDeviceCharacteristics.Right) == UnityEngine.XR.InputDeviceCharacteristics.Right) { if (deviceType == DeviceType.RightHand) { inputDevice = allInputDevices[i]; poseAction = new InputAction(); poseAction.AddBinding("<XRController>{RightHand}/devicePose"); poseAction.performed += OnPoseAction; poseAction.Enable(); } } } } }
// Get the left and right controller void GetControllers() { var gameContorllers = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(UnityEngine.XR.InputDeviceCharacteristics.Controller, gameContorllers); if (gameContorllers.Count > 0) { leftController = gameContorllers[0]; rightController = gameContorllers[1]; } }
// Start is called before the first frame update void Start() { var rightHandedControllers = new List <UnityEngine.XR.InputDevice>(); var desiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Right | UnityEngine.XR.InputDeviceCharacteristics.Controller; UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics, rightHandedControllers); if (rightHandedControllers.Count > 0) { rightController = rightHandedControllers[0]; } balloonrb = GameObject.FindWithTag("Balloon").GetComponent <Rigidbody>(); audioSource = GetComponent <AudioSource>(); }
void FindControllers() { if (InputManager.Instance.GetLeftController()) { leftController = InputManager.Instance.controllerLeft[0]; leftControllerFound = true; } if (InputManager.Instance.GetRightController()) { rightController = InputManager.Instance.controllerRight[0]; rightControllerFound = true; } }
private void onDeviceDisconnected(UnityEngine.XR.InputDevice device) { Debug.Log(string.Format("Disconnected : name '{0}' and role '{1}'", device.name, device.characteristics.ToString())); UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, listDevices); if (listDevices.Count == 0) { if (spawnedHandModel != null) { spawnedHandModel.SetActive(false); } } }
void FindController() { if (!controllerFound) { inputDevice = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode(transform.GetComponentInChildren <UnityEngine.XR.Interaction.Toolkit.XRController>().controllerNode, inputDevice); Debug.Log(inputDevice.Count); if (inputDevice.Count > 0) { hand = inputDevice[0]; controllerFound = true; } } }
void Start() { var headsets = new List <UnityEngine.XR.InputDevice>(); var desiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeadMounted | UnityEngine.XR.InputDeviceCharacteristics.TrackedDevice; UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics, headsets); foreach (var device in headsets) { if (device.name == "Oculus Rift CV1") { headset = device; } } }
private void GetFeatureValues() { List <InputDevice> devices = new List <InputDevice>(); InputDevices.GetDevicesWithCharacteristics(inputDeviceCharacteristics, devices); if (devices.Count == 1) { UnityEngine.XR.InputDevice device = devices[0]; targetDevice.TryGetFeatureValue(CommonUsages.deviceVelocity, out Vector3 velocity); targetDevice.TryGetFeatureValue(CommonUsages.deviceVelocity, out Vector3 angularVelocity); Debug.Log(string.Format("Device name '{0}' with velocity : '{1}' and angular '{2}'", device.name, velocity, angularVelocity)); } }
// Start is called before the first frame update void Start() { speed = 1f; var gameControllers = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesWithRole(UnityEngine.XR.InputDeviceRole.RightHanded, gameControllers); foreach (var device in gameControllers) { Debug.Log(string.Format("Device name '{0}' has role '{1}'", device.name, device.role.ToString())); } if (gameControllers.Count > 0) { controller = gameControllers[0]; } }
/// <summary> /// Returns whether the secondary button is pressed on the left or right /// controller (Y or B respectively on the Quest). /// </summary> private bool SecondaryButtonIsPressed(bool left) { UnityEngine.XR.InputDevice controller = left ? _leftController : _rightController; if (controller.TryGetFeatureValue( UnityEngine.XR.CommonUsages.secondaryButton, out bool secondaryButtonValue ) ) { return(secondaryButtonValue); } // If we can't get whether the button is pressed, assume it's not. return(false); }
void GetControllerDevices(XRNode controllerNode, ref UnityEngine.XR.InputDevice controller, ref List <UnityEngine.XR.InputDevice> inputDevices) { Debug.Log("Get devices is called"); UnityEngine.XR.InputDevices.GetDevicesAtXRNode(controllerNode, inputDevices); if (inputDevices.Count == 1) { controller = inputDevices[0]; Debug.Log(string.Format("Device name '{0}' with characteristics '{1}'", controller.name, controller.characteristics)); } if (inputDevices.Count > 1) { Debug.LogAssertion("More than one device found with the same input characteristics"); } }
// Start is called before the first frame update void Start() { startY = transform.localPosition.y; maxY = startY - 0.25f; handleGameObject = transform.Find("hori").gameObject; balloon = GetComponentInParent <BalloonController>(); var leftHandedControllers = new List <UnityEngine.XR.InputDevice>(); var desiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Left | UnityEngine.XR.InputDeviceCharacteristics.Controller; UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics, leftHandedControllers); if (leftHandedControllers.Count > 0) { leftController = leftHandedControllers[0]; leftControllerGO = GameObject.Find("LeftController"); } }
// Update is called once per frame void Update() { // left var leftHandDevices = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.LeftHand, leftHandDevices); if (leftHandDevices.Count == 1) { UnityEngine.XR.InputDevice device = leftHandDevices[0]; Debug.Log(string.Format("Device name '{0}' with role '{1}'", device.name, device.role.ToString())); //lHand.transform.position = device. device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.devicePosition, out lHandPos); device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.deviceRotation, out lHandRot); lHand.transform.rotation = lHandRot; //lHand.transform.position = lHand.transform.InverseTransformVector(pbody.transform.position); lHand.transform.localPosition = lHandPos; //lHand.transform.position *= gameObject.transform.localScale.x; } else if (leftHandDevices.Count > 1) { Debug.Log("Found more than one left hand!"); } // right var rightHandDevices = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, rightHandDevices); if (rightHandDevices.Count == 1) { UnityEngine.XR.InputDevice device = rightHandDevices[0]; Debug.Log(string.Format("Device name '{0}' with role '{1}'", device.name, device.role.ToString())); //lHand.transform.position = device. device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.devicePosition, out rHandPos); Debug.Log("rHandPos:" + rHandPos); device.TryGetFeatureValue(UnityEngine.XR.CommonUsages.deviceRotation, out rHandRot); rHand.transform.rotation = rHandRot; rHand.transform.localPosition = rHandPos; //rHand.transform.position *= gameObject.transform.localScale.x; } else if (rightHandDevices.Count > 1) { Debug.Log("Found more than one right hand!"); } }
void Start() { initializer = GameObject.Find("initVR"); initVR = initializer.GetComponent <initVR>(); // deviceML = initVR.deviceL; // deviceMR = initVR.deviceR; var inputDevices = new List <UnityEngine.XR.InputDevice>(); var leftHandDevices = new List <UnityEngine.XR.InputDevice>(); var rightHandDevices = new List <UnityEngine.XR.InputDevice>(); InputDevices.GetDevices(inputDevices); foreach (var device in inputDevices) { Debug.Log(string.Format("Device found with name '{0}' and role '{1}'", device.name, device.characteristics.ToString())); } UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.LeftHand, leftHandDevices); if (leftHandDevices.Count == 1) { deviceML = leftHandDevices[0]; Debug.Log(string.Format("Device name '{0}' with role '{1}'", deviceML.name, deviceML.characteristics.ToString())); } else if (leftHandDevices.Count > 1) { Debug.Log("Found more than one left hand!"); } UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, rightHandDevices); if (rightHandDevices.Count == 1) { deviceMR = rightHandDevices[0]; Debug.Log(string.Format("Device name '{0}' with role '{1}'", deviceMR.name, deviceMR.characteristics.ToString())); } else if (rightHandDevices.Count > 1) { Debug.Log("Found more than one right hand!"); } }
private void onDeviceConnected(UnityEngine.XR.InputDevice device) { Debug.Log(string.Format("Connected : name '{0}' and role '{1}'", device.name, device.characteristics.ToString())); UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, listDevices); if (listDevices.Count > 0) { targetDevice = listDevices[0]; if (spawnedHandModel != null) { spawnedHandModel.SetActive(true); } else { spawnedHandModel = Instantiate(handModelPrefab, transform); } } }
private void Start() { var devices = new List <InputDevice>(); InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices); foreach (var item in devices) { Debug.Log(item.name + item.characteristics); } if (devices.Count > 0) { _targetDevice = devices[0]; _spawnedHandModel = Instantiate(handModelPrefab, transform); _handAnimator = _spawnedHandModel.GetComponent <Animator>(); } }
void UpdateHandAnimation(UnityEngine.XR.InputDevice targetDevice, Animator handAnimator) { if (targetDevice.TryGetFeatureValue(UnityEngine.XR.CommonUsages.trigger, out float triggerValue)) { handAnimator.SetFloat("Trigger", triggerValue); } else { handAnimator.SetFloat("Trigger", 0); } if (targetDevice.TryGetFeatureValue(UnityEngine.XR.CommonUsages.grip, out float gripValue)) { handAnimator.SetFloat("Grip", gripValue); } else { handAnimator.SetFloat("Grip", 0); } }
private void AssignControllers() { if (cType == ControllerType.LeftController) { var leftHandDevices = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.LeftHand, leftHandDevices); if (leftHandDevices.Count == 1) { controller = leftHandDevices[0]; } } else if (cType == ControllerType.RightController) { var rightHandDevices = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, rightHandDevices); if (rightHandDevices.Count == 1) { controller = rightHandDevices[0]; } } controller.TryGetHapticCapabilities(out capabilities); }
public void Start() { var inputDevices = new List <UnityEngine.XR.InputDevice>(); var leftHandDevices = new List <UnityEngine.XR.InputDevice>(); var rightHandDevices = new List <UnityEngine.XR.InputDevice>(); InputDevices.GetDevices(inputDevices); foreach (var device in inputDevices) { Debug.Log(string.Format("Device found with name '{0}' and role '{1}'", device.name, device.characteristics.ToString())); } UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.LeftHand, leftHandDevices); if (leftHandDevices.Count == 1) { deviceL = leftHandDevices[0]; Debug.Log(string.Format("Device name '{0}' with role '{1}'", deviceL.name, deviceL.characteristics.ToString())); } else if (leftHandDevices.Count > 1) { Debug.Log("Found more than one left hand!"); } UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, rightHandDevices); if (rightHandDevices.Count == 1) { deviceR = rightHandDevices[0]; Debug.Log(string.Format("Device name '{0}' with role '{1}'", deviceR.name, deviceR.characteristics.ToString())); } else if (rightHandDevices.Count > 1) { Debug.Log("Found more than one right hand!"); } }
/// <summary> /// Attempts to update the reference to the specified controller, returning /// true if the reference is now valid, and false if not. /// </summary> private bool TryUpdateController(bool left) { // Do nothing if the controller is already valid. UnityEngine.XR.InputDevice curController = left ? _leftController : _rightController; if (curController.isValid) { return(true); } var controllers = new List <UnityEngine.XR.InputDevice>(); UnityEngine.XR.InputDevices.GetDevicesAtXRNode( left ? UnityEngine.XR.XRNode.LeftHand : UnityEngine.XR.XRNode.RightHand, controllers ); if (controllers.Count == 0) { return(false); } if (controllers.Count > 1) { string handType = left ? "left" : "right"; throw new System.Exception($"Error: Found multiple {handType} hands."); } if (left) { _leftController = controllers[0]; } else { _rightController = controllers[0]; } return(true); }
private void Awake() { tpd = GetComponent <TrackedPoseDriver>(); anchor = GetComponent <Rigidbody>(); device = InputDevices.GetDeviceAtXRNode(XRNode.RightHand); }
private void onDeviceDisconnected(UnityEngine.XR.InputDevice device) { refreshDevices(); }
private void SetDevices() { //Set Controller Devices _leftDevice = GetCurrentDevice(XRNode.LeftHand); _rightDevice = GetCurrentDevice(XRNode.RightHand); }
private void OnDeviceConnected(UnityEngine.XR.InputDevice device) { RegisterDevices(); }
private void Start() { //_leftDevice = GetCurrentDevice(XRNode.LeftHand); _rightDevice = GetCurrentDevice(XRNode.RightHand); }