Exemple #1
0
 /// <summary>
 /// sets scale ("sensitivity") of a smart control
 /// </summary>
 /// <param name="smartControlName"></param>
 /// <param name="scale"></param>
 /// <param name="slot"></param>
 public static void SetScale(string smartControlName, float scale, InputDeviceSlot slot = InputDeviceSlot.any)
 {
     SinputUpdate();
     controlFound = false;
     for (int i = 0; i < _smartControls.Length; i++)
     {
         if (_smartControls[i].name == smartControlName)
         {
             controlFound = true;
             if (slot == InputDeviceSlot.any)
             {
                 for (int k = 0; k < _totalPossibleDeviceSlots; k++)
                 {
                     _smartControls[i].scales[k] = scale;
                 }
             }
             else
             {
                 _smartControls[i].scales[(int)slot] = scale;
             }
         }
     }
     if (!controlFound)
     {
         Debug.LogError("Sinput Error: Smart Control \"" + smartControlName + "\" not found in list of SmartControls.");
     }
 }
Exemple #2
0
        public override void Process()
        {
            bool usedEvent = SendUpdateEventToSelectedObject();

            m_InputDeviceSlot = (InputDeviceSlot)Enum.Parse(typeof(InputDeviceSlot), m_InputSlotter);

            if (eventSystem.sendNavigationEvents)
            {
                if (!usedEvent)
                {
                    usedEvent |= SendMoveEventToSelectedObject();
                }

                if (!usedEvent)
                {
                    //SendSubmitEventToSelectedObject();
                    if (SendSubmitEventToSelectedObject())
                    {
                        Sinput.ResetInputs();
                    }
                }
            }

            ProcessMouseEvent();
        }
Exemple #3
0
        public float GetValue(InputDeviceSlot slot, bool getRawValue)
        {
            if ((int)slot >= controlValues.Length)
            {
                return(0f);                                             //not a slot we have any input info for
            }
            //if this input is checking a framerate independent input like a mouse, return the raw value regardless of getRawValue
            if (!valuePrefersDeltaUse[(int)slot])
            {
                return(rawValues[(int)slot] * scales[(int)slot]);
            }

            //deadzone clipping
            if (Mathf.Abs(controlValues[(int)slot]) < deadzone)
            {
                return(0f);
            }

            if (getRawValue)
            {
                //return the raw value
                return(rawValues[(int)slot] * scales[(int)slot]);
            }

            //return the smoothed value
            return(controlValues[(int)slot] * scales[(int)slot]);
        }
