计算unity Text文字所占用的长度

                        Text textComp;
                        Font font = textComp.font;
                        if (font != null)
                        {
                            font.RequestCharactersInTexture(textComp.text, textComp.fontSize, FontStyle.Normal);
                            CharacterInfo characterInfo;
                            float width = 0f;
                            for (int j = 0; j < textComp.text.Length; j++)
                            {
                                font.GetCharacterInfo(textComp.text[j], out characterInfo, textComp.fontSize);
                                width += characterInfo.advance;
                            }
                        }

你可能感兴趣的:(计算unity Text文字所占用的长度)