public static List <InputDevice> GetSimulated6DOFs() { var devices = new List <InputDevice>(); #if UNITY_2019_3_OR_NEWER InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Simulated6DOF, devices); #else InputDevices.GetDevicesWithRole(InputDeviceRole.Unknown, devices); #endif return(devices); }
public static List <InputDevice> GetRights() { var devices = new List <InputDevice>(); #if UNITY_2019_3_OR_NEWER InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Right, devices); #else InputDevices.GetDevicesWithRole(InputDeviceRole.RightHanded, devices); #endif return(devices); }
void OnEnable() { InputDevices.deviceConnected += OnDeviceConnected; InputDevices.deviceDisconnected += OnDeviceDisconnected; Application.onBeforeRender += OnBeforeRender; InputDevices.GetDevicesWithRole(role, devices); if (devices.Count > 0) { OnDeviceConnected(devices[0]); } }
void Check() { InputDevices.GetDevicesWithRole(deviceRole, _devices); if (controller.activeInHierarchy && _devices.Count == 0) { controller.SetActive(false); } else if (!controller.activeInHierarchy && _devices.Count > 0) { controller.SetActive(true); } }
void ShowDeviceNames() { string displayTextAccumulator = role + ": "; List <InputDevice> inputDevices = new List <InputDevice>(); InputDevices.GetDevicesWithRole(role, inputDevices); foreach (InputDevice device in inputDevices) { displayTextAccumulator += (device.name + ", "); } listText.text = displayTextAccumulator; }
void Update() { InputDevices.GetDevicesWithRole(inputDeviceRole, _inputDevices); _inputDevices.ForEach((d) => { if (d.TryGetFeatureValue(_selectedFeature, out _inputValue) && _inputValue) { if (!_isPressed) { _isPressed = true; OnPress.Invoke(); } } else if (_isPressed) { _isPressed = false; OnRelease.Invoke(); } }); }
//probably an opportinuty for imporvement, since I'm getting the controller and checking if it exists for every button public static bool ButtonCheck(InputDeviceRole role, CommonFeaturesString inputFeatureUsage) { var device = new List <InputDevice>(); InputDevices.GetDevicesWithRole(role, device); if (device.Count > 0) { if (device[0].TryGetFeatureValue(GetFeature(inputFeatureUsage), out bool controlValue)) { return(controlValue); } else { Debug.LogError("Match3_Cube: attempted to get a button which is not acessible on this controller!"); return(false); } } return(false); }
void Check() { // get the tracked devices for the specified role InputDevices.GetDevicesWithRole(deviceRole, devices); // if the controller was being shown, and it's not found... if (gameObj.activeInHierarchy && devices.Count == 0) { // disable unused controller gameObj.SetActive(false); } // if the controller was hidden, and now it's found else if (!gameObj.activeInHierarchy && devices.Count > 0) { // enable controller gameObj.SetActive(true); } }
void Start() { // put the controllers into an array controllerArray.Add(RightController); controllerArray.Add(LeftController); var vrDevices = new List <InputDevice>(); // temp array // get right hand InputDevices.GetDevicesWithRole(InputDeviceRole.RightHanded, vrDevices); if (vrDevices.Count > 0) { controllerDeviceArray.Add(vrDevices[0]); } // get left hand InputDevices.GetDevicesWithRole(InputDeviceRole.LeftHanded, vrDevices); if (vrDevices.Count > 0) { controllerDeviceArray.Add(vrDevices[0]); } }
private InputDevice GetDevice() { if (_device.isValid) { return(_device); } if (role == InputDeviceRole.Unknown) { return(_device); } List <InputDevice> devices = new List <InputDevice> (); InputDevices.GetDevicesWithRole(role, devices); if (devices.Count > 0 && devices[0].isValid) { _device = devices[0]; } return(_device); }
// Update is called once per frame // Logic for LipSync_Demo void Update() { if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha1)) { targetSet = 0; SetCurrentTarget(); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha2)) { targetSet = 1; SetCurrentTarget(); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha3)) { targetSet = 2; SetCurrentTarget(); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha4)) { targetSet = 3; SetCurrentTarget(); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha5)) { targetSet = 4; SetCurrentTarget(); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Alpha6)) { targetSet = 5; SetCurrentTarget(); } // Close app if (UnityEngine.Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } // VR controllers: primary buttons scrolls forward, secondary backwards #if UNITY_2019_1_OR_NEWER var inputDevices = new List <InputDevice>(); #if UNITY_2019_3_OR_NEWER InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeldInHand, inputDevices); #else InputDevices.GetDevicesWithRole(InputDeviceRole.RightHanded, inputDevices); #endif var primaryButtonPressed = false; var secondaryButtonPressed = false; foreach (var device in inputDevices) { bool boolValue; if (device.TryGetFeatureValue(CommonUsages.primaryButton, out boolValue) && boolValue) { primaryButtonPressed = true; } if (device.TryGetFeatureValue(CommonUsages.secondaryButton, out boolValue) && boolValue) { secondaryButtonPressed = true; } } if (primaryButtonPressed && !XRButtonBeingPressed) { targetSet++; if (targetSet >= maxTarget) { targetSet = 0; } SetCurrentTarget(); } if (secondaryButtonPressed && !XRButtonBeingPressed) { targetSet--; if (targetSet < 0) { targetSet = maxTarget - 1; } SetCurrentTarget(); } XRButtonBeingPressed = primaryButtonPressed || secondaryButtonPressed; #endif }
// Update is called once per frame void Update() { InputDevices.GetDevicesWithRole(chosenRole, devices); foreach (InputDevice device in devices) { device.TryGetFeatureValue(CommonUsages.trigger, out closeness); handController.SetFloat("Closeness", closeness); } if (_currentGrabObject == null) { Collider[] colliders = Physics.OverlapSphere(transform.position, grabDistance); if (colliders.Length > 0) { foreach (Collider c in colliders) { if (closeness > 0 && c.transform.CompareTag(grabTag)) { Debug.Log("Grabed object tag: " + c.gameObject.name); if (_isGrabbing) { return; } _isGrabbing = true; c.transform.SetParent(transform); if (c.GetComponent <Rigidbody>() == null) { c.gameObject.AddComponent <Rigidbody>(); } c.GetComponent <Rigidbody>().isKinematic = true; _currentGrabObject = colliders[0].transform; if (OtherHandReference.getGrabbingObject() != null) { OtherHandReference.setGrabbingObject(null); } if (c.gameObject.name == "key") { SceneManager.LoadScene(2); } } } } } else { if (closeness < 0.1) { //release the the object (unparent it) Rigidbody _objectRGB = _currentGrabObject.GetComponent <Rigidbody>(); _objectRGB.isKinematic = false; //calculate the hand's current velocity Vector3 CurrentVelocity = (transform.position - _lastFramePosition) / Time.deltaTime; //set the grabbed object's velocity to the current velocity of the hand _objectRGB.velocity = CurrentVelocity * throw_multiplier; _currentGrabObject.SetParent(null); //release reference to object _currentGrabObject = null; } } if (closeness < 0.1 && _isGrabbing) { _isGrabbing = false; } _lastFramePosition = transform.position; }
void FindDevices() { //InputDevices.GetDevices(allDevices); InputDevices.GetDevicesWithRole(InputDeviceRole.LeftHanded, leftHandDevices); InputDevices.GetDevicesWithRole(InputDeviceRole.RightHanded, rightHandDevices); }