Beispiel #1
0
    /**
     * Adds text lines to the viewport.
     *
     * @param text The lines of text to render.
     * @param time The time before fading.
     * @param color The color to use.
     */
    public void AddViewportText(string[] text, float time, Color color)
    {
        ViewportTextElement element = new ViewportTextElement();

        element.color = color;
        element.text  = text;
        element.time  = time;

        m_viewportTextElements.Add(element);
    }
Beispiel #2
0
    /**
     * Renders the all the viewport text elements.
     */
    protected void RenderViewportText()
    {
        if (m_viewportTextElements.Count == 0)
        {
            return;
        }

        Rect bounds = new Rect(0, 0, Screen.width, Screen.height);

        GUIStyle style = new GUIStyle();

        style.fontStyle = FontStyle.Bold;
        style.alignment = TextAnchor.UpperLeft;
        style.fontSize  = m_viewportFontSize;

        // render each element
        for (int i = 0; i < m_viewportTextElements.Count; ++i)
        {
            ViewportTextElement element = m_viewportTextElements[i];

            if (element.fontSize <= 0)
            {
                style.fontSize = m_viewportFontSize;
            }
            else
            {
                style.fontSize = element.fontSize;
            }

            // render each line
            for (int j = 0; j < element.text.Length; ++j)
            {
                RenderText(element.text[j], element, bounds, style);

                // move the line cursor down
                bounds.yMin += style.fontSize + m_viewportTextSpacing;
            }
        }
    }