Exemplo n.º 1
0
 void localRightTrigger(ControllerAxis axis)
 {
     if (axis.axisValue.x > .05f || axis.axisValue.y > .05f || axis.axisValue.x < -.05f || axis.axisValue.y < -.05f)
     {
         rightTrigger = true;
     }
 }
Exemplo n.º 2
0
 void localRightStick(ControllerAxis axis)
 {
     if (axis.axisValue.x > .05f || axis.axisValue.y > .05f || axis.axisValue.x < -.05f || axis.axisValue.y < -.05f)
     {
         rightStick = true;
     }
 }
Exemplo n.º 3
0
 void localDpad(ControllerAxis axis)
 {
     if (axis.axisValue.x > .05f || axis.axisValue.y > .05f || axis.axisValue.x < -.05f || axis.axisValue.y < -.05f)
     {
         dPad = true;
     }
 }
Exemplo n.º 4
0
 private float GetControllerAxisFromEnum(ControllerAxis axis)
 {
     if (axis == ControllerAxis.LeftStickX)
     {
         return(Input.GetAxis("X axis"));
     }
     else if (axis == ControllerAxis.LeftStickY)
     {
         return(Input.GetAxis("Y axis"));
     }
     else if (axis == ControllerAxis.RightStickX)
     {
         return(Input.GetAxis("3rd axis"));
     }
     else if (axis == ControllerAxis.RightStickY)
     {
         return(Input.GetAxis("4th axis"));
     }
     else if (axis == ControllerAxis.DPadX)
     {
         return((control.GetControllerButton(ControllerButton.DPadLeft) ? -1 : 0) + (control.GetControllerButton(ControllerButton.DPadRight) ? 1 : 0));
     }
     else if (axis == ControllerAxis.DPadY)
     {
         return((control.GetControllerButton(ControllerButton.DPadDown) ? -1 : 0) + (control.GetControllerButton(ControllerButton.DPadUp) ? 1 : 0));
     }
     else
     {
         return(0);
     }
 }
Exemplo n.º 5
0
        void localAxis(ControllerAxis axis)
        {
            horizontal    = axis.axisValue.x * sensitivity * Time.deltaTime * 100f;
            vertical      = axis.axisValue.y * sensitivity * Time.deltaTime * 100f;
            actionVector3 = EasyInputUtilities.getControllerVector3(horizontal, vertical, axisHorizontal, axisVertical);

            switch (action)
            {
            case EasyInputConstants.ACTION_TYPE.Position:
                transform.position += actionVector3;
                break;

            case EasyInputConstants.ACTION_TYPE.Rotation:
                transform.Rotate(actionVector3, Space.World);
                break;

            case EasyInputConstants.ACTION_TYPE.LocalPosition:
                transform.Translate(actionVector3);
                break;

            case EasyInputConstants.ACTION_TYPE.LocalRotation:
                transform.Rotate(actionVector3);
                break;

            case EasyInputConstants.ACTION_TYPE.LocalScale:
                transform.localScale += actionVector3;
                break;

            default:
                Debug.Log("Invalid Action");
                break;
            }
        }
Exemplo n.º 6
0
    public static bool GetControllerAxis(ControllerAxis axis, int id, int InputMode = 0, bool positiveComparison = true)
    {
        if (positiveComparison)
        {
            switch (InputMode)
            {
            case 0:    //held
                return(axisInput[id - 1][(int)axis] == true);

            case 1:    //down
                return(axisInput[id - 1][(int)axis] == true && lastAxisInput[id - 1][(int)axis] != true);

            case 2:    //up
                return(axisInput[id - 1][(int)axis] != true && lastAxisInput[id - 1][(int)axis] == true);
            }
        }
        else
        {
            switch (InputMode)
            {
            case 0:    //held
                return(axisInput[id - 1][(int)axis] == false);

            case 1:    //down
                return(axisInput[id - 1][(int)axis] == false && lastAxisInput[id - 1][(int)axis] != false);

            case 2:    //up
                return(axisInput[id - 1][(int)axis] != false && lastAxisInput[id - 1][(int)axis] == false);
            }
        }


        throw new System.NotImplementedException();
    }
Exemplo n.º 7
0
 void localRightTrigger(ControllerAxis axis)
 {
     if (axis.player == player || player == EasyInputConstants.PLAYER_NUMBER.Any)
     {
         onRightTrigger.Invoke(axis);
     }
 }
