Exemple #1
0
        /// <summary>
        /// Updates the key pose state based on the provided snapshot.
        /// </summary>
        protected override void Update()
        {
            List <InputDevice> leftHandDevices = new List <InputDevice>();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Left, leftHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, leftHandDevices);
            #endif

            if (leftHandDevices.Count > 0 && leftHandDevices[0].isValid)
            {
                this.left.Update(leftHandDevices[0]);
            }

            List <InputDevice> rightHandDevices = new List <InputDevice>();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Right, rightHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.RightHand, rightHandDevices);
            #endif

            if (rightHandDevices.Count > 0 && rightHandDevices[0].isValid)
            {
                this.right.Update(rightHandDevices[0]);
            }
        }
        /// <summary>
        /// Updates the key pose state based on the provided snapshot.
        /// </summary>
        protected override void Update()
        {
            this.leftHandDevices.Clear();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Left, this.leftHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, this.leftHandDevices);
            #endif

            if (this.leftHandDevices.Count > 0 && this.leftHandDevices[0].isValid)
            {
                this.left.Update(this.leftHandDevices[0]);
            }

            this.rightHandDevices.Clear();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Right, this.rightHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.RightHand, this.rightHandDevices);
            #endif

            if (this.rightHandDevices.Count > 0 && this.rightHandDevices[0].isValid)
            {
                this.right.Update(this.rightHandDevices[0]);
            }
        }
Exemple #3
0
        void FixedUpdate()
        {
            InputDevices.GetDevicesAtXRNode(role, devices);
            if (devices.Count > 0)
            {
                device = devices[0];
            }

            if (device != null && device.isValid)
            {
                //Sets hand fingers wrap
                if (device.TryGetFeatureValue(XRHandControllerLink.GetCommonButton(button), out bool teleportButton))
                {
                    if (teleporting && !teleportButton)
                    {
                        hand.Teleport();
                        teleporting = false;
                    }
                    else if (!teleporting && teleportButton)
                    {
                        hand.StartTeleport();
                        teleporting = true;
                    }
                }
            }
        }
Exemple #4
0
    void Init()
    {
        var devices = new List <InputDevice>();

        InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, devices);
        if (devices.Count == 1)
        {
            ld = devices[0];
        }
        devices = new List <InputDevice>();
        InputDevices.GetDevicesAtXRNode(XRNode.RightHand, devices);
        if (devices.Count == 1)
        {
            rd = devices[0];
        }
        XRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale);
        Vector3 p1, p2;

        ld.TryGetFeatureValue(CommonUsages.devicePosition, out p1);
        rd.TryGetFeatureValue(CommonUsages.devicePosition, out p2);
        if (p1 == Vector3.zero || p2 == Vector3.zero)
        {
            Invoke("Init", 1.0f);
        }
    }
Exemple #5
0
    public void Start()
    {
        cam         = GetComponent <Camera>();
        cam.enabled = false;
        XRGeneralSettings.Instance.Manager.activeLoader.GetLoadedSubsystem <XRInputSubsystem>().TrySetTrackingOriginMode(TrackingOriginModeFlags.Floor);
        Application.onBeforeRender += () => {
            cam.enabled = true;
            var heads = new List <InputDevice>();
            InputDevices.GetDevicesAtXRNode(XRNode.Head, heads);
            InputDevice head = new InputDevice();
            if (heads.Count == 1)
            {
                head = heads[0];
            }
            head.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 headPosition);
            head.TryGetFeatureValue(CommonUsages.deviceRotation, out Quaternion headRotation);


            var ent = CameraRigEntity.Value;
            if (ent != Entity.Null)
            {
                var entMan = CameraRigEntity.World.EntityManager;
                transform.position = entMan.GetComponentData <LocalToWorld>(ent).Position + (float3)headPosition;
                transform.rotation = headRotation * entMan.GetComponentData <LocalToWorld>(ent).Rotation;
            }
            else
            {
                transform.position = headPosition;
                transform.rotation = headRotation;
            }
        };
    }
Exemple #6
0
    void Start()
    {
        var rightHandDevices = new List <InputDevice>();

        InputDevices.GetDevicesAtXRNode(XRNode.RightHand, rightHandDevices);
        rightHand = rightHandDevices[0];
    }
