示例#1
0
        public bool CheckAdditionalFeature(HVRXRInputFeatures input)
        {
            if (input == HVRXRInputFeatures.SecondaryAxis2DUp ||
                input == HVRXRInputFeatures.SecondaryAxis2DDown ||
                input == HVRXRInputFeatures.SecondaryAxis2DLeft ||
                input == HVRXRInputFeatures.SecondaryAxis2DRight)
            {
                return(IsPressed(Device, InputMap.TrackPadButton));
            }

            if (input == HVRXRInputFeatures.PrimaryAxis2DUp ||
                input == HVRXRInputFeatures.PrimaryAxis2DDown ||
                input == HVRXRInputFeatures.PrimaryAxis2DLeft ||
                input == HVRXRInputFeatures.PrimaryAxis2DRight)
            {
                return(IsPressed(Device, InputMap.TrackPadButton));
            }

            return(true);
        }
示例#2
0
        public bool IsPressed(InputDevice device, HVRXRInputFeatures inputFeature, float threshold = 0f)
        {
            if ((int)inputFeature >= s_ButtonData.Length)
            {
                throw new ArgumentException("[InputHelpers.IsPressed] The value of <button> is out or the supported range.");
            }

            //button down check in addition to track pad check
            if (!CheckAdditionalFeature(inputFeature))
            {
                return(false);
            }

            var info = s_ButtonData[(int)inputFeature];

            switch (info.type)
            {
            case ButtonReadType.Binary:
            {
                if (device.TryGetFeatureValue(new InputFeatureUsage <bool>(info.name), out bool value))
                {
                    return(value);
                }
            }
            break;

            case ButtonReadType.Axis1D:
            {
                if (device.TryGetFeatureValue(new InputFeatureUsage <float>(info.name), out float value))
                {
                    return(value >= threshold);
                }
            }
            break;

            case ButtonReadType.Axis2DUp:
            {
                if (device.TryGetFeatureValue(new InputFeatureUsage <Vector2>(info.name), out Vector2 value))
                {
                    return(value.y >= InputMap.Axis2DUpThreshold);
                }
            }
            break;

            case ButtonReadType.Axis2DDown:
            {
                if (device.TryGetFeatureValue(new InputFeatureUsage <Vector2>(info.name), out Vector2 value))
                {
                    return(value.y <= -InputMap.Axis2DDownThreshold);
                }
            }
            break;

            case ButtonReadType.Axis2DLeft:
            {
                if (device.TryGetFeatureValue(new InputFeatureUsage <Vector2>(info.name), out Vector2 value))
                {
                    return(value.x <= -InputMap.Axis2DLeftThreshold);
                }
            }
            break;

            case ButtonReadType.Axis2DRight:
            {
                if (device.TryGetFeatureValue(new InputFeatureUsage <Vector2>(info.name), out Vector2 value))
                {
                    return(value.x >= InputMap.Axis2DRighThreshold);
                }
            }
            break;
            }

            return(false);
        }