Beispiel #1
0
 /// <summary>
 /// starts up the controller
 /// sets up basic information for the controller
 /// </summary>
 /// <param name="a_ControllerIndex">index from controller array in InputManager</param>
 internal void startController(int a_ControllerIndex)
 {
     m_ControllerIndex = a_ControllerIndex;
     setCurrentController(m_ControllerIndex);
     m_IsXbox = isControllerXbox();
     m_Data   = new ControllerData();
 }
Beispiel #2
0
        /// <summary>
        /// updates this controllers button and axes values
        /// also updates whether the buttons were pressed or released this frame
        /// </summary>
        internal void updateController()
        {
            setCurrentController(m_ControllerIndex);
            m_IsActive = isControllerActive();
            if (!m_IsActive)
            {
                //small check to see if we should remove old data from the controller
                if (m_WasActive)
                {
                    m_WasActive = false;
                    //reset all controller information
                    m_Data = new ControllerData();
                }
                return;
            }

            m_WasActive = true;

            //go through 14 buttons, should change to number of buttons on the controller
            for (int i = 0; i < 14; i++)
            {
                bool last = m_Data.buttons[i];
                m_Data.buttons[i] = getButton(i) >= 1;
                //if the button is not different then normal, else if the last one was down then released else pressed
                m_Data.buttonStates[i] = last != m_Data.buttons[i] ? (last ? ButtonStates.Released : ButtonStates.Pressed) : ButtonStates.Normal;
            }
            for (int i = 0; i < 6; i++)
            {
                m_Data.axesValues[i] = getAxesValue(i) / 1000.0f;
                //todo make from deadzone to 1 be 0 to 1
                //todo map axes info to a square??
                //dead zone
                float deadZone = InputManager.getControllerDeadZone();
                if (Mathf.Abs(m_Data.axesValues[i]) <= deadZone)
                {
                    m_Data.axesValues[i] = 0;
                }
            }
            m_Data.hatSwitch = getPovDir();
        }