Exemple #7
0
 //Get all the devices for the appropiate node (left or right node)
 //And assign it to the hand if there exists a device
 private void GetDevices()
 {
     InputDevices.GetDevicesAtXRNode(xrNode, devices);
     if (devices.Count > 0)
     {
         hand = devices[0];
     }
 }
 void GetDevices()
 {
     InputDevices.GetDevicesAtXRNode(xrHandNode, deviceList); //Gets all connected devices
     if (deviceList.Count > 0)
     {
         deviceActual = deviceList[0]; //And assigns the first one to be the tracked device
     }
 }
Exemple #9
0
        public static List <InputDevice> GetTrackingReferences2()
        {
            var devices = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(XRNode.TrackingReference, devices);

            return(devices);
        }
Exemple #10
0
        public static List <InputDevice> GetRightEyes()
        {
            var devices = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(XRNode.RightEye, devices);

            return(devices);
        }
Exemple #11
0
        public static List <InputDevice> GetHeads()
        {
            var devices = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(XRNode.Head, devices);

            return(devices);
        }
Exemple #12
0
        public static List <InputDevice> GetHardwareTrackers()
        {
            var devices = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(XRNode.HardwareTracker, devices);

            return(devices);
        }
Exemple #13
0
        public static List <InputDevice> GetGameControllers()
        {
            var devices = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(XRNode.GameController, devices);

            return(devices);
        }
Exemple #14
0
        public void SetDeviceFromXRNode()
        {
            var devices = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(XRNode, devices);

            Device = devices.FirstOrDefault();
        }
Exemple #15
0
    // Use this for initialization
    void Start()
    {
        takeoffLandButton.transform.GetComponentInChildren <Text>().text = "Takeoff";
        takeoffLandButton.GetComponent <Button>().onClick.AddListener(TakeoffLandButtonEvent);
        ConnectToTcpServer();

        InputDevices.GetDevicesAtXRNode(controllerNode, devices);
        controller = devices.FirstOrDefault();
    }
Exemple #16
0
    private void UpdateHand(XRNode node, HandProxy proxy)
    {
        List <InputDevice> devices = new List <InputDevice>(); // Gosh I hate this API...

        InputDevices.GetDevicesAtXRNode(node, devices);
        if (devices.Count == 1)
        {
            UpdateHand(devices[0], proxy);
        }
    }
        /// <summary>
        /// Update all eye data.
        /// </summary>
        protected override void Update()
        {
            List <InputDevice> devices = new List <InputDevice>();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.EyeTracking, devices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.Head, devices);
            #endif

            foreach (var device in devices)
            {
                // Controller/EyeTracking - use the same definition, so we must check.
                if (device.isValid)
                {
                    // Eyes
                    if (device.TryGetFeatureValue(CommonUsages.eyesData, out UnityEngine.XR.Eyes deviceEyes))
                    {
                        if (LeftEye != null)
                        {
                            this.UpdateEye(device, deviceEyes, MLEye.EyeType.Left);
                        }

                        if (RightEye != null)
                        {
                            this.UpdateEye(device, deviceEyes, MLEye.EyeType.Right);
                        }

                        // Fixation Point
                        if (deviceEyes.TryGetFixationPoint(out Vector3 deviceFixationPoint))
                        {
                            MLEyes.FixationPoint = deviceFixationPoint;
                        }

                        // Fixation Confidence
                        if (device.TryGetFeatureValue(MagicLeapHeadUsages.FixationConfidence, out float deviceFixationConfidence))
                        {
                            MLEyes.FixationConfidence = deviceFixationConfidence;
                        }

                        // Calibration Status
                        if (device.TryGetFeatureValue(MagicLeapHeadUsages.EyeCalibrationStatus, out uint deviceCalibrationStatus))
                        {
                            MLEyes.CalibrationStatus = (Calibration)deviceCalibrationStatus;
                        }
                    }
                }
                else
                {
                    MLPluginLog.Error("MLEyes.Update failed to locate a valid tracker.");
                }
            }
        }
Exemple #18
0
 void GetDevice()
 {
     for (int i = 0; i < listener.nodes; i++)
     {
         InputDevices.GetDevicesAtXRNode(listener.xrNodes[i], listener.devices);
         listener.device[i] = new EventListener.Device
         {
             name  = listener.xrNodes[i].ToString(),
             input = listener.devices.FirstOrDefault()
         };
     }
 }
    void Start()
    {
        InputDevices.GetDevicesAtXRNode(XRNode.RightEye, rightEyeDevice);

        sniperTransform = GetComponent <Transform>();

        XRRig xrScript = xrRigGameObject.GetComponent <XRRig>();

        headsetCamera = xrScript.cameraGameObject;

        scopeRenderingObject.SetActive(false);
    }
