I tried source.cachedTextGenerator.rectExtents which according to the doc should return the rect of the generated text and not the rect of the text so this should return the rect of the overflow text but it doesn’t.
What’s the magic formula?
I tried source.cachedTextGenerator.rectExtents which according to the doc should return the rect of the generated text and not the rect of the text so this should return the rect of the overflow text but it doesn’t.
What’s the magic formula?
It seems cachedTextGeneratorForLayout works better but as you can see there is an offset that keeps getting larger.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
public class UIMatchSize : MonoBehaviour {
// [SerializeField] RectTransform source;
[SerializeField] Text source;
[SerializeField] Vector2 extra;
void Update()
{
// GetComponent<RectTransform> ().sizeDelta = source.sizeDelta+extra;
GetComponent<RectTransform> ().sizeDelta = new Vector2(source.cachedTextGeneratorForLayout.rectExtents.width, source.cachedTextGeneratorForLayout.rectExtents.height)+extra;
}
}