Пример #1
0
    void AssignController()
    {
        if ((m_prevGpdState.Buttons.Back == ButtonState.Released && m_gpdState.Buttons.Back == ButtonState.Pressed) ||
            Input.GetKeyDown(KeyCode.Escape))
        {
            m_eWaitState = InputWaitState.INPUT_NONE;

            // Detactivate darken panel, re-enable the button and select it.
            m_darkPanel.SetActive(false);
            m_controllerButtonTexts[m_nControlIndex].GetComponentInParent <Button>().interactable = true;
            m_events.SetSelectedGameObject(m_controllerButtonTexts[m_nControlIndex].transform.parent.gameObject);

            return;
        }

        // Get button or axis input.
        int button = GetButton();
        int axis   = GetAxis();

        // Assign button or axis if detected.
        if (button > -1)
        {
            // Set data to be written to a file.
            m_currentData.m_buttons[m_nControlIndex]   = (PlayerInput.EGamePadButton)button;
            m_currentData.m_bIsButton[m_nControlIndex] = true;

            m_controllerButtonTexts[m_nControlIndex].text = m_buttonNames[button];

            // Disable wait state and refuse input for 2 more frames.
            m_nWaitFrames = 2;
            m_eWaitState  = InputWaitState.INPUT_NONE;
            // Mark as changes made.
            m_bChangesMade = true;

            // Detactivate darken panel, re-enable the button and select it.
            m_darkPanel.SetActive(false);
            m_controllerButtonTexts[m_nControlIndex].GetComponentInParent <Button>().interactable = true;
            m_events.SetSelectedGameObject(m_controllerButtonTexts[m_nControlIndex].transform.parent.gameObject);

            return;
        }
        else if (axis > -1)
        {
            // Set data to be written to a file.
            m_currentData.m_axes[m_nControlIndex] = (PlayerInput.EGamePadAxis)axis;

            m_controllerButtonTexts[m_nControlIndex].text = m_axisNames[axis];

            // Disable wait state and refuse input for 2 more frames.
            m_nWaitFrames = 2;
            m_eWaitState  = InputWaitState.INPUT_NONE;
            // Mark as changes made.
            m_bChangesMade = true;

            // Detactivate darken panel, re-enable the button and select it.
            m_darkPanel.SetActive(false);
            m_controllerButtonTexts[m_nControlIndex].GetComponentInParent <Button>().interactable = true;
            m_events.SetSelectedGameObject(m_controllerButtonTexts[m_nControlIndex].transform.parent.gameObject);
        }
    }
Пример #2
0
    public void ActiveController(int nIndex)
    {
        if (m_nWaitFrames > 0)
        {
            return;
        }

        // Activate darken panel and disable button.
        m_darkPanel.SetActive(true);
        m_controllerButtonTexts[nIndex].GetComponentInParent <Button>().interactable = false;

        // Set controller input wait state and refuse input for two frames (to prevent last input from being read).
        m_eWaitState    = InputWaitState.INPUT_CONTROLLER;
        m_nWaitFrames   = 2;
        m_nControlIndex = nIndex;
    }
Пример #3
0
    void AssignKeyboard()
    {
        int key = -1;

        // Find which key was pressed (if any).
        foreach (KeyCode k in System.Enum.GetValues(typeof(KeyCode)))
        {
            if (Input.GetKeyDown(k))
            {
                key = (int)k;
            }
        }

        if ((KeyCode)key == KeyCode.Escape)
        {
            m_eWaitState = InputWaitState.INPUT_NONE;

            // Detactivate darken panel and re-enable the button.
            m_darkPanel.SetActive(false);
            m_keyboardButtonTexts[m_nControlIndex].GetComponentInParent <Button>().interactable = true;

            return;
        }

        // If a key was found assign it.
        if (key > -1)
        {
            m_currentData.m_keys[m_nControlIndex] = (KeyCode)key;

            m_keyboardButtonTexts[m_nControlIndex].GetComponentInChildren <Text>().text = ((KeyCode)key).ToString();

            m_eWaitState   = InputWaitState.INPUT_NONE;
            m_nWaitFrames  = 2;
            m_bChangesMade = true;

            // Detactivate darken panel and re-enable the button.
            m_darkPanel.SetActive(false);
            m_keyboardButtonTexts[m_nControlIndex].GetComponentInParent <Button>().interactable = true;
        }
    }