- Home /
Question by
NarallandaKaratoga · Jun 13, 2018 at 07:38 AM ·
guitextguitext
How to find the origin point of a text line?
I'm going to implement my own InputField with some new features, and trying to get the caret position, using Text componenet of UGUI.
I wrote this
float curOffset = 0.0f;
foreach(var c in text.text)
{
CharacterInfo info;
text.font.GetCharacterInfo(c, out info, text.fontSize, text.fontStyle);
Vector3 bottomLeft = rectTransform.position + new Vector3(curOffset + info.minX, info.minY, -1f);
Vector3 bottomRight = rectTransform.position + new Vector3(curOffset + info.maxX, info.minY, -1f);
Vector3 topLeft = rectTransform.position + new Vector3(curOffset + info.minX, info.maxY, -1f);
Vector3 topRight = rectTransform.position + new Vector3(curOffset + info.maxX, info.maxY, -1f);
Debug.DrawLine(bottomLeft, bottomRight, Color.green);
Debug.DrawLine(bottomRight, topRight, Color.green);
Debug.DrawLine(topRight, topLeft, Color.green);
Debug.DrawLine(topLeft, bottomLeft, Color.green);
curOffset += info.advance;
}
and got this...
how can I get the proper position?
qq截图20180613152641.png
(20.4 kB)
Comment
Your answer
Follow this Question
Related Questions
Problem Reading A Text File 2 Answers
Bitmap based GUI Ui.Text 3 Answers
Script to change GUI text's displayed text value? 7 Answers
HELP with scripting where GUI is involved 2 Answers
changing font + size of text 1 Answer