コード例 #1
0
    public static string CorrectString(Text text, string baseStr, string endStr)
    {
        GameObject gameObject = (GameObject)Object.Instantiate <GameObject>((M0)((Component)text).get_gameObject(), (Transform)null, false);
        Text       component  = (Text)gameObject.GetComponent <Text>();
        float      spaceWidth = TextCorrectLimit.GetSpaceWidth(component);
        int        length1    = endStr.Length;
        float      num1       = 0.0f;

        for (int startIndex = 0; startIndex < length1; ++startIndex)
        {
            num1 += endStr[startIndex] != ' ' ? TextCorrectLimit.GetTextWidth(component, endStr.Substring(startIndex, 1)) : spaceWidth;
        }
        Rect  rect    = ((Graphic)text).get_rectTransform().get_rect();
        float num2    = ((Rect) ref rect).get_width() - num1;
        int   length2 = baseStr.Length;
        int   length3 = 0;
        float num3    = 0.0f;

        for (int startIndex = 0; startIndex < length2; ++startIndex)
        {
            num3 += baseStr[startIndex] != ' ' ? TextCorrectLimit.GetTextWidth(component, baseStr.Substring(startIndex, 1)) : spaceWidth;
            if ((double)num3 < (double)num2)
            {
                ++length3;
            }
            else
            {
                break;
            }
        }
        Object.Destroy((Object)gameObject);
        return(baseStr.Substring(0, length3) + (length3 != length2 ? endStr : string.Empty));
    }
コード例 #2
0
 private static float GetSpaceWidth(Text textComp)
 {
     return(TextCorrectLimit.GetTextWidth(textComp, "m m") - TextCorrectLimit.GetTextWidth(textComp, "mm"));
 }