示例#1
0
        /// Returns primary Axis (2D) vector
        public Vector2 GetAxisPrimary()
        {
            if (!HasAxisPrimary())
            {
                return(Vector2.zero);
            }

            Vector2 axis;

            if (!trackedDevice.TryGetFeatureValue(CommonUsages.primary2DAxis, out axis))
            {
                XRUtil.LogError("Failed to get primary axis value");
                return(Vector2.zero);
            }

            return(axis);
        }
示例#2
0
        /// Returns grip Axis (1D) value from 0 to 1
        public float GetAxisGrip()
        {
            // If grip Axis is not supported, return it's button alternative when avalible
            if (!HasAxisGrip() && HasFeature(CommonUsages.gripButton.name))
            {
                return(GetButton(CommonUsages.gripButton) ? 1 : 0);
            }

            float value;

            if (!trackedDevice.TryGetFeatureValue(CommonUsages.grip, out value))
            {
                XRUtil.LogError("Failed to get grip axis value");
                return(0);
            }

            return(value);
        }
示例#3
0
        void OnDeviceConnected(InputDevice device)
        {
            // Skip tracking invalid device
            if (!device.isValid)
            {
                return;
            }

            // Skip allready tracked device
            if (trackedDevice == device)
            {
                XRUtil.Log("Device is allready tracked: " + device.name);
                return;
            }

            Debug.Log(device.name + " vs " + xrDevice.ToString());
            var deviceFlags   = (uint)device.characteristics;
            var selectedFlags = (uint)xrDevice;
            var a             = Convert.ToString(deviceFlags, 2);
            var b             = Convert.ToString(selectedFlags, 2);
            var c             = Convert.ToString(deviceFlags & selectedFlags, 2);

            Debug.Log(a + " & " + b + "=" + c);

            if (!((deviceFlags & selectedFlags) == selectedFlags))
            {
                return;
            }

            trackedDevice = device;

            XRUtil.Log("Connected & Tracking " + xrDevice.ToString());

            if (trackedDevice.TryGetFeatureUsages(features))
            {
                featureNames = features.Select(feature => feature.name).ToList();
            }

            // TODO: add error reporting everywhere that uses a [TryGet"Something"] pattern
            else
            {
                XRUtil.LogError("Failed to get feature usages");
            }
        }