Best Fit font size

Hello

The new UI system is so great. I am using the text Best Fit feature which works flawlessly.
However I need to know at real time what font is used after setting the Text.text filed and with ‘Best Fit’ enabled.
The reason is that I use an RTL plugin which reverses the text, so I need to know where does the UI.Text field insert line break to correct the string text itself.
So is there a way to know the real fontsize used or where a line break is inserted when using ‘Best Fit’ in a UI.Text field?

Any help is greatly appreciated.
Thanks for advance.

1 Like

To answer my own question, I found the information I needed here.
text.cachedTextGenerator

Here is how to use RTL with best fit UI.Text.

string convertedText = RTL.Convert (textString, NumberFormat, IsLtrText);

        TextGenerationSettings settings = text.GetGenerationSettings (text.rectTransform.rect.size);
        TextGenerator generator = new TextGenerator();
        generator.Populate(convertedText, settings);

        Debug.Log ("generator.lineCount: " + generator.lineCount);
        CharsPerLine = 0;
        int lastIndex = 0;
        foreach (UILineInfo lineInfo in generator.lines) {
            int newLineLenght = lineInfo.startCharIdx - lastIndex;
            if(CharsPerLine < newLineLenght) {
                CharsPerLine = newLineLenght;
            }
            lastIndex = lineInfo.startCharIdx;
        }

        convertedText = RTL.ConvertCharacterWordWrapping(textString, CharsPerLine, NumberFormat, IsLtrText);
        text.text = convertedText;