Exemple #20
0
        void RefreshDevice()
        {
            var trackers = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(XRNode.HardwareTracker, trackers);
            if (trackers.Count > 1)
            {
                var tracker = trackers.Find(id => id.isValid);
                //todo get serialnumber and search steamvr for its tracker role

                //mFeets[1] = trackers.FindLast(id => id.isValid);
            }
        }
 void GetDevice(XRNode Hand, GameObject controller)
 {
     InputDevices.GetDevicesAtXRNode(Hand, devices);
     device = devices.FirstOrDefault();
     if (!device.isValid)
     {
         controller.SetActive(false);
     }
     else
     {
         controller.SetActive(true);
     }
 }
Exemple #22
0
    void ShowDeviceNames()
    {
        string displayTextAccumulator = node + ": ";

        List <InputDevice> inputDevices = new List <InputDevice>();

        InputDevices.GetDevicesAtXRNode(node, inputDevices);

        foreach (InputDevice device in inputDevices)
        {
            displayTextAccumulator += (device.name + ", ");
        }
        listText.text = displayTextAccumulator;
    }
Exemple #23
0
    protected override void OnUpdate()
    {
        EntityManager entityManager = EntityManager;
        var heads = new List<InputDevice>();
        InputDevices.GetDevicesAtXRNode(XRNode.Head, heads);
        var leftHandDevices = new List<InputDevice>();
        InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, leftHandDevices);
        var rightHandDevices = new List<InputDevice>();
        InputDevices.GetDevicesAtXRNode(XRNode.RightHand, rightHandDevices);

        InputDevice head = new InputDevice();
        if (heads.Count == 1)
        {
            head = heads[0];
        }

        InputDevice leftHand = new InputDevice();
        if (leftHandDevices.Count == 1)
        {
            leftHand = leftHandDevices[0];
        }

        InputDevice rightHand = new InputDevice();
        if (rightHandDevices.Count == 1)
        {
            rightHand = rightHandDevices[0];
        }

        var pInput = InputManager.pilotInput;

        head.TryGetFeatureValue(CommonUsages.centerEyePosition, out Vector3 headPosition);
        head.TryGetFeatureValue(CommonUsages.centerEyeRotation, out Quaternion headRotation);

        leftHand.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 leftPosition);
        leftHand.TryGetFeatureValue(CommonUsages.deviceRotation, out Quaternion leftRotation);
        rightHand.TryGetFeatureValue(CommonUsages.devicePosition, out Vector3 rightPosition);
        rightHand.TryGetFeatureValue(CommonUsages.deviceRotation, out Quaternion rightRotation);
        
        Entities.ForEach((CameraRigData cameraRig) =>
        {

            SetComponent(cameraRig.head, new Translation { Value = headPosition });
            SetComponent(cameraRig.head, new Rotation { Value = headRotation });
            SetComponent(cameraRig.leftHand, new Translation { Value = leftPosition });
            SetComponent(cameraRig.leftHand, new Rotation { Value = leftRotation });
            SetComponent(cameraRig.rightHand, new Translation { Value = rightPosition });
            SetComponent(cameraRig.rightHand, new Rotation { Value = rightRotation });
        }).Run();
    }