Exemplo n.º 8
0
        // [JsonConstructor]
        public TriggerControllerAxis(
            string namePart,
            ControllerAxis axis,
            int bands,
            int deadzoneIndex,
            int deadzoneSize,
            List <Keys> keyList,
            List <string> macroNames) : base(namePart, macroNames)
        {
            this.axis          = axis;
            this.bands         = bands;
            this.deadzoneIndex = deadzoneIndex;
            this.deadzoneSize  = deadzoneSize;
            this.keyList.AddRange(keyList);

            int bandSpace = AXIS_MAX;

            if (DeadzoneIndex != -1)
            {
                bandSpace -= deadzoneSize;
            }

            this.bandSize = bandSpace;
            if (this.bands > 0)
            {
                this.bandSize = bandSpace / this.bands;
            }

            Type = TriggerType.ControllerAxis;
        }
Exemplo n.º 9
0
    public string AxisName(ControllerAxis axis)
    {
        switch (axis)
        {
        case ControllerAxis.HorizontalMovement:
            return("Horizontal Movement");

        case ControllerAxis.VerticalMovement:
            return("Vertical Movement");

        case ControllerAxis.HorizontalLook:
            return("Horizontal Look");

        case ControllerAxis.VerticalLook:
            return("Vertical Look");

        case ControllerAxis.Shoot:
            return("Shoot");

        case ControllerAxis.Jump:
            return("Jump");

        case ControllerAxis.Pause:
            return("Pause");

        case ControllerAxis.Back:
            return("Back");

        default:
            return("Not a valid axis oops");
        }
    }
Exemplo n.º 10
0
    void UpdateControllerValue(ControllerAxis axis, float newValue)
    {
        int   i    = (int)axis;
        float prev = inputValues[i];

        if (prev == 0 && newValue == 1)
        {
            inputDown[i] = 2; // pressed this frame
        }
        else if (prev == 1 && newValue == 0)
        {
            inputDown[i] = -2; // released this frame
        }
        else if (prev == 1 && newValue == 1)
        {
            inputDown[i] = 1; // pressed
        }
        else if (prev == 0 && newValue == 0)
        {
            inputDown[i] = -1; // not pressed
        }
        else
        {
            inputDown[i] = 0;
        }
        inputValues[i] = newValue;
    }
Exemplo n.º 11
0
 void localLeftStick(ControllerAxis axis)
 {
     if (axis.player == player || player == EasyInputConstants.PLAYER_NUMBER.Any)
     {
         onLeftStick.Invoke(axis);
     }
 }
