获取字符串的像素长度

来源:互联网 发布:神优化单机大作 编辑:程序博客网 时间:2024/06/11 05:06
 public float GetPixelByStr(string str)
{
        float pixel = 0;
        for (int index = 0; index < str.Length; index++ )
        {
                float tempPixel = m_text.cachedTextGenerator.GetPreferredWidth(
                        str[index].Tostring(),
                        m_text.GetGenerationSettings(Vector2.zero));
                 pixel += tempPiexl;
        }
    return pixel;
}
0 0