Render() public method

public Render ( Vector2 position, string str, Vector2 renderSize ) : Vector2
position Vector2
str string
renderSize Vector2
return Vector2
Beispiel #1
0
 /// <summary>
 ///		Renders a given string of text to the screen with the current font/
 /// </summary>
 /// <param name="text">String of text to render to screen.</param>
 /// <param name="x">Position on the x-axis to start rendering text.</param>
 /// <param name="y">Position on the y-axis to start rendering text.</param>
 /// <param name="z">Position on the z-axis to start rendering text.</param>
 /// <param name="bfCode">If set to true BFCode in the text will be parsed.</param>
 public static void RenderText(string text, float x, float y, float z, bool bfCode)
 {
     if (_currentFont == null)
     {
         _defaultFont.Render(text, x, y, z, bfCode);
     }
     else
     {
         _currentFont.Render(text, x, y, z, bfCode);
     }
 }
    public void OnGUI()
    {
        str = GUILayout.TextField(str);

        if (Event.current.type == EventType.Repaint)
        {
            //shadowed font
            font1.Render(new Vector2(50, 20), str, 32);
            font1.Render(new Vector2(50, 50), str, 80);
            font1.Render(new Vector2(50, 100), str, 256);

            //outlined font
            font2.Render(new Vector2(50, 300), str, Screen.width / 2.5f);

            //without distance field
            font3.Render(new Vector2(50, 300 + Screen.width / 3.5f), str, Screen.width / 2.5f);

            //Incremental rendering of characters from different fonts
            Vector2 pos = new Vector2(50, 650);
            pos = font2.Render(pos, "a", 256);
            pos = font1.Render(pos, "a", 256);
        }
    }
Beispiel #3
0
    public void OnGUI()
    {
        if (Event.current.type == EventType.Repaint)
        {
            if (Font != null && Text != null)
            {
                //Convert scale to pixels
                Vector2 scale = new Vector2(transform.lossyScale.x, transform.lossyScale.y);
                if (ScaleUnits == TextUnits.ScreenNormalized)
                {
                    scale.x *= Screen.width;
                    scale.y *= Screen.height;
                }
                if (KeepAspectRatio)
                {
                    scale.y = scale.x;
                }

                //Calculate bounding box of rendered text
                Vector2 size = Font.CalculateSize(Text, scale);

                //Convert position to pixels
                Vector2 pos = new Vector2(transform.position.x, transform.position.y);
                if (PositionUnits == TextUnits.ScreenNormalized)
                {
                    pos.x *= Screen.width;
                    pos.y *= Screen.height;
                }

                //Default origin is top left
                if (Origin == TextOrigin.BottomLeft || Origin == TextOrigin.BottomRight)
                {
                    pos.y = Screen.height - pos.y;
                }
                if (Origin == TextOrigin.TopRight || Origin == TextOrigin.BottomRight)
                {
                    pos.x = Screen.width - pos.x;
                }
                if (Origin == TextOrigin.Center)
                {
                    pos.x = pos.x + Screen.width / 2;
                    pos.y = pos.y + Screen.height / 2;
                }


                Vector2 offset = new Vector2(0, 0);
                if (Anchor == TextAnchor.LowerCenter || Anchor == TextAnchor.LowerLeft || Anchor == TextAnchor.LowerRight)
                {
                    offset.y = size.y;
                }
                if (Anchor == TextAnchor.MiddleCenter || Anchor == TextAnchor.MiddleLeft || Anchor == TextAnchor.MiddleRight)
                {
                    offset.y = size.y / 2;
                }
                if (Anchor == TextAnchor.LowerRight || Anchor == TextAnchor.MiddleRight || Anchor == TextAnchor.UpperRight)
                {
                    offset.x = size.x;
                }
                if (Anchor == TextAnchor.LowerCenter || Anchor == TextAnchor.MiddleCenter || Anchor == TextAnchor.UpperCenter)
                {
                    offset.x = size.x / 2;
                }

                Font.Render(pos - offset, Text, scale);
            }
        }
    }