Example #1
0
    public override bool ApplyInputModify(InputScanResult data)
    {
        if (!EnableModify())
        {
            return(false);
        }

        var requestInputType = data.ScanType;

        switch (requestInputType)
        {
        case InputScanType.KeyboardButton:
            if (data.IsPositive)
            {
                m_positive.SetCustom(data.KeyCode);
            }
            else
            {
                m_negative.SetCustom(data.KeyCode);
            }
            break;

        case InputScanType.MouseAxis:
            m_axis.SetCustom(data.Axis);
            break;

        default:
            return(false);
        }

        return(true);
    }
    void ClearInput()
    {
        if (IsScanning)
        {
            IsScanning = false;

            if (m_scanHandler != null)
            {
                var result = new InputScanResult(m_curScaningSetting, InputResultType.Clear);
                m_scanHandler(result);
            }
        }
    }
    public void ForceStop()
    {
        if (IsScanning)
        {
            IsScanning = false;

            if (m_scanHandler != null)
            {
                var result = new InputScanResult(m_curScaningSetting, InputResultType.Cancel);
                m_scanHandler(result);
            }
        }
    }
    bool ScanMouseAxis()
    {
        for (int i = 0; i < m_rawMouseAxes.Length; i++)
        {
            if (IsAxisChange(m_rawMouseAxes[i]) && m_scanHandler != null)
            {
                var result = new InputScanResult(m_curScaningSetting, InputResultType.Success);
                result.Axis = i;

                if (m_scanHandler(result))
                {
                    m_scanHandler = null;
                    return(true);
                }
            }
        }
        return(false);
    }
    bool ScanJoystickAxis()
    {
        for (int i = 0; i < m_rawJoystickAxes.Length; i++)
        {
            if (IsAxisChange(m_rawJoystickAxes[i]) && m_scanHandler != null)
            {
                var result = new InputScanResult(m_curScaningSetting, InputResultType.Success);
                result.JoystickIndex = i / InputManager.JOYSTICK_AXIS_COUNT;
                result.Axis          = i % InputManager.JOYSTICK_AXIS_COUNT;

                if (m_scanHandler(result))
                {
                    m_scanHandler = null;
                    return(true);
                }
            }
        }
        return(false);
    }
    public override bool ApplyInputModify(InputScanResult data)
    {
        if (!EnableModify())
        {
            return(false);
        }

        switch (data.ScanType)
        {
        case InputScanType.JoystickButton:

            if (m_joystickMatchType == JoystickMatchType.FixedIndex)
            {
                m_joystickFixedIndex.SetCustom(data.JoystickIndex);
            }

            if (data.IsPositive)
            {
                m_positive.SetCustom(data.JoystickButton);
            }
            else
            {
                m_negative.SetCustom(data.JoystickButton);
            }

            break;

        case InputScanType.JoystickAxis:
            if (m_joystickMatchType == JoystickMatchType.FixedIndex)
            {
                m_joystickFixedIndex.SetCustom(data.JoystickIndex);
            }
            m_axis.SetCustom(data.Axis);

            break;

        default:
            return(false);
        }

        return(true);
    }
Example #7
0
    bool FinishScan(InputScanResult result)
    {
        if (result.ResultType == InputResultType.Cancel)
        {
            Text_input.text = GetUIStr();
            Debug.Log("scan end failed " + GetUIStr());
            return(false);
        }

        if (result.ResultType == InputResultType.Clear)
        {
            result.InputBinding.Clear();
            Text_input.text = GetUIStr();

            setting.CurKeyCode        = result.KeyCode;
            setting.CurJoystickAxis   = result.Axis;
            setting.CurJoystickButton = result.JoystickButton;
            setting.CurMouseAxis      = result.Axis;
            setting.CurJoystickIndex  = result.JoystickIndex;

            Debug.Log("scan end clear " + GetUIStr());
            return(true);
        }

        result.InputBinding.ApplyInputModify(result);

        setting.CurKeyCode        = result.KeyCode;
        setting.CurJoystickAxis   = result.Axis;
        setting.CurJoystickButton = result.JoystickButton;
        setting.CurMouseAxis      = result.Axis;
        setting.CurJoystickIndex  = result.JoystickIndex;

        Text_input.text = GetUIStr();
        Debug.Log("scan end success " + GetUIStr());

        return(true);
    }
    bool ScanJoystickButton()
    {
        int start = (int)KeyCode.Joystick1Button0;
        int end   = (int)KeyCode.Joystick8Button19;

        for (int i = start; i <= end; i++)
        {
            var curKey = (KeyCode)i;
            if (Input.GetKeyDown(curKey) && m_scanHandler != null)
            {
                var result = new InputScanResult(m_curScaningSetting, InputResultType.Success);
                result.JoystickIndex  = (i - start) / InputManager.JOYSTICK_BUTTON_COUNT;
                result.JoystickButton = ((JoystickButton)((i - start) % InputManager.JOYSTICK_BUTTON_COUNT));

                if (m_scanHandler(result))
                {
                    m_scanHandler = null;
                    return(true);
                }
            }
        }

        return(false);
    }
    /// <summary>
    /// 监测键盘输入
    /// </summary>
    /// <returns></returns>
    bool ScanKeyboardButton()
    {
        for (int i = 0, length = m_keys.Length; i < length; i++)
        {
            if ((int)m_keys[i] >= (int)KeyCode.JoystickButton0)
            {
                break;
            }

            if (Input.GetKeyDown(m_keys[i]) && m_scanHandler != null)
            {
                var result = new InputScanResult(m_curScaningSetting, InputResultType.Success);
                result.KeyCode = m_keys[i];

                if (m_scanHandler(result))
                {
                    m_scanHandler = null;
                    return(true);
                }
            }
        }

        return(false);
    }
Example #10
0
 /// <summary>
 /// 修改键位
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public abstract bool ApplyInputModify(InputScanResult data);