unity inputField计算文本高度

private float countTextHeight()
    {
        InputField inputField = talkBox.transform.GetComponent();
        TextGenerator m_TextGenerator = inputField.textComponent.cachedTextGenerator;
        TextGenerationSettings settings = inputField.textComponent.GetGenerationSettings(new Vector2(inputField.GetComponent().rect.width, 0));
        settings.fontSize = playerInputTextSize;
        settings.lineSpacing = 1;
        settings.verticalOverflow = VerticalWrapMode.Overflow;
        float height = m_TextGenerator.GetPreferredHeight(inputField.text, settings);

        return height;
        //inputField.GetComponent().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); } 
        //return 1f;
    }

你可能感兴趣的:(python)