Exemplo n.º 12
0
 void localDpad(ControllerAxis axis)
 {
     if (axis.player == player || player == EasyInputConstants.PLAYER_NUMBER.Any)
     {
         onDpad.Invoke(axis);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Retrieves the specific intensity in terms of how far/deep an axis is pressed in.
        /// The return value should be a floating point number between -100 and 100 float.
        /// For triggers, the range is a value between 0 and 100.
        /// </summary>
        /// <remarks>
        /// This does not take into account the destination axis and reads the value
        /// of the equivalent source axis. If the user has Left Stick mapped to e.g. Right Stick
        /// and you request the right stick axis, the value will return 0 (assuming right stick is centered).
        /// </remarks>
        public float GetAxisState(ControllerAxis axis)
        {
            // Retrieve requested axis mapping entry.
            AxisMappingEntry controllerAxisMapping = InputGetMappedAxis(axis, InputMappings.AxisMapping);

            // Retrieve the intensity of the axis press-in value.
            return(XInputGetAxisValue(controllerAxisMapping));
        }
Exemplo n.º 14
0
    private IEnumerator RebindAxis(int actionIndex, BindingType bindingType)
    {
        isRebindingKey = true;

        while (true)
        {
            if (GetControllerButtonDown(ControllerButton.MenuRight))
            {
                isRebindingKey = false;
                yield break;
            }

            ControllerAxis toBindTo = ControllerAxis.None;
            if (MaxFloat(GetControllerAxisFromEnum(ControllerAxis.LeftStickX)) != 0)
            {
                toBindTo = ControllerAxis.LeftStickX;
            }
            else if (MaxFloat(GetControllerAxisFromEnum(ControllerAxis.LeftStickY)) != 0)
            {
                toBindTo = ControllerAxis.LeftStickY;
            }
            else if (MaxFloat(GetControllerAxisFromEnum(ControllerAxis.RightStickX)) != 0)
            {
                toBindTo = ControllerAxis.RightStickX;
            }
            else if (MaxFloat(GetControllerAxisFromEnum(ControllerAxis.RightStickY)) != 0)
            {
                toBindTo = ControllerAxis.RightStickY;
            }
            else if (MaxFloat(GetControllerAxisFromEnum(ControllerAxis.DPadX)) != 0)
            {
                toBindTo = ControllerAxis.DPadX;
            }
            else if (MaxFloat(GetControllerAxisFromEnum(ControllerAxis.DPadY)) != 0)
            {
                toBindTo = ControllerAxis.DPadY;
            }

            if (toBindTo != ControllerAxis.None)
            {
                if (bindingType == BindingType.PrimaryAxis)
                {
                    actions[actionIndex].primaryAxis = toBindTo;
                }
                else
                {
                    actions[actionIndex].secondaryAxis = toBindTo;
                }
                isRebindingKey = false;
                yield break;
            }
            yield return(null);
        }
    }
Exemplo n.º 15
0
 public override float GetAxis(ControllerAxis axis, bool usePrevState = false)
 {
     if (IsValidAxis(axis))
     {
         return(usePrevState ? prevAxisValue[(int)axis] : currAxisValue[(int)axis]);
     }
     else
     {
         return(0f);
     }
 }
Exemplo n.º 16
0
        void localDpad(ControllerAxis axis)
        {
            //first for the siri remote we don't want to recognize the dpad and instead use touch
#if !UNITY_EDITOR && UNITY_TVOS
            if (axis.player != EasyInputHelper.siriRemotePlayer)
            {
#endif
            dpad[(int)axis.player] = axis.axisValue;
#if !UNITY_EDITOR && UNITY_TVOS
        }
#endif
        }
Exemplo n.º 17
0
        public static void SetDeadZone(int playerIndex, ControllerAxis axis, ushort value)
        {
            var controller = ControllerRegistry.Instance.GetControllerInfo(playerIndex);

            if (controller == null)
            {
                return;
            }

            if (!controller.DeadZones.ContainsKey(axis))
            {
                controller.DeadZones.Add(axis, value);
            }
            else
            {
                controller.DeadZones[axis] = value;
            }
        }
Exemplo n.º 18
0
        public static bool CanIgnoreAxisMotion(int playerIndex, ControllerAxis axis, short axisValue)
        {
            var controller = ControllerRegistry.Instance.GetControllerInfo(playerIndex);

            if (controller == null)
            {
                return(true);
            }

            if (controller.DeadZones.ContainsKey(axis))
            {
                if (Math.Abs((int)axisValue) < controller.DeadZones[axis])
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 19
0
        public static short GetAxisValue(int playerIndex, ControllerAxis axis)
        {
            var controller = ControllerRegistry.Instance.GetControllerInfo(playerIndex);

            if (controller == null)
            {
                return(0);
            }

            var axisValue = SDL2.SDL_GameControllerGetAxis(
                controller.InstancePointer,
                (SDL2.SDL_GameControllerAxis)axis
                );

            if (CanIgnoreAxisMotion(playerIndex, axis, axisValue))
            {
                return(0);
            }

            return(axisValue);
        }
Exemplo n.º 20
0
        void localAxis(ControllerAxis axis)
        {
            //first thing check if it's the right player otherwise do nothing
            if (axis.player == player || player == EasyInputConstants.PLAYER_NUMBER.Any)
            {
                horizontal    = axis.axisValue.x * sensitivity * Time.deltaTime * 100f;
                vertical      = axis.axisValue.y * sensitivity * Time.deltaTime * 100f;
                actionVector3 = EasyInputUtilities.getControllerVector3(horizontal, vertical, axisHorizontal, axisVertical);

                switch (action)
                {
                case EasyInputConstants.ACTION_TYPE.Position:
                    transform.position += actionVector3;
                    break;

                case EasyInputConstants.ACTION_TYPE.Rotation:
                    transform.Rotate(actionVector3, Space.World);
                    break;

                case EasyInputConstants.ACTION_TYPE.LocalPosition:
                    transform.Translate(actionVector3);
                    break;

                case EasyInputConstants.ACTION_TYPE.LocalRotation:
                    transform.Rotate(actionVector3);
                    break;

                case EasyInputConstants.ACTION_TYPE.LocalScale:
                    transform.localScale += actionVector3;
                    break;

                default:
                    Debug.Log("Invalid Action");
                    break;
                }
            }
        }
        /// <summary>
        /// Returns the appropriate axis mapping entry for each individual specific axis.
        /// The axis have a 1-1 relationship (oldaxis -> new axis) and a set of properties as defined in
        /// Controller_Axis_Mapping.
        /// </summary>
        /// <param name="axis">The axis whose details we want to obtain.</param>
        /// <param name="axisMapping">The axis mapping which stores the axis details for the individual controller.</param>
        /// <returns></returns>
        public static AxisMappingEntry InputGetMappedAxis(ControllerAxis axis, AxisMapping axisMapping)
        {
            // Stores the axis configuration that is to be returned.
            AxisMappingEntry controllerAxisMapping = new AxisMappingEntry();

            // Find axis mapped to the requested controller axis.
            // Check every axis manually, until one of the axes contains the desired destination axis.
            if (IsCorrectAxisMappingEntry(axisMapping.LeftStickX, axis))
            {
                return(axisMapping.LeftStickX);
            }
            if (IsCorrectAxisMappingEntry(axisMapping.LeftStickY, axis))
            {
                return(axisMapping.LeftStickY);
            }

            if (IsCorrectAxisMappingEntry(axisMapping.RightStickX, axis))
            {
                return(axisMapping.RightStickX);
            }
            if (IsCorrectAxisMappingEntry(axisMapping.RightStickY, axis))
            {
                return(axisMapping.RightStickY);
            }

            if (IsCorrectAxisMappingEntry(axisMapping.LeftTrigger, axis))
            {
                return(axisMapping.LeftTrigger);
            }
            if (IsCorrectAxisMappingEntry(axisMapping.RightTrigger, axis))
            {
                return(axisMapping.RightTrigger);
            }

            // Retrieve empty struct if null, else the correct axis mapping.
            return(controllerAxisMapping);
        }
Exemplo n.º 22
0
 public static Vector2 GetScrollDeltaEx(Type roleType, int roleValue, ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY)
 {
     return(GetState(roleType, roleValue).GetScrollDelta(scrollType, scale, xAxis, yAxis));
 }
Exemplo n.º 23
0
 private static bool IsValidAxis(ControllerAxis axis)
 {
     return(axis >= 0 && (int)axis < CONTROLLER_BUTTON_COUNT);
 }
Exemplo n.º 24
0
 public static float GetAxis(HandRole role, ControllerAxis axis, bool usePrevState = false)
 {
     return(GetAxisEx(role, axis, usePrevState));
 }
Exemplo n.º 25
0
 public static float GetAxisEx(Type roleType, int roleValue, ControllerAxis axis, bool usePrevState = false)
 {
     return(GetState(roleType, roleValue).GetAxis(axis, usePrevState));
 }
Exemplo n.º 26
0
 public static Vector2 GetScrollDelta(ViveRoleProperty role, ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY)
 {
     return(GetScrollDeltaEx(role.roleType, role.roleValue, scrollType, scale, xAxis, yAxis));
 }
Exemplo n.º 27
0
 public static float GetAxisEx <TRole>(TRole role, ControllerAxis axis, bool usePrevState = false)
 {
     return(GetState(role).GetAxis(axis, usePrevState));
 }
Exemplo n.º 28
0
 public static float GetAxis(ViveRoleProperty role, ControllerAxis axis, bool usePrevState = false)
 {
     return(GetAxisEx(role.roleType, role.roleValue, axis, usePrevState));
 }
Exemplo n.º 29
0
 public static Vector2 GetScrollDelta(HandRole role, ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY)
 {
     return(GetScrollDeltaEx(role, scrollType, scale, xAxis, yAxis));
 }
Exemplo n.º 30
0
		extern public static Int16 GameControllerGetAxis(IntPtr gamecontroller, ControllerAxis axis);
Exemplo n.º 31
0
		extern public static ControllerButtonBind GameControllerGetBindForAxis(IntPtr gamecontroller, ControllerAxis axis);
Exemplo n.º 32
0
 public static float GetAxisValueNormalized(int playerIndex, ControllerAxis axis)
 => GetAxisValue(playerIndex, axis) / 32768f;