Exemple #24
0
        // Update is called once per frame
        void Update()
        {
            if (XRSettings.enabled)
            {
                var inputDevices = new List <InputDevice>();
                InputDevices.GetDevicesAtXRNode(XRNode.RightHand, inputDevices);
                foreach (var device in inputDevices)
                {
                    if (device.TryGetFeatureValue(CommonUsages.triggerButton, out inputValue) && inputValue)
                    {
                        if (ButtonTrigger == ButtonState.RELEASED)
                        {
                            ButtonTrigger = ButtonState.PRESSED;
                            var eventData = new PointerEventData(EventSystem.current);
//						dropdown.OnPointerClick(eventData);
//						GetComponent<Canvas>().
//						ExecuteEvents.Execute(GetComponent<Canvas>(), eventData, ExecuteEvents.pointerClickHandler);


//						this.OnPointerClick(eventData);

/*
 *                                              var dropdownList = this.transform.Find("Dropdown List");
 *                                              if (dropdownList != null)
 *                                              {
 *                                                      var boxCollider = dropdownList.GetComponent<BoxCollider>();
 *                                                      if (boxCollider == null)
 *                                                      {
 *                                                              dropdownList.gameObject.AddComponent<BoxCollider>();
 *                                                              dropdownList.gameObject.AddComponent<ResizeCollider>();
 *                                                              dropdownList.gameObject.AddComponent<SelectModule>();
 *                                                      }
 *                                              }
 *                                              Debug.Log("Trigger is pressed.");
 */
                        }
                        else if (ButtonTrigger == ButtonState.PRESSED)
                        {
                            Debug.Log("Trigger button keep pressing.");
                            ButtonTrigger = ButtonState.KEEP_PRESSING;
                        }
                    }
                    else
                    {
                        ButtonTrigger = ButtonState.RELEASED;
                    }
                }
            }
        }
        private bool GetDevice()
        {
            _xrController = (XRNode)xrController.Value;
            InputDevices.GetDevicesAtXRNode(_xrController, devices);

            if (devices != null)
            {
                device = devices.FirstOrDefault();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #26
0
    // Update is called once per frame
    void Update()
    {
        deviceCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Left;
        InputDevices.GetDevicesAtXRNode(controllerNode, inputDevices);

        foreach (InputDevice inputDevice in inputDevices)
        {
            Debug.Log("Device found with name: " + inputDevice.name);
            bool inputValue;
            if (inputDevice.TryGetFeatureValue(CommonUsages.primaryButton, out inputValue) && inputValue)
            {
                Debug.Log("You pressed the Primary Button");
            }
        }
    }
Exemple #27
0
        void Update()
        {
            InputDevices.GetDevicesAtXRNode(role, devices);
            if (devices.Count > 0)
            {
                device = devices[0];
            }

            if (device != null && device.isValid)
            {
                //Sets hand fingers wrap
                if (device.TryGetFeatureValue(GetCommonAxis(grabAxis), out float triggerOffset))
                {
                    hand.SetGrip(triggerOffset);
                }

                //Grip input
                if (device.TryGetFeatureValue(GetCommonButton(grabButton), out bool grip))
                {
                    if (grabbing && !grip)
                    {
                        hand.Release();
                        hand.gripOffset -= 0.8f;
                        grabbing         = false;
                    }
                    else if (!grabbing && grip)
                    {
                        hand.Grab();
                        hand.gripOffset += 0.8f;
                        grabbing         = true;
                    }
                }
                //Grip input
                if (device.TryGetFeatureValue(GetCommonButton(squeezeButton), out bool squeeze))
                {
                    if (squeezing && !squeeze)
                    {
                        hand.Unsqueeze();
                        squeezing = false;
                    }
                    else if (!squeezing && squeeze)
                    {
                        hand.Squeeze();
                        squeezing = true;
                    }
                }
            }
        }
Exemple #28
0
 protected void OnDeviceConnected(InputDevice target)
 {
     if (device == target || !device.isValid)
     {
         // so we don't spam everything waiting on a connection, let's see if this might be a new target for ourselves:
         var potentialDevices = new List <InputDevice>();
         InputDevices.GetDevicesAtXRNode(xrNode, potentialDevices);
         if (potentialDevices != null && potentialDevices.Count != 0)
         {
             if (potentialDevices.Contains(target))
             {
                 Initialize();
             }
         }
     }
 }
Exemple #29
0
    //AWAKE CONTROLLERS
    private void GetControllers()
    {
        InputDevices.GetDevicesAtXRNode(leftControllerNode, leftDevices);
        if (leftDevices.Count == 1)
        {
            leftController = leftDevices[0];
            //Debug.Log(leftDevices[0]);
        }

        InputDevices.GetDevicesAtXRNode(rightControllerNode, rightDevices);
        if (rightDevices.Count == 1)
        {
            rightController = rightDevices[0];
            //Debug.Log(rightDevices[0]);
        }
    }
Exemple #30
0
        private void Start()
        {
            var devices = new List <InputDevice>();

            InputDevices.GetDevicesAtXRNode(xrNode, devices);

            if (devices.Count == 1)
            {
                device = devices[0];
                Debug.Log(string.Format("Device name '{0}' with role '{1}'", device.name, device.role.ToString()));
            }
            else if (devices.Count > 1)
            {
                Debug.Log("Found more than one left hand!");
            }
        }