示例#1
0
    /// @brief	Colour inputs blue if they have just received a value-change callback.
    ///         Red if they are classed as Pressed. Dark grey otherwise.
    Color GCInputColor(int nControllerIndex, GameController.GCInput input)
    {
        if (m_inputValueChanged == input)
        {
            return(Color.blue);
        }

        if (GameController.GetInputPressed(nControllerIndex, input))
        {
            return(Color.red);
        }

        return(g_darkGrey);
    }
示例#2
0
    //////////////////////////////////////////////////////////////////////////
    /// @brief	Draw up to 4 controller statuses on screen using UnityGUI.
    ///         Call this from your own OnGUI function to overlay on other UnityGUI.
    //////////////////////////////////////////////////////////////////////////
    public void DrawGameControllerGUI()
    {
        Color      orgColor = GUI.color;
        TextAnchor orgAlign = GUI.skin.label.alignment;

#if UNITY_EDITOR
        int nNumControllers = 4;
#else
        int nNumControllers = GameController.GetNumControllers();
#endif

        float fControllerX      = Screen.width * 0.05f;
        float fControllerY      = Screen.width * 0.05f;
        float fControllerWidth  = Screen.width * 0.4f;
        float fControllerHeight = fControllerWidth * 0.5f;

        if (nNumControllers >= 1)
        {
            DrawController(0, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if (nNumControllers >= 2)
        {
            fControllerX += fControllerWidth + 5.0f;
            DrawController(1, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if (nNumControllers >= 3)
        {
            fControllerX  = Screen.width * 0.05f;
            fControllerY += fControllerHeight + 5.0f;
            DrawController(2, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if (nNumControllers >= 4)
        {
            fControllerX += fControllerWidth + 5.0f;
            DrawController(3, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if (Time.realtimeSinceStartup > m_fInputValueChangedTimeout)
        {
            m_inputValueChanged = GameController.GCInput.None;
        }

        GUI.color = orgColor;
        GUI.skin.label.alignment = orgAlign;
    }
示例#3
0
    /// @brief	Draw a coloured rectangle with a label to represent a button.
    void DrawButton(int nControllerIndex, GameController.GCInput input, Rect rect, String sLabel)
    {
        float fSnapshotValue = 0.0f;

        // Get input's value from the current snapshot
        if (m_bIsExtendedSnapshotValid)
        {
            fSnapshotValue = m_extendedSnapshot.GetInputValue(input);
        }
        else
        if (m_bIsGamepadSnapshotValid)
        {
            fSnapshotValue = m_gamepadSnapshot.GetInputValue(input);
        }

        GUI.color = GCInputColor(nControllerIndex, input);                              // Colour button background to indicate value-changed event or pressed status.
        GUI.DrawTexture(rect, m_whiteTexture);
        GUI.color = (fSnapshotValue == 0.0f) ? Color.white : Color.black;               // Colour label black or white to indicate snapshot value.
        GUI.skin.label.alignment = TextAnchor.MiddleCenter;
        GUI.Label(rect, sLabel);
    }
示例#4
0
 /// @brief	Input value-change callback.
 void InputValueChangedEvent(int nController, GameController.GCInput input)
 {
     m_inputValueChanged         = input;
     m_fInputValueChangedTimeout = Time.realtimeSinceStartup + 0.5f;
 }
示例#5
0
    //////////////////////////////////////////////////////////////////////////
    /// @brief	Draw up to 4 controller statuses on screen using UnityGUI.
    /// 		Call this from your own OnGUI function to overlay on other UnityGUI.
    //////////////////////////////////////////////////////////////////////////
    public void DrawGameControllerGUI()
    {
        Color orgColor = GUI.color;
        TextAnchor orgAlign = GUI.skin.label.alignment;

        #if UNITY_EDITOR
        int nNumControllers = 4;
        #else
        int nNumControllers = GameController.GetNumControllers();
        #endif

        float fControllerX = Screen.width * 0.05f;
        float fControllerY = Screen.width * 0.05f;
        float fControllerWidth = Screen.width * 0.4f;
        float fControllerHeight = fControllerWidth * 0.5f;

        if(nNumControllers >= 1)
        {
            DrawController(0, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if(nNumControllers >= 2)
        {
            fControllerX += fControllerWidth + 5.0f;
            DrawController(1, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if(nNumControllers >= 3)
        {
            fControllerX = Screen.width * 0.05f;
            fControllerY += fControllerHeight + 5.0f;
            DrawController(2, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if(nNumControllers >= 4)
        {
            fControllerX += fControllerWidth + 5.0f;
            DrawController(3, fControllerX, fControllerY, fControllerWidth, fControllerHeight);
        }

        if(Time.realtimeSinceStartup > m_fInputValueChangedTimeout)
            m_inputValueChanged = GameController.GCInput.None;

        GUI.color = orgColor;
        GUI.skin.label.alignment = orgAlign;
    }
示例#6
0
 /// @brief	Input value-change callback.
 void InputValueChangedEvent(int nController, GameController.GCInput input)
 {
     m_inputValueChanged = input;
     m_fInputValueChangedTimeout = Time.realtimeSinceStartup + 0.5f;
 }