public override void DebugRender()
    {
        if (!Enabled)
        {
            return;
        }
        Vector2 sz = Camera.main.pixelRect.size;

        lock (_objectsLock) {
            if (_currPoints == null)
            {
                return;
            }
            Vector2 v1 = Vector2.zero, v2 = Vector2.zero;
            for (int i = 0; i < _opticalFlow.Count; ++i)
            {
                var f = _opticalFlow [i];

                v1.Set(f.v1.x * sz.x, f.v1.y * sz.y);
                v2.Set(f.v2.x * sz.x, f.v2.y * sz.y);
                GUITools.DrawCircle(v1, 3, 10, ColorCode);
                GUITools.DrawLine(v1, v2, ColorCode);
            }
        }
    }
Exemplo n.º 2
0
    void OnGUI()
    {
        // If comm room is down disable its viewing by blacking it out
        if (GameController.Instance.RoomStatus[GameController.ShipRoom.COMMUNICATIONS] && !GameController.Instance.GameOver)
        {
            GUI.color = Color.black;
        }

        // Draws progress and health bars
        GUITools.progressBar(_progressFore, _progressBack, _line, LINE_WIDTH, _progressRect, GameController.Instance.Progress);
        GUITools.progressBar(_healthFore, _healthBack, _line, LINE_WIDTH, _healthRect, GameController.Instance.ShipHealth);

        // Gets text size (width and height) of progress and health bar labels
        Vector2 progressTextSize = GUI.skin.GetStyle("Label").CalcSize(new GUIContent("Progress"));
        Vector2 healthTextSize   = GUI.skin.GetStyle("Label").CalcSize(new GUIContent("Ship Health"));

        // Creates a rect centered in the progress bar rect
        Rect progressTextRect = new Rect(_progressRect.x + (_progressRect.width / 2 - progressTextSize.x / 2),
                                         _progressRect.y + (_progressRect.height / 2 - progressTextSize.y / 2), progressTextSize.x, progressTextSize.y);

        // Creates a rect centered in the health bar rect
        Rect healthTextRect = new Rect(_healthRect.x + (_healthRect.width / 2 - healthTextSize.x / 2),
                                       _healthRect.y + (_healthRect.height / 2 - healthTextSize.y / 2), healthTextSize.x, healthTextSize.y);

        // Draws the labels over the progress and health bars
        GUI.Label(progressTextRect, "Progress");
        GUI.Label(healthTextRect, "Ship Health");

        // Draws the dial backgrounds for heading and velocity
        GUI.DrawTexture(_headingRect, _dialBack);
        GUI.DrawTexture(_velocityRect, _dialBack);

        // Calculates and draws labels for dials
        Vector2 headingTextSize  = GUI.skin.GetStyle("Label").CalcSize(new GUIContent("Heading"));
        Vector2 velocityTextSize = GUI.skin.GetStyle("Label").CalcSize(new GUIContent("Velocity"));
        Rect    headingTextRect  = new Rect(_headingRect.x + (_headingRect.width / 2 - headingTextSize.x / 2),
                                            _headingRect.y + _headingRect.height - (headingTextSize.y + 6), headingTextSize.x, headingTextSize.y);
        Rect velocityTextRect = new Rect(_velocityRect.x + (_velocityRect.width / 2 - velocityTextSize.x / 2),
                                         _velocityRect.y + _velocityRect.height - (velocityTextSize.y + 6), velocityTextSize.x, velocityTextSize.y);

        GUI.Label(headingTextRect, "Heading");
        GUI.Label(velocityTextRect, "Velocity");

        // Draw dial increase/decrease notifiers
        if (!GameController.Instance.RoomStatus[GameController.ShipRoom.CONTROL])
        {
            GUI.DrawTexture(new Rect(headingTextRect.x + headingTextRect.width + 5, _headingRect.y + _headingRect.height - (Screen.height / 40 + 8), Screen.width / 35, Screen.height / 40), _arrowUp);
        }
        else
        {
            GUI.DrawTexture(new Rect(headingTextRect.x - (Screen.width / 35 + 5), _headingRect.y + _headingRect.height - (Screen.height / 40 + 8), Screen.width / 35, Screen.height / 40), _arrowDown);
        }
        if (!GameController.Instance.RoomStatus[GameController.ShipRoom.ENGINE] && !GameController.Instance.RoomStatus[GameController.ShipRoom.POWER])
        {
            GUI.DrawTexture(new Rect(velocityTextRect.x + velocityTextRect.width + 5, _headingRect.y + _headingRect.height - (Screen.height / 40 + 8), Screen.width / 35, Screen.height / 40), _arrowUp);
        }
        else
        {
            GUI.DrawTexture(new Rect(velocityTextRect.x - (Screen.width / 35 + 5), _headingRect.y + _headingRect.height - (Screen.height / 40 + 8), Screen.width / 35, Screen.height / 40), _arrowDown);
        }

        // Draw labels for score and multiplier
        GUISkin current      = GUI.skin;
        Color   currentColor = GUI.color;

        GUI.skin  = Skin;
        GUI.color = Color.green;
        GUI.Label(new Rect(Screen.width * 0.25f, _unitHeight + _unitHeight * 2.4f * 2, 400, 100), "Score: " + GameController.Instance.Score);
        GUI.Label(new Rect(Screen.width * 0.25f * 2, _unitHeight + _unitHeight * 2.4f * 2, 400, 100), "Multiplier: " + GameController.Instance.Multiplier + "x");
        GUI.skin  = current;
        GUI.color = currentColor;

        // Calculate and draw dials
        Vector2 headingDialOrigin  = new Vector2(_headingRect.x + _headingRect.width / 2 - 4, _headingRect.y + _headingRect.height * 0.76f);
        Vector2 velocityDialOrigin = new Vector2(_velocityRect.x + _velocityRect.width / 2 - 4, _velocityRect.y + _velocityRect.height * 0.76f);
        float   hDegree            = GameController.Instance.Heading;
        float   vDegree            = GameController.Instance.Velocity;
        int     headingX           = (int)(80 * Mathf.Cos(Mathf.PI * hDegree));
        int     headingY           = (int)(80 * Mathf.Sin(Mathf.PI * hDegree));
        int     velocityX          = (int)(80 * Mathf.Cos(Mathf.PI * vDegree));
        int     velocityY          = (int)(80 * Mathf.Sin(Mathf.PI * vDegree));
        Vector2 headingEnd         = new Vector2(headingDialOrigin.x - headingX, headingDialOrigin.y - headingY);
        Vector2 velocityEnd        = new Vector2(velocityDialOrigin.x - velocityX, velocityDialOrigin.y - velocityY);

        GUITools.DrawLine(headingDialOrigin, headingEnd, _dial, 8);
        GUITools.DrawLine(velocityDialOrigin, velocityEnd, _dial, 8);

        // Prints game over state
        if (GameController.Instance.GameOver)
        {
            current      = GUI.skin;
            currentColor = GUI.color;
            GUI.skin     = Skin;
            if (GameController.Instance.ShipHealth == 0)
            {
                GUI.color = Color.red;
                Vector2 gameOver = GUI.skin.GetStyle("Label").CalcSize(new GUIContent("YOU LOSE!"));
                GUI.Label(new Rect(Screen.width / 2 - gameOver.x / 2, Screen.height / 2 - gameOver.y / 2, gameOver.x, gameOver.y), "YOU LOSE!");
            }
            else
            {
                GUI.color = Color.green;
                Vector2 gameOver = GUI.skin.GetStyle("Label").CalcSize(new GUIContent("YOU WIN!"));
                GUI.Label(new Rect(Screen.width / 2 - gameOver.x / 2, Screen.height / 2 - gameOver.y / 2, gameOver.x, gameOver.y), "YOU WIN!");
            }
            GUI.skin  = current;
            GUI.color = currentColor;

            if (Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter))
            {
                Application.LoadLevel("Start");
            }
        }
    }