Exemple #4
0
 public bool ButtonCheck(ButtonAction bAction, InputDeviceSlot slot)
 {
     if (bAction == ButtonAction.DOWN && Sinput.GetButtonDown(positiveControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.DOWN && Sinput.GetButtonDown(negativeControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.HELD && Sinput.GetButton(positiveControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.HELD && Sinput.GetButton(negativeControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.UP && Sinput.GetButtonUp(positiveControl, slot))
     {
         return(true);
     }
     if (bAction == ButtonAction.UP && Sinput.GetButtonUp(negativeControl, slot))
     {
         return(true);
     }
     return(false);
 }
Exemple #5
0
        private float AxisCheck(InputDeviceSlot slot, out bool framerateIndependentValue)
        {
            float returnV = 0f;

            framerateIndependentValue = true;
            for (int i = 0; i < inputs.Count; i++)
            {
                float v = inputs[i].AxisCheck(slot);
                if (Mathf.Abs(v) > returnV)
                {
                    //this is the value we're going with
                    returnV = v;
                    //now find out if what set this value was something we shouldn't multiply by deltaTime
                    framerateIndependentValue = true;
                    if (inputs[i].inputType == InputDeviceType.Mouse)
                    {
                        if (inputs[i].mouseInputType == MouseInputType.MouseMoveLeft || inputs[i].mouseInputType == MouseInputType.MouseMoveRight ||
                            inputs[i].mouseInputType == MouseInputType.MouseMoveUp || inputs[i].mouseInputType == MouseInputType.MouseMoveDown ||
                            inputs[i].mouseInputType == MouseInputType.MouseHorizontal || inputs[i].mouseInputType == MouseInputType.MouseVertical ||
                            inputs[i].mouseInputType == MouseInputType.MouseScrollUp || inputs[i].mouseInputType == MouseInputType.MouseScrollDown ||
                            inputs[i].mouseInputType == MouseInputType.MouseScroll)
                        {
                            framerateIndependentValue = false;
                        }
                    }
                }
            }
            return(returnV);
        }
Exemple #6
0
    }                                                                                                           //default wait is half a second

    /// <summary>
    /// tells Sinput to return false/0f for any input checks until the wait time has passed
    /// </summary>
    /// <param name="waitTime"></param>
    /// <param name="slot"></param>
    public static void ResetInputs(float waitTime, InputDeviceSlot slot = InputDeviceSlot.any)
    {
        SinputUpdate();

        if (slot == InputDeviceSlot.any)
        {
            //reset all slots' input
            for (int i = 0; i < _totalPossibleDeviceSlots; i++)
            {
                zeroInputWaits[i] = waitTime;
                zeroInputs[i]     = true;
            }
        }
        else
        {
            //reset only a specific slot's input
            zeroInputWaits[(int)slot] = waitTime;
            zeroInputs[(int)slot]     = true;
        }

        //reset smartControl values
        if (_smartControls != null)
        {
            for (int i = 0; i < _smartControls.Length; i++)
            {
                _smartControls[i].ResetAllValues(slot);
            }
        }
    }
Exemple #7
0
        public float GetValue(InputDeviceSlot slot, bool getRawValue, out bool prefersDeltaUse)
        {
            prefersDeltaUse = true;             // Defaults to true, but doesn't matter because when default, the value returned is 0
            if ((int)slot >= controlValues.Length)
            {
                return(0f);                                             //not a slot we have any input info for
            }
            prefersDeltaUse = valuePrefersDeltaUse[(int)slot];

            //if this input is checking a framerate independent input like a mouse, return the raw value regardless of getRawValue
            if (!prefersDeltaUse)
            {
                return(rawValues[(int)slot] * scales[(int)slot]);
            }

            //deadzone clipping
            if (Math.Abs(controlValues[(int)slot]) < deadzone)
            {
                return(0f);
            }

            if (getRawValue)
            {
                //return the raw value
                return(rawValues[(int)slot] * scales[(int)slot]);
            }

            //return the smoothed value
            return(controlValues[(int)slot] * scales[(int)slot]);
        }
Exemple #8
0
    public static bool PrefersDeltaUse(string controlName, InputDeviceSlot slot)
    {
        SinputUpdate();

        bool preferDelta = true;

        controlFound = false;

        if (controlName == "")
        {
            return(false);
        }
        float axisVal = 0f;

        for (int i = 0; i < _controls.Length; i++)
        {
            if (_controls[i].name == controlName)
            {
                controlFound = true;
                float v = _controls[i].GetAxisState(slot);
                if (Mathf.Abs(v) > axisVal)
                {
                    axisVal     = v;
                    preferDelta = _controls[i].GetAxisStateDeltaPreference(slot);
                }
            }
        }

        //now check smart controls for framerate independence
        for (int i = 0; i < _smartControls.Length; i++)
        {
            if (_smartControls[i].name == controlName)
            {
                controlFound = true;
                float v = _smartControls[i].GetValue(slot, true);
                if (Mathf.Abs(v) > axisVal)
                {
                    axisVal = v;

                    if (!PrefersDeltaUse(_smartControls[i].positiveControl, slot) || !PrefersDeltaUse(_smartControls[i].negativeControl, slot))
                    {
                        preferDelta = false;
                    }
                }
            }
        }

        if (!controlFound)
        {
            Debug.LogError("Sinput Error: Control \"" + controlName + "\" not found in list of Controls or SmartControls.");
        }

        return(preferDelta);
    }
Exemple #9
0
 private bool ButtonCheck(ButtonAction bAction, InputDeviceSlot slot)
 {
     for (int i = 0; i < inputs.Count; i++)
     {
         if (inputs[i].ButtonCheck(bAction, slot))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #10
0
 /// <summary>
 /// gets scale of a smart control
 /// </summary>
 /// <param name="smartControlName"></param>
 /// <param name="slot"></param>
 /// <returns></returns>
 public static float GetScale(string smartControlName, InputDeviceSlot slot = InputDeviceSlot.any)
 {
     for (int i = 0; i < _smartControls.Length; i++)
     {
         if (_smartControls[i].name == smartControlName)
         {
             return(_smartControls[i].scales[(int)slot]);
         }
     }
     Debug.LogError("Sinput Error: Smart Control \"" + smartControlName + "\" not found in list of SmartControls.");
     return(1f);
 }
Exemple #11
0
        void UpdateControlState(ControlState controlState, InputDeviceSlot slot)
        {
            var wasHeld = controlState.held;

            controlState.held = false;

            controlState.value = 0f;
            controlState.valuePrefersDeltaUse = true;

            foreach (var input in inputs)
            {
                var v = input.AxisCheck(slot);

                //update axis-as-button and button state (When checking axis we also check for button state)
                switch (input.inputType)
                {
                case InputDeviceType.GamepadAxis:
                    controlState.held |= v > input.axisButtoncompareVal;
                    break;

                case InputDeviceType.Mouse:
                    controlState.held |= Math.Abs(v) > 0.5f;
                    break;

                case InputDeviceType.Keyboard:
                case InputDeviceType.GamepadButton:
                    controlState.held |= v == 1;
                    break;

                case InputDeviceType.Virtual:
                    // Meh. Would be better to unify GetVirtualButton and GetVirtualAxis
                    controlState.held |= VirtualInputs.GetVirtualButton(input.virtualInputID);
                    break;

                case InputDeviceType.XR:
                    // TO DO
                    break;
                }

                if (Math.Abs(v) > Math.Abs(controlState.value))
                {
                    //this is the value we're going with
                    controlState.value = v;
                    //now find out if what set this value was something we shouldn't multiply by deltaTime
                    controlState.valuePrefersDeltaUse =
                        input.inputType != InputDeviceType.Mouse ||
                        input.mouseInputType <MouseInputType.MouseMoveLeft ||
                                              input.mouseInputType> MouseInputType.MouseScroll;
                }
            }

            UpdateButtonStates(controlState, wasHeld);
        }
Exemple #12
0
 /// <summary>
 /// returns true if a smart control is inverted
 /// </summary>
 /// <param name="smartControlName"></param>
 /// <param name="slot"></param>
 /// <returns></returns>
 public static bool GetInverted(string smartControlName, InputDeviceSlot slot = InputDeviceSlot.any)
 {
     SinputUpdate();
     for (int i = 0; i < _smartControls.Length; i++)
     {
         if (_smartControls[i].name == smartControlName)
         {
             return(_smartControls[i].inversion[(int)slot]);
         }
     }
     Debug.LogError("Sinput Error: Smart Control \"" + smartControlName + "\" not found in list of SmartControls.");
     return(false);
 }
Exemple #13
0
    static float AxisCheck(string controlName, InputDeviceSlot slot, bool getRawValue = false)
    {
        SinputUpdate();
        if (zeroInputs[(int)slot])
        {
            return(0f);
        }

        controlFound = false;

        if (controlName == "")
        {
            return(0f);
        }

        float returnV = 0f;

        for (int i = 0; i < _controls.Length; i++)
        {
            if (_controls[i].name == controlName)
            {
                controlFound = true;
                float v = _controls[i].GetAxisState(slot);
                if (Mathf.Abs(v) > returnV)
                {
                    returnV = v;
                }
            }
        }

        for (int i = 0; i < _smartControls.Length; i++)
        {
            if (_smartControls[i].name == controlName)
            {
                controlFound = true;
                float v = _smartControls[i].GetValue(slot, getRawValue);
                if (Mathf.Abs(v) > returnV)
                {
                    returnV = v;
                }
            }
        }

        if (!controlFound)
        {
            Debug.LogError("Sinput Error: Control \"" + controlName + "\" not found in list of Controls or SmartControls.");
        }

        return(returnV);
    }
Exemple #14
0
    static Vector2 Vector2Check(string controlNameA, string controlNameB, InputDeviceSlot slot, bool normalClip)
    {
        SinputUpdate();

        returnVec2   = Vector2.zero;
        returnVec2.x = AxisCheck(controlNameA, slot);
        returnVec2.y = AxisCheck(controlNameB, slot);

        if (normalClip && returnVec2.magnitude > 1f)
        {
            returnVec2.Normalize();
        }

        return(returnVec2);
    }
Exemple #15
0
        void UpdateControlState(int i, InputDeviceSlot slot)
        {
            controlStates[i].value = AxisCheck(slot, out controlStates[i].valuePrefersDeltaUse);

            controlStates[i].held     = ButtonCheck(ButtonAction.HELD, slot);
            controlStates[i].pressed  = ButtonCheck(ButtonAction.DOWN, slot);
            controlStates[i].released = ButtonCheck(ButtonAction.UP, slot);


            controlStates[i].toggleReleased = false;
            controlStates[i].togglePressed  = false;
            if (controlStates[i].pressed)
            {
                if (controlStates[i].toggleHeld)
                {
                    controlStates[i].toggleHeld     = false;
                    controlStates[i].toggleReleased = true;
                }
                else
                {
                    controlStates[i].toggleHeld    = true;
                    controlStates[i].togglePressed = true;
                }
            }



            controlStates[i].repeatPressed = false;
            if (controlStates[i].pressed)
            {
                controlStates[i].repeatPressed = true;                                      //repeat press returns true on first frame down
            }
            if (controlStates[i].held)
            {
                controlStates[i].holdTime   += Time.deltaTime;
                controlStates[i].repeatTime -= Time.deltaTime;
                if (controlStates[i].holdTime > Sinput.buttonRepeatWait && controlStates[i].repeatTime < 0f)
                {
                    controlStates[i].repeatTime    = Sinput.buttonRepeat;
                    controlStates[i].repeatPressed = true;
                }
            }
            else
            {
                controlStates[i].holdTime   = 0f;
                controlStates[i].repeatTime = 0f;
            }
        }
Exemple #16
0
 public void ResetAllValues(InputDeviceSlot slot)
 {
     //set all values for this control to 0
     if (slot == InputDeviceSlot.any)
     {
         for (int i = 0; i < controlValues.Length; i++)
         {
             rawValues[i]            = 0f;
             controlValues[i]        = 0f;
             valuePrefersDeltaUse[i] = true;
         }
     }
     else
     {
         rawValues[(int)slot]            = 0f;
         controlValues[(int)slot]        = 0f;
         valuePrefersDeltaUse[(int)slot] = true;
     }
 }
Exemple #17
0
        //button checks
        public bool GetButtonState(ButtonAction bAction, InputDeviceSlot slot, bool getRaw)
        {
            if (!getRaw && isToggle)
            {
                if (bAction == ButtonAction.HELD)
                {
                    return(controlStates[(int)slot].toggleHeld);
                }
                if (bAction == ButtonAction.DOWN)
                {
                    return(controlStates[(int)slot].togglePressed);
                }
                if (bAction == ButtonAction.UP)
                {
                    return(controlStates[(int)slot].toggleReleased);
                }
            }
            else
            {
                if (bAction == ButtonAction.HELD)
                {
                    return(controlStates[(int)slot].held);
                }
                if (bAction == ButtonAction.DOWN)
                {
                    if (null == controlStates)
                    {
                        Debug.Log("yup");
                    }
                    return(controlStates[(int)slot].pressed);
                }
                if (bAction == ButtonAction.UP)
                {
                    return(controlStates[(int)slot].released);
                }
            }
            if (bAction == ButtonAction.REPEATING)
            {
                return(controlStates[(int)slot].repeatPressed);
            }

            return(false);
        }
Exemple #18
0
    static bool ButtonCheck(string controlName, InputDeviceSlot slot, ButtonAction bAction, bool getRawValue = false)
    {
        SinputUpdate();
        if (zeroInputs[(int)slot])
        {
            return(false);
        }

        controlFound = false;

        for (int i = 0; i < _controls.Length; i++)
        {
            if (_controls[i].name == controlName)
            {
                controlFound = true;
                if (_controls[i].GetButtonState(bAction, slot, getRawValue))
                {
                    return(true);
                }
            }
        }

        for (int i = 0; i < _smartControls.Length; i++)
        {
            if (_smartControls[i].name == controlName)
            {
                controlFound = true;
                if (_smartControls[i].ButtonCheck(bAction, slot))
                {
                    return(true);
                }
            }
        }

        if (!controlFound)
        {
            Debug.LogError("Sinput Error: Control \"" + controlName + "\" not found in list of controls or SmartControls.");
        }

        return(false);
    }
Exemple #19
0
        void UpdateControlState(int i, InputDeviceSlot slot)
        {
            controlStates[i].value = 0f;
            controlStates[i].valuePrefersDeltaUse = true;
            controlStates[i].axisAsButtonHeld     = false;

            for (int inpt = 0; inpt < inputs.Count; inpt++)
            {
                v = inputs[inpt].AxisCheck(slot);

                //update axis-as-button state
                if (inputs[inpt].inputType == InputDeviceType.GamepadAxis)
                {
                    if (v > inputs[inpt].axisButtoncompareVal)
                    {
                        controlStates[i].axisAsButtonHeld = true;
                    }
                }
                if (inputs[inpt].inputType == InputDeviceType.Mouse)
                {
                    if (Mathf.Abs(v) > 0.5f)
                    {
                        controlStates[i].axisAsButtonHeld = true;
                    }
                }

                if (Mathf.Abs(v) > controlStates[i].value)
                {
                    //this is the value we're going with
                    controlStates[i].value = v;
                    //now find out if what set this value was something we shouldn't multiply by deltaTime
                    controlStates[i].valuePrefersDeltaUse = true;
                    if (inputs[inpt].inputType == InputDeviceType.Mouse)
                    {
                        if (inputs[inpt].mouseInputType == MouseInputType.MouseMoveLeft || inputs[inpt].mouseInputType == MouseInputType.MouseMoveRight ||
                            inputs[inpt].mouseInputType == MouseInputType.MouseMoveUp || inputs[inpt].mouseInputType == MouseInputType.MouseMoveDown ||
                            inputs[inpt].mouseInputType == MouseInputType.MouseHorizontal || inputs[inpt].mouseInputType == MouseInputType.MouseVertical ||
                            inputs[inpt].mouseInputType == MouseInputType.MouseScrollUp || inputs[inpt].mouseInputType == MouseInputType.MouseScrollDown ||
                            inputs[inpt].mouseInputType == MouseInputType.MouseScroll)
                        {
                            controlStates[i].valuePrefersDeltaUse = false;
                        }
                    }
                }
            }
            //controlStates[i].value = AxisCheck(slot, out controlStates[i].valuePrefersDeltaUse, out controlStates[i].axisAsButtonHeld);

            //check if this control is held
            wasHeld = controlStates[i].held;
            controlStates[i].held = false;
            for (int inpt = 0; inpt < inputs.Count; inpt++)
            {
                if (inputs[inpt].ButtonHeldCheck(slot))
                {
                    controlStates[i].held = true;
                }
            }
            //controlStates[i].pressed = ButtonCheck(ButtonAction.DOWN, slot);
            //controlStates[i].released = ButtonCheck(ButtonAction.UP, slot);

            //held state
            if (wasHeld)
            {
                controlStates[i].pressed = false;
                if (controlStates[i].axisAsButtonHeld || controlStates[i].held)
                {
                    controlStates[i].held     = true;
                    controlStates[i].released = false;
                }
                else
                {
                    controlStates[i].held     = false;
                    controlStates[i].released = true;
                }
            }
            else
            {
                controlStates[i].released = false;
                if (controlStates[i].axisAsButtonHeld || controlStates[i].held)
                {
                    controlStates[i].held    = true;
                    controlStates[i].pressed = true;
                }
                else
                {
                    controlStates[i].held    = false;
                    controlStates[i].pressed = false;
                }
            }

            //toggled state
            controlStates[i].toggleReleased = false;
            controlStates[i].togglePressed  = false;
            if (controlStates[i].pressed)
            {
                if (controlStates[i].toggleHeld)
                {
                    controlStates[i].toggleHeld     = false;
                    controlStates[i].toggleReleased = true;
                }
                else
                {
                    controlStates[i].toggleHeld    = true;
                    controlStates[i].togglePressed = true;
                }
            }


            //repeating press state
            controlStates[i].repeatPressed = false;
            if (controlStates[i].pressed)
            {
                controlStates[i].repeatPressed = true;                                      //repeat press returns true on first frame down
            }
            if (controlStates[i].held)
            {
                controlStates[i].holdTime   += Time.deltaTime;
                controlStates[i].repeatTime -= Time.deltaTime;
                if (controlStates[i].holdTime > Sinput.buttonRepeatWait && controlStates[i].repeatTime < 0f)
                {
                    controlStates[i].repeatTime    = Sinput.buttonRepeat;
                    controlStates[i].repeatPressed = true;
                }
            }
            else
            {
                controlStates[i].holdTime   = 0f;
                controlStates[i].repeatTime = 0f;
            }
        }
Exemple #20
0
 //axis checks
 public float GetAxisState(InputDeviceSlot slot)
 {
     return(controlStates[(int)slot].value);
 }
Exemple #21
0
 public bool GetAxisStateDeltaPreference(InputDeviceSlot slot)
 {
     return(controlStates[(int)slot].valuePrefersDeltaUse);
 }
Exemple #22
0
 /// <summary>
 /// Returns true if a Sinput Control or Smart Control was Pressed this frame, or if it has been held long enough to start repeating.
 /// <para>Use this for menu scrolling inputs</para>
 /// </summary>
 /// <param name="controlName"></param>
 /// <param name="slot"></param>
 /// <returns></returns>
 public static bool GetButtonDownRepeating(string controlName, InputDeviceSlot slot)
 {
     return(ButtonCheck(controlName, slot, ButtonAction.REPEATING));
 }
Exemple #23
0
 /// <summary>
 /// Returns true if a Sinput Control or Smart Control was Released this frame, regardless of the Control's toggle setting.
 /// </summary>
 /// <param name="controlName"></param>
 /// <param name="slot"></param>
 /// <returns></returns>
 public static bool GetButtonUpRaw(string controlName, InputDeviceSlot slot)
 {
     return(ButtonCheck(controlName, slot, ButtonAction.UP, true));
 }
Exemple #24
0
        public float AxisCheck(InputDeviceSlot slot)
        {
            //keyboard checks
            if (inputType == InputDeviceType.Keyboard)
            {
                if (slot == InputDeviceSlot.any || slot == InputDeviceSlot.keyboard || slot == InputDeviceSlot.keyboardAndMouse)
                {
                    if (Input.GetKey(keyboardKeyCode))
                    {
                        return(1f);
                    }
                }

                return(0f);
            }

            //gamepad button and axis checks
            if (inputType == InputDeviceType.GamepadButton || inputType == InputDeviceType.GamepadAxis)
            {
                if (slot == InputDeviceSlot.keyboard || slot == InputDeviceSlot.mouse || slot == InputDeviceSlot.keyboardAndMouse)
                {
                    return(0f);
                }

                //if checking any slot, call this function for each possible slot
                if (slot == InputDeviceSlot.any)
                {
                    float greatestV = 0f;
                    for (int i = 1; i <= Sinput.gamepads.Length; i++)
                    {
                        greatestV = Mathf.Max(greatestV, Mathf.Abs(AxisCheck((InputDeviceSlot)i)));
                    }
                    return(greatestV);
                }

                int slotIndex = ((int)slot) - 1;



                //don't check slots without a connected gamepad
                if (Sinput.gamepads.Length <= slotIndex)
                {
                    return(0f);
                }

                //make sure the gamepad in this slot is one this input is allowed to check (eg don't check PS4 pad bindings for an XBOX pad)
                bool allowInputFromThisPad = false;
                for (int i = 0; i < allowedSlots.Length; i++)
                {
                    if (slotIndex == allowedSlots[i])
                    {
                        allowInputFromThisPad = true;
                    }
                }

                if (!allowInputFromThisPad)
                {
                    return(0f);
                }

                //button as axis checks
                if (inputType == InputDeviceType.GamepadButton)
                {
                    string buttonString = string.Format("Joystick{0}Button{1}", (slotIndex + 1), gamepadButtonNumber);
                    if (string.IsNullOrEmpty(buttonString))
                    {
                        return(0f);
                    }
                    UnityGamepadKeyCode keyCode = (UnityGamepadKeyCode)System.Enum.Parse(typeof(UnityGamepadKeyCode), buttonString);

                    //button check now
                    if (Input.GetKey((KeyCode)(int)keyCode))
                    {
                        return(1f);
                    }
                }

                //gamepad axis check
                if (inputType == InputDeviceType.GamepadAxis)
                {
                    string axisString = string.Format("J_{0}_{1}", (slotIndex + 1), gamepadAxisNumber);
                    float  axisValue  = Input.GetAxisRaw(axisString);
                    if (invertAxis)
                    {
                        axisValue *= -1f;
                    }
                    if (rescaleAxis)
                    {
                        //some gamepad axis are -1 to 1 or something when you want them as 0 to 1, EG; triggers on XBONE pad on OSX
                        axisValue = Mathf.InverseLerp(rescaleAxisMin, rescaleAxisMax, axisValue);
                    }

                    if (clampAxis)
                    {
                        axisValue = Mathf.Clamp01(axisValue);
                    }

                    //we return every axis' default value unless we measure a change first
                    //this prevents weird snapping and false button presses if the pad is reporting a weird value to start with
                    if (useDefaultAxisValue)
                    {
                        if (measuredAxisValue != -54.321f)
                        {
                            if (axisValue != measuredAxisValue)
                            {
                                useDefaultAxisValue = false;
                            }
                        }
                        else
                        {
                            measuredAxisValue = axisValue;
                        }
                        if (useDefaultAxisValue)
                        {
                            axisValue = defaultAxisValue;
                        }
                    }

                    return(axisValue);
                }

                return(0f);
            }


            //virtual device axis input checks
            if (inputType == InputDeviceType.Virtual)
            {
                if (slot == InputDeviceSlot.any || slot == InputDeviceSlot.virtual1)
                {
                    return(VirtualInputs.GetVirtualAxis(virtualInputID));
                }
                //return virtualAxisValue;
            }

            //mouseaxis button checks (these don't happen)
            if (inputType == InputDeviceType.Mouse)
            {
                if (slot != InputDeviceSlot.any && slot != InputDeviceSlot.mouse && slot != InputDeviceSlot.keyboardAndMouse)
                {
                    return(0f);
                }

                switch (mouseInputType)
                {
                case MouseInputType.MouseHorizontal:
                    return(Input.GetAxisRaw("Mouse Horizontal") * Sinput.mouseSensitivity);

                case MouseInputType.MouseMoveLeft:
                    return(Mathf.Min(Input.GetAxisRaw("Mouse Horizontal") * Sinput.mouseSensitivity, 0f) * -1f);

                case MouseInputType.MouseMoveRight:
                    return(Mathf.Max(Input.GetAxisRaw("Mouse Horizontal") * Sinput.mouseSensitivity, 0f));

                case MouseInputType.MouseMoveUp:
                    return(Mathf.Max(Input.GetAxisRaw("Mouse Vertical") * Sinput.mouseSensitivity, 0f));

                case MouseInputType.MouseMoveDown:
                    return(Mathf.Min(Input.GetAxisRaw("Mouse Vertical") * Sinput.mouseSensitivity, 0f) * -1f);

                case MouseInputType.MouseVertical:
                    return(Input.GetAxisRaw("Mouse Vertical") * Sinput.mouseSensitivity);

                case MouseInputType.MouseScroll:
                    return(Input.GetAxisRaw("Mouse Scroll"));

                case MouseInputType.MouseScrollUp:
                    return(Mathf.Max(Input.GetAxisRaw("Mouse Scroll"), 0f));

                case MouseInputType.MouseScrollDown:
                    return(Mathf.Min(Input.GetAxisRaw("Mouse Scroll"), 0f) * -1f);

                case MouseInputType.MousePositionX:
                    return(Input.mousePosition.x);

                case MouseInputType.MousePositionY:
                    return(Input.mousePosition.y);

                default:
                    //it's a click type mouse input
                    if (Input.GetKey((KeyCode)(System.Enum.Parse(typeof(KeyCode), mouseInputType.ToString()))))
                    {
                        return(1f);
                    }
                    break;
                }
                //return Input.GetAxisRaw(mouseAxis);
            }

            return(0f);
        }
Exemple #25
0
 /// <summary>
 /// Returns a Vector3 made with GetAxis() values applied to x, y, and z
 /// </summary>
 /// <param name="controlNameA"></param>
 /// <param name="controlNameB"></param>
 /// <returns></returns>
 public static Vector3 GetVector(string controlNameA, string controlNameB, string controlNameC, InputDeviceSlot slot)
 {
     return(Vector3Check(controlNameA, controlNameB, controlNameC, slot, true));
 }
Exemple #26
0
 public float GetValue(InputDeviceSlot slot)
 {
     return(GetValue(slot, false));
 }
Exemple #27
0
    static Vector3 Vector3Check(string controlNameA, string controlNameB, string controlNameC, InputDeviceSlot slot, bool normalClip)
    {
        SinputUpdate();

        returnVec3   = Vector3.zero;
        returnVec3.x = AxisCheck(controlNameA, slot);
        returnVec3.y = AxisCheck(controlNameB, slot);
        returnVec3.z = AxisCheck(controlNameC, slot);

        if (normalClip && returnVec3.magnitude > 1f)
        {
            returnVec3.Normalize();
        }

        return(returnVec3);
    }
Exemple #28
0
 /// <summary>
 /// Returns a Vector3 made with GetAxis() values applied to x, y, and z
 /// </summary>
 /// <param name="controlNameA"></param>
 /// <param name="controlNameB"></param>
 /// <returns></returns>
 public static Vector3 GetVector(string controlNameA, string controlNameB, string controlNameC, InputDeviceSlot slot, bool normalClip)
 {
     return(Vector3Check(controlNameA, controlNameB, controlNameC, slot, normalClip));
 }
Exemple #29
0
        //public float virtualAxisValue;


        public bool ButtonCheck(ButtonAction bAction, InputDeviceSlot slot)
        {
            //keyboard key checks
            if (inputType == InputDeviceType.Keyboard)
            {
                if (slot == InputDeviceSlot.any || slot == InputDeviceSlot.keyboard || slot == InputDeviceSlot.keyboardAndMouse)
                {
                    if (bAction == ButtonAction.HELD)
                    {
                        return(Input.GetKey(keyboardKeyCode));
                    }
                    if (bAction == ButtonAction.DOWN)
                    {
                        return(Input.GetKeyDown(keyboardKeyCode));
                    }
                    if (bAction == ButtonAction.UP)
                    {
                        return(Input.GetKeyUp(keyboardKeyCode));
                    }
                }

                return(false);
            }

            //gamepad button checks
            if (inputType == InputDeviceType.GamepadButton || inputType == InputDeviceType.GamepadAxis)
            {
                if (slot == InputDeviceSlot.keyboard || slot == InputDeviceSlot.mouse || slot == InputDeviceSlot.keyboardAndMouse)
                {
                    return(false);
                }

                //if checking any slot, call this function for each possible slot
                if (slot == InputDeviceSlot.any)
                {
                    return(ButtonCheck(bAction, InputDeviceSlot.gamepad1) || ButtonCheck(bAction, InputDeviceSlot.gamepad2) || ButtonCheck(bAction, InputDeviceSlot.gamepad3) || ButtonCheck(bAction, InputDeviceSlot.gamepad4) || ButtonCheck(bAction, InputDeviceSlot.gamepad5) || ButtonCheck(bAction, InputDeviceSlot.gamepad6) || ButtonCheck(bAction, InputDeviceSlot.gamepad7) || ButtonCheck(bAction, InputDeviceSlot.gamepad7) || ButtonCheck(bAction, InputDeviceSlot.gamepad9) || ButtonCheck(bAction, InputDeviceSlot.gamepad10) || ButtonCheck(bAction, InputDeviceSlot.gamepad11) || ButtonCheck(bAction, InputDeviceSlot.gamepad12) || ButtonCheck(bAction, InputDeviceSlot.gamepad13) || ButtonCheck(bAction, InputDeviceSlot.gamepad14) || ButtonCheck(bAction, InputDeviceSlot.gamepad15) || ButtonCheck(bAction, InputDeviceSlot.gamepad16));
                }

                int slotIndex = ((int)slot) - 1;

                //don't check slots without a connected gamepad
                if (Sinput.gamepads.Length <= slotIndex)
                {
                    return(false);
                }

                //make sure the gamepad in this slot is one this input is allowed to check (eg don't check PS4 pad bindings for an XBOX pad)
                bool allowInputFromThisPad = false;
                for (int i = 0; i < allowedSlots.Length; i++)
                {
                    if (slotIndex == allowedSlots[i])
                    {
                        allowInputFromThisPad = true;
                    }
                }
                if (!allowInputFromThisPad)
                {
                    return(false);
                }

                //gamepad button check
                if (inputType == InputDeviceType.GamepadButton)
                {
                    //get the keycode for the gamepad's slot/button
                    string buttonString = string.Format("Joystick{0}Button{1}", (slotIndex + 1), gamepadButtonNumber);
                    if (string.IsNullOrEmpty(buttonString))
                    {
                        return(false);
                    }
                    UnityGamepadKeyCode keyCode = (UnityGamepadKeyCode)System.Enum.Parse(typeof(UnityGamepadKeyCode), buttonString);

                    //button check now
                    if (bAction == ButtonAction.HELD)
                    {
                        return(Input.GetKey((KeyCode)(int)keyCode));
                    }
                    if (bAction == ButtonAction.DOWN)
                    {
                        return(Input.GetKeyDown((KeyCode)(int)keyCode));
                    }
                    if (bAction == ButtonAction.UP)
                    {
                        return(Input.GetKeyUp((KeyCode)(int)keyCode));
                    }
                }

                //gamepad axis as a button check
                if (inputType == InputDeviceType.GamepadAxis)
                {
                    if (bAction == axisButtonState[slotIndex + 1])
                    {
                        return(true);
                    }
                    if (bAction == ButtonAction.HELD && axisButtonState[slotIndex + 1] == ButtonAction.DOWN)
                    {
                        return(true);
                    }

                    return(false);
                }

                return(false);
            }


            //virtual device input checks
            if (inputType == InputDeviceType.Virtual)
            {
                if (slot == InputDeviceSlot.any || slot == InputDeviceSlot.virtual1)
                {
                    virtualInputState = VirtualInputs.GetVirtualButton(virtualInputID);
                    if (bAction == virtualInputState)
                    {
                        return(true);
                    }
                    if (bAction == ButtonAction.HELD && virtualInputState == ButtonAction.DOWN)
                    {
                        return(true);
                    }
                }
            }

            //mouseaxis button checks (these don't happen)
            if (inputType == InputDeviceType.Mouse)
            {
                if (slot != InputDeviceSlot.any && slot != InputDeviceSlot.mouse && slot != InputDeviceSlot.keyboardAndMouse)
                {
                    return(false);
                }

                KeyCode mouseKeyCode = KeyCode.None;
                if (mouseInputType == MouseInputType.Mouse0)
                {
                    mouseKeyCode = KeyCode.Mouse0;
                }
                if (mouseInputType == MouseInputType.Mouse1)
                {
                    mouseKeyCode = KeyCode.Mouse1;
                }
                if (mouseInputType == MouseInputType.Mouse2)
                {
                    mouseKeyCode = KeyCode.Mouse2;
                }
                if (mouseInputType == MouseInputType.Mouse3)
                {
                    mouseKeyCode = KeyCode.Mouse3;
                }
                if (mouseInputType == MouseInputType.Mouse4)
                {
                    mouseKeyCode = KeyCode.Mouse4;
                }
                if (mouseInputType == MouseInputType.Mouse5)
                {
                    mouseKeyCode = KeyCode.Mouse5;
                }
                if (mouseInputType == MouseInputType.Mouse6)
                {
                    mouseKeyCode = KeyCode.Mouse6;
                }

                if (mouseKeyCode != KeyCode.None)
                {
                    //clicky mouse input
                    if (bAction == ButtonAction.HELD)
                    {
                        return(Input.GetKey(mouseKeyCode));
                    }
                    if (bAction == ButtonAction.DOWN)
                    {
                        return(Input.GetKeyDown(mouseKeyCode));
                    }
                    if (bAction == ButtonAction.UP)
                    {
                        return(Input.GetKeyUp(mouseKeyCode));
                    }
                }
                else
                {
                    //mouse axis as button input
                    if (bAction == axisButtonState[0])
                    {
                        return(true);
                    }
                    if (bAction == ButtonAction.HELD && axisButtonState[0] == ButtonAction.DOWN)
                    {
                        return(true);
                    }
                }

                return(false);
            }

            return(false);
        }
Exemple #30
0
 /// <summary>
 /// Returns the raw value of a Sinput Control or Smart Control
 /// </summary>
 /// <param name="controlName"></param>
 /// <param name="slot"></param>
 /// <returns></returns>
 public static float GetAxisRaw(string controlName, InputDeviceSlot slot)
 {
     return(AxisCheck(controlName, slot, true));
 }