I have a need to make some text font size the same as the other. I was looking into the TextMeshPro code and found out that there is EventManager and one can use it’s events to track stuff. I wrote the script but I think that might be terribly inefficient. May be there is a better way? Here is the script:
[ExecuteAlways]
[RequireComponent(typeof(TMP_Text))]
public class SameTextSizeAs : MonoBehaviour
{
public TMP_Text sameAsText;
private TMP_Text thisText;
private void OnEnable()
{
thisText = GetComponent<TMP_Text>();
TMPro_EventManager.TEXT_CHANGED_EVENT.Add(UpdateFontSize);
}
private void OnDisable()
{
TMPro_EventManager.TEXT_CHANGED_EVENT.Remove(UpdateFontSize);
}
public void UpdateFontSize(UnityEngine.Object obj)
{
if (sameAsText != null && obj == sameAsText)
{
thisText.fontSize = sameAsText.fontSize;
thisText.ForceMeshUpdate();
}
if (thisText == obj)
{
thisText.enableAutoSizing = false;
}
}
}
I want all the buttons to have the same font size as one particular button which has AutoSize option enabled. In the example above I wanted to make all buttons have the same font size as Description button because it is the longest word and will determine the smallest size needed for all of them to fit. This is useful for different layouts when button size scales but you want all the texts to be of the same size.
Also… I want to use the possibility to thank you Stephan_B for all the energy you invested into the development of the TextMeshPro package and the effort continuously put into it’s support. It is truly amazing.