Пример #1
0
        static bool _GetValue(Dictionary <InputDevice, ControllerValues> controllerValues, InputDevice controller, InputFeatureUsage <bool> usage)
        {
            InputDevice c = GetLeftOrRightHandedController(controller);

            if (!controllerValues.ContainsKey(c))
            {
                return(false);
            }

            ControllerValues controllerValue = controllerValues[c];

            if (usage == CommonUsages.primary2DAxisClick)
            {
                return(controllerValue.primary2DAxisClickState);
            }
            else if (usage == CommonUsages.triggerButton)
            {
                return(controllerValue.triggerButtonPressed);
            }
            else if (usage == CommonUsages.primaryButton)
            {
                return(controllerValue.primaryButtonState);
            }
            else if (usage == CommonUsages.secondaryButton)
            {
                return(controllerValue.secondaryButtonState);
            }
            else if (usage == CommonUsages.gripButton)
            {
                return(controllerValue.gripButtonPressed);
            }
            return(false);
        }
Пример #2
0
        static void UpdateControllerValue(InputDevice controller, InputFeatureUsage <bool> usage, bool value)
        {
            if (!currentControllerValues.ContainsKey(controller))
            {
                return;
            }

            ControllerValues controllerValue = currentControllerValues[controller];

            if (usage == CommonUsages.primary2DAxisClick)
            {
                controllerValue.primary2DAxisClickState = value;
            }
            else if (usage == CommonUsages.triggerButton)
            {
                controllerValue.triggerButtonPressed = value;
            }
            else if (usage == CommonUsages.primaryButton)
            {
                controllerValue.primaryButtonState = value;
            }
            else if (usage == CommonUsages.secondaryButton)
            {
                controllerValue.secondaryButtonState = value;
            }
            else if (usage == CommonUsages.gripButton)
            {
                controllerValue.gripButtonPressed = value;
            }
        }
Пример #3
0
        static Vector2 _GetValue(Dictionary <InputDevice, ControllerValues> controllerValues, InputDevice controller, InputFeatureUsage <Vector2> usage)
        {
            InputDevice c = GetLeftOrRightHandedController(controller);

            if (!controllerValues.ContainsKey(c))
            {
                return(Vector2.zero);
            }

            ControllerValues controllerValue = controllerValues[c];

            if (usage == CommonUsages.primary2DAxis)
            {
                Vector2 value    = controllerValue.primary2DAxis;
                Vector2 absvalue = new Vector2(Mathf.Abs(value.x), Mathf.Abs(value.y));
                if (absvalue.x >= deadZoneIn)
                {
                    value.x = Mathf.Sign(value.x) * (absvalue.x - deadZoneIn) * (1f / (1f - deadZoneIn));
                }
                else
                {
                    value.x = 0;
                }
                if (absvalue.y >= deadZoneIn)
                {
                    value.y = Mathf.Sign(value.y) * (absvalue.y - deadZoneIn) * (1f / (1f - deadZoneIn));
                }
                else
                {
                    value.y = 0;
                }
                return(value);
            }
            return(Vector2.zero);
        }
Пример #4
0
        static void UpdateControllerValue(InputDevice controller, InputFeatureUsage <Vector2> usage, Vector2 value)
        {
            if (!currentControllerValues.ContainsKey(controller))
            {
                return;
            }

            ControllerValues controllerValue = currentControllerValues[controller];

            if (usage == CommonUsages.primary2DAxis)
            {
                controllerValue.primary2DAxis = value;
            }
        }
Пример #5
0
        // copy current frame controller values to previous frame
        public static void BackupControllerValues()
        {
            prevControllerValues.Clear();
            foreach (KeyValuePair <InputDevice, ControllerValues> controllerValues in currentControllerValues)
            {
                ControllerValues values = new ControllerValues();
                values.primary2DAxisClickState = controllerValues.Value.primary2DAxisClickState;
                values.triggerButtonPressed    = controllerValues.Value.triggerButtonPressed;
                values.triggerValue            = controllerValues.Value.triggerValue;
                values.gripValue            = controllerValues.Value.gripValue;
                values.gripButtonPressed    = controllerValues.Value.gripButtonPressed;
                values.primaryButtonState   = controllerValues.Value.primaryButtonState;
                values.secondaryButtonState = controllerValues.Value.secondaryButtonState;
                values.primary2DAxis        = controllerValues.Value.primary2DAxis;

                prevControllerValues[controllerValues.Key] = values;
            }
        }
Пример #6
0
        static void UpdateControllerValue(InputDevice controller, InputFeatureUsage <float> usage, bool value)
        {
            if (!currentControllerValues.ContainsKey(controller))
            {
                return;
            }

            ControllerValues controllerValue = currentControllerValues[controller];

            if (usage == CommonUsages.trigger)
            {
                controllerValue.triggerButtonPressed = value;
            }
            if (usage == CommonUsages.grip)
            {
                controllerValue.gripButtonPressed = value;
            }
        }
Пример #7
0
        static float _GetValue(Dictionary <InputDevice, ControllerValues> controllerValues, InputDevice controller, InputFeatureUsage <float> usage)
        {
            InputDevice c = GetLeftOrRightHandedController(controller);

            if (!controllerValues.ContainsKey(c))
            {
                return(0f);
            }

            ControllerValues controllerValue = controllerValues[c];

            if (usage == CommonUsages.trigger)
            {
                return(controllerValue.triggerValue);
            }
            else if (usage == CommonUsages.grip)
            {
                return(controllerValue.gripValue);
            }
            return(0f);
        }