Пример #1
0
        private void Update()
        {
            var node   = _hand == Hand.Left ? XRNode.LeftHand : XRNode.RightHand;
            var device = InputDevices.GetDeviceAtXRNode(node);

            // Match this transform to the controller's position & rotation
            InputTracking.GetNodeStates(_states);
            IsConnected = false;
            for (var i = 0; i < _states.Count; i++)
            {
                var state = _states[i];
                if (state.nodeType == node)
                {
                    if (state.TryGetPosition(out var pos))
                    {
                        _xform.localPosition = pos;
                        if (state.TryGetRotation(out var rot))
                        {
                            _xform.localRotation = rot;
                            IsConnected          = true;
                        }
                    }
                    break;
                }
            }

            // Update the states of the Grip and Trigger analog buttons
            if (device.TryGetFeatureValue(CommonUsages.grip, out var value))
            {
                Grip.Update(value);
            }

            if (device.TryGetFeatureValue(CommonUsages.trigger, out value))
            {
                Trigger.Update(value);
            }


            // Update the A/X button, interpreting a touch with a value that can be seen in the ButtonState's analog value
            if (device.TryGetFeatureValue(CommonUsages.primaryButton, out var buttonValue))
            {
                if (buttonValue)
                {
                    AorX.Update(1f);
                }
                else if (device.TryGetFeatureValue(CommonUsages.primaryTouch, out buttonValue))
                {
                    AorX.Update(buttonValue ? 0.25f : 0f);
                }
                else
                {
                    AorX.Update(0f);
                }
            }

            // Update the B/Y button, interpreting a touch with a value that can be seen in the ButtonState's analog value
            if (device.TryGetFeatureValue(CommonUsages.secondaryButton, out buttonValue))
            {
                if (buttonValue)
                {
                    BorY.Update(1f);
                }
                else if (device.TryGetFeatureValue(CommonUsages.secondaryTouch, out buttonValue))
                {
                    BorY.Update(buttonValue ? 0.25f : 0f);
                }
                else
                {
                    BorY.Update(0f);
                }
            }
        }