Example #1
0
        string GetFeatureValue(InputDevice device, InputFeatureUsage featureUsage)
        {
            switch (featureUsage.type.ToString())
            {
            case "System.Boolean":
                bool boolValue;
                if (device.TryGetFeatureValue(featureUsage.As <bool>(), out boolValue))
                {
                    return(boolValue.ToString());
                }
                break;

            case "System.UInt32":
                uint uintValue;
                if (device.TryGetFeatureValue(featureUsage.As <uint>(), out uintValue))
                {
                    return(uintValue.ToString());
                }
                break;

            case "System.Single":
                float floatValue;
                if (device.TryGetFeatureValue(featureUsage.As <float>(), out floatValue))
                {
                    return(floatValue.ToString());
                }
                break;

            case "UnityEngine.Vector2":
                Vector2 Vector2Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector2>(), out Vector2Value))
                {
                    return(Vector2Value.ToString());
                }
                break;

            case "UnityEngine.Vector3":
                Vector3 Vector3Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector3>(), out Vector3Value))
                {
                    return(Vector3Value.ToString());
                }
                break;

            case "UnityEngine.Quaternion":
                Quaternion QuaternionValue;
                if (device.TryGetFeatureValue(featureUsage.As <Quaternion>(), out QuaternionValue))
                {
                    return(QuaternionValue.ToString());
                }
                break;

            case "UnityEngine.XR.Hand":
                Hand HandValue;
                if (device.TryGetFeatureValue(featureUsage.As <Hand>(), out HandValue))
                {
                    return(HandValue.ToString());
                }
                break;

            case "UnityEngine.XR.Bone":
                Bone BoneValue;
                if (device.TryGetFeatureValue(featureUsage.As <Bone>(), out BoneValue))
                {
                    return(BoneValue.ToString());
                }
                break;

            case "UnityEngine.XR.Eyes":
                Eyes EyesValue;
                if (device.TryGetFeatureValue(featureUsage.As <Eyes>(), out EyesValue))
                {
                    return(EyesValue.ToString());
                }
                break;
            }

            return("");
        }
        string GetFeatureValue(InputDevice device, InputFeatureUsage featureUsage)
        {
            switch (featureUsage.type.ToString())
            {
            case "System.Boolean":
                bool boolValue;
                if (device.TryGetFeatureValue(featureUsage.As <bool>(), out boolValue))
                {
                    return(boolValue.ToString());
                }
                break;

            case "System.UInt32":
                uint uintValue;
                if (device.TryGetFeatureValue(featureUsage.As <uint>(), out uintValue))
                {
                    return(uintValue.ToString());
                }
                break;

            case "System.Single":
                float floatValue;
                if (device.TryGetFeatureValue(featureUsage.As <float>(), out floatValue))
                {
                    return(floatValue.ToString());
                }
                break;

            case "UnityEngine.Vector2":
                Vector2 Vector2Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector2>(), out Vector2Value))
                {
                    return(Vector2Value.ToString());
                }
                break;

            case "UnityEngine.Vector3":
                Vector3 Vector3Value;
                if (device.TryGetFeatureValue(featureUsage.As <Vector3>(), out Vector3Value))
                {
                    return(Vector3Value.ToString());
                }
                break;

            case "UnityEngine.Quaternion":
                Quaternion QuaternionValue;
                if (device.TryGetFeatureValue(featureUsage.As <Quaternion>(), out QuaternionValue))
                {
                    return(QuaternionValue.ToString());
                }
                break;

            case "UnityEngine.XR.Hand":
                Hand HandValue;
                if (device.TryGetFeatureValue(featureUsage.As <Hand>(), out HandValue))
                {
                    return(HandValue.ToString());
                }
                break;

            case "UnityEngine.XR.Bone":
                Bone BoneValue;
                if (device.TryGetFeatureValue(featureUsage.As <Bone>(), out BoneValue))
                {
                    Vector3    bonePosition;
                    Quaternion boneRotation;
                    if (BoneValue.TryGetPosition(out bonePosition) && BoneValue.TryGetRotation(out boneRotation))
                    {
                        return(string.Format("{0}, {1}", bonePosition.ToString(), boneRotation.ToString()));
                    }
                }
                break;

            case "UnityEngine.XR.Eyes":
                Eyes EyesValue;
                if (device.TryGetFeatureValue(featureUsage.As <Eyes>(), out EyesValue))
                {
                    Vector3 fixation, left, right;
                    float   leftOpen, rightOpen;
                    if (EyesValue.TryGetFixationPoint(out fixation) &&
                        EyesValue.TryGetLeftEyePosition(out left) &&
                        EyesValue.TryGetRightEyePosition(out right) &&
                        EyesValue.TryGetLeftEyeOpenAmount(out leftOpen) &&
                        EyesValue.TryGetRightEyeOpenAmount(out rightOpen))
                    {
                        return(string.Format("{0}, {1}, {2}, {3}, {4}", fixation.ToString(), left.ToString(), right.ToString(), leftOpen, rightOpen));
                    }
                }
                break;
            }

            return("");
        }