public override Vector4 GetInputValue()
 {
     newVector = new Vector4();
     if (featureValue.name != null) // check if feature is not null
     {
         float floatValue = 0;
         var   devices    = new List <UnityEngine.XR.InputDevice>();
         UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(data.deviceCharacteristics, devices);
         UnityEngine.XR.InputFeatureUsage <bool> featureValue2 = CommonUsages.triggerButton;
         foreach (var device in devices)
         {
             if (device.TryGetFeatureValue(featureValue, out value))
             {
                 floatValue = value ? 1 : 0;
                 newVector += new Vector4(floatValue, 0, 0);
             }
         }
         if (devices.Count == 0)
         {
             floatValue = debugValue ? 1 : 0;
             newVector += new Vector4(floatValue, 0, 0);
         }
         else
         {
             newVector /= devices.Count;
         }
     }
     newVector = Vector4.Scale(newVector, data.maskVector);
     VRValue   = newVector;
     return(newVector);
 }
示例#2
0
    private float GetTriggerValue(bool left, bool right)
    {
        float floatValue;
        float result  = 0f;
        var   devices = new List <UnityEngine.XR.InputDevice>();

        UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(UnityEngine.XR.InputDeviceCharacteristics.Left, devices);
        UnityEngine.XR.InputFeatureUsage <float> featureValue = CommonUsages.trigger;
        if (left)
        {
            foreach (var device in devices)
            {
                if (device.TryGetFeatureValue(featureValue, out floatValue))
                {
                    result += floatValue;
                }
            }
        }

        devices = new List <UnityEngine.XR.InputDevice>();
        UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(UnityEngine.XR.InputDeviceCharacteristics.Right, devices);
        if (right)
        {
            foreach (var device in devices)
            {
                if (device.TryGetFeatureValue(featureValue, out floatValue))
                {
                    result += floatValue;
                }
            }
        }

        return(result);
    }
示例#3
0
    public void getNewColor()
    {
        if (fromWheelToggle != null && fromWheelToggle.isOn)
        {
            Vector2 vector2Value;
            bool    boolValue;
            var     devices = new List <UnityEngine.XR.InputDevice>();
            UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(UnityEngine.XR.InputDeviceCharacteristics.HeldInHand, devices);
            UnityEngine.XR.InputFeatureUsage <bool>    featureValue2 = CommonUsages.primary2DAxisTouch;
            UnityEngine.XR.InputFeatureUsage <Vector2> featureValue  = CommonUsages.primary2DAxis;
            foreach (var device in devices)
            {
                if (device.TryGetFeatureValue(featureValue2, out boolValue))
                {
                    if (boolValue)
                    {
                        if (device.TryGetFeatureValue(featureValue, out vector2Value))
                        {
                            if (vector2Value.y >= 0)
                            {
                                float h     = Vector2.Angle(Vector2.right, vector2Value) / 360;
                                float s     = 1f;
                                float v     = vector2Value.magnitude;
                                Color color = Color.HSVToRGB(h, s, v);
                                UpdateColor(color);
                            }
                            else
                            {
                                float h     = (360 - Vector2.Angle(Vector2.right, vector2Value)) / 360;
                                float s     = 1f;
                                float v     = vector2Value.magnitude;
                                Color color = Color.HSVToRGB(h, s, v);
                                UpdateColor(color);
                            }
                        }
                    }
                }
            }
            //Debug purpose

/*            if (false)
 *          {
 *              float h = Vector2.Angle(Vector2.right, new Vector2(x, y)) / 360;
 *              UpdateColor(Color.HSVToRGB(h, 1, (new Vector2(x, y).magnitude)));
 *          }*/
        }
    }
示例#4
0
    private void GetMenuValue()
    {
        var devices = new List <UnityEngine.XR.InputDevice>();

        UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(UnityEngine.XR.InputDeviceCharacteristics.Left, devices);
        UnityEngine.XR.InputFeatureUsage <bool> featureValue = CommonUsages.primaryButton;
        foreach (var device in devices)
        {
            if (device.TryGetFeatureValue(featureValue, out bool valueL))
            {
                if (valueL & !leftMenuPressed)
                {
                    saveSystem.OnDown();
                    leftMenuPressed = true;
                }
                else if (!valueL)
                {
                    leftMenuPressed = false;
                }
            }
        }

        devices = new List <UnityEngine.XR.InputDevice>();
        UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(UnityEngine.XR.InputDeviceCharacteristics.Right, devices);
        foreach (var device in devices)
        {
            if (device.TryGetFeatureValue(featureValue, out bool valueR))
            {
                if (valueR & !rightMenuPressed)
                {
                    saveSystem.OnUp();
                    rightMenuPressed = true;
                }
                else if (!valueR)
                {
                    rightMenuPressed = false;
                }
            }
        }
    }
 public override void SetInput(string name, int index)
 {
     featureValue   = (InputFeatureUsage <Quaternion>) typeof(CommonUsages).GetField(name).GetValue(typeof(CommonUsages).GetField(name));
     data.propIndex = index;
 }