예제 #1
0
        public void AddBinding(IInputSource source, Action onRebindComplete)
        {
            if (m_rebindState == RebindState.None)
            {
                if (source is BufferedButton)
                {
                    m_rebindState     = RebindState.Button;
                    m_rebindingButton = (BufferedButton)source;
                }
                else if (source is BufferedAxis)
                {
                    m_rebindState   = RebindState.Axis;
                    m_rebindingAxis = (BufferedAxis)source;
                }

                m_onRebindComplete         = onRebindComplete;
                m_rebindingPreviousKeys    = FindActiveKeys(false);
                m_rebindingPreviousButtons = FindActiveButtons(false);
            }
        }
예제 #2
0
        /*
         * When rebinding detects any appropriate inputs.
         */
        public void UpdateRebinding()
        {
            if (m_rebindState != RebindState.None)
            {
                if (m_rebindState == RebindState.Axis)
                {
                    ISource <float> source = GetAxisSource();
                    if (source != null)
                    {
                        m_rebindState = RebindState.None;
                        m_rebindingAxis.AddSource(source);
                        m_onRebindComplete();
                    }
                    else
                    {
                        List <KeyCode>       activeKeys    = FindActiveKeys(true);
                        List <GamepadButton> activeButtons = FindActiveButtons(true);
                        if (activeButtons.Count > 0)
                        {
                            m_rebindState         = RebindState.ButtonAxis;
                            m_rebindingAxisButton = activeButtons.First();
                        }
                        else if (activeKeys.Count > 0)
                        {
                            m_rebindState      = RebindState.KeyAxis;
                            m_rebindingAxisKey = activeKeys.First();
                        }
                    }
                }
                else if (m_rebindState == RebindState.Button)
                {
                    ISource <bool> source = GetButtonSource();
                    if (source != null)
                    {
                        m_rebindState = RebindState.None;
                        m_rebindingButton.AddSource(source);
                        m_onRebindComplete();
                    }
                }
                else if (m_rebindState == RebindState.ButtonAxis)
                {
                    List <GamepadButton> activeButtons = FindActiveButtons(true);
                    if (activeButtons.Count > 0)
                    {
                        m_rebindState = RebindState.None;
                        m_rebindingAxis.AddSource(new JoystickButtonAxis(activeButtons.First(), m_rebindingAxisButton));
                        m_onRebindComplete();
                    }
                }
                else if (m_rebindState == RebindState.KeyAxis)
                {
                    List <KeyCode> activeKeys = FindActiveKeys(true);
                    if (activeKeys.Count > 0)
                    {
                        m_rebindState = RebindState.None;
                        m_rebindingAxis.AddSource(new KeyAxis(activeKeys.First(), m_rebindingAxisKey));
                        m_onRebindComplete();
                    }
                }

                m_rebindingPreviousKeys    = FindActiveKeys(false);
                m_rebindingPreviousButtons = FindActiveButtons(false);
